· 6 years ago · Mar 16, 2020, 10:28 PM
1#Speaker Verification Microsoft API
2
3
4# 1) Create Profile
5# https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/563309b7778daf06340c9652
6
7
8########### Python 3.2 #############
9import http.client, urllib.request, urllib.parse, urllib.error, base64
10
11headers = {
12 # Request headers
13 'Content-Type': 'application/json',
14 'Ocp-Apim-Subscription-Key': '{subscription key}',
15}
16
17params = urllib.parse.urlencode({
18})
19
20try:
21 conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
22 conn.request("POST", "/spid/v1.0/verificationProfiles?%s" % params, "{body}", headers)
23 response = conn.getresponse()
24 data = response.read()
25 conn.close()
26except Exception as e:
27 print("[Errno {0}] {1}".format(e.errno, e.strerror))
28
29####################################
30
31
32# 2) Create Enrollment
33# https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/56406930e597ed20c8d8549c
34
35########### Python 3.2 #############
36import http.client, urllib.request, urllib.parse, urllib.error, base64
37
38headers = {
39 # Request headers
40 'Content-Type': 'multipart/form-data',
41 'Ocp-Apim-Subscription-Key': '{subscription key}',
42}
43
44params = urllib.parse.urlencode({
45})
46
47try:
48 conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
49 conn.request("POST", "/spid/v1.0/verificationProfiles/{verificationProfileId}/enroll?%s" % params, "{body}", headers)
50 response = conn.getresponse()
51 data = response.read()
52 print(data)
53 conn.close()
54except Exception as e:
55 print("[Errno {0}] {1}".format(e.errno, e.strerror))
56
57####################################
58
59
60# 3) Verification
61# https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/56406930e597ed20c8d8549d
62
63########### Python 3.2 #############
64import http.client, urllib.request, urllib.parse, urllib.error, base64
65
66headers = {
67 # Request headers
68 'Content-Type': 'application/octet-stream',
69 'Ocp-Apim-Subscription-Key': '{subscription key}',
70}
71
72params = urllib.parse.urlencode({
73})
74
75try:
76 conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
77 conn.request("POST", "/spid/v1.0/verify?verificationProfileId={verificationProfileId}&%s" % params, "{body}", headers)
78 response = conn.getresponse()
79 data = response.read()
80 print(data)
81 conn.close()
82except Exception as e:
83 print("[Errno {0}] {1}".format(e.errno, e.strerror))
84
85####################################