-
Notifications
You must be signed in to change notification settings - Fork 1
/
VoiceIt.py
113 lines (97 loc) · 5.2 KB
/
VoiceIt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import hashlib,requests
class VoiceIt:
developerId = ""
urlUsers = 'https://siv.voiceprintportal.com/sivservice/api/users'
urlEnrollments = 'https://siv.voiceprintportal.com/sivservice/api/enrollments'
urlAuthentication = 'https://siv.voiceprintportal.com/sivservice/api/authentications'
def getSHA256(self, strData):
return hashlib.sha256(strData.encode("ascii")).hexdigest()
def __init__(self, devId):
self.developerId = devId
def createUser(self, userId, passwd):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'application/json', "UserId": userId, "VsitPassword": password, "VsitDeveloperId": self.developerId}
try:
response = requests.post(self.urlUsers, headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def deleteUser(self, userId, passwd):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'application/json', "UserId": userId,
"VsitPassword": password, "VsitDeveloperId": self.developerId}
try:
response = requests.delete(self.urlUsers, headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def getUser(self, userId, passwd):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'application/json', "UserId": userId,
"VsitPassword": password, "VsitDeveloperId": self.developerId}
try:
response = requests.get(self.urlUsers, headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def createEnrollment(self, userId, passwd, pathToEnrollmentWav, contentLanguage=""):
password = self.getSHA256(passwd)
with open(pathToEnrollmentWav, 'rb') as file:
wavData = file.read()
headers = {'PlatformID': '2', 'Content-Type': 'audio/wav', "UserId": userId,
"VsitPassword": password, "VsitDeveloperId": self.developerId, "ContentLanguage":contentLanguage}
try:
response = requests.post(
self.urlEnrollments, headers=headers, data=wavData)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def createEnrollmentByWavURL(self, userId, passwd, urlToEnrollmentWav, contentLanguage=""):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'audio/wav', "UserId": userId, "VsitPassword": password,
"VsitDeveloperId": self.developerId, "VsitwavURL": urlToEnrollmentWav, "ContentLanguage":contentLanguage}
try:
response = requests.post(
self.urlEnrollments + "/bywavurl", headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def getEnrollments(self, userId, passwd):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'application/json', "UserId": userId,
"VsitPassword": password, "VsitDeveloperId": self.developerId}
try:
response = requests.get(self.urlEnrollments, headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def deleteEnrollment(self, userId, passwd, enrollmentId):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'application/json', "UserId": userId,
"VsitPassword": password, "VsitDeveloperId": self.developerId}
try:
response = requests.delete(
self.urlEnrollments + "/" + enrollmentId, headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def authentication(self, userId, passwd, pathToAuthenticationWav, contentLanguage=""):
password = self.getSHA256(passwd)
with open(pathToAuthenticationWav, 'rb') as file:
wavData = file.read()
headers = {'PlatformID': '2', 'Content-Type': 'audio/wav', "UserId": userId, "VsitPassword": password, "VsitDeveloperId": self.developerId, "ContentLanguage":contentLanguage}
try:
response = requests.post(
self.urlAuthentication, headers=headers, data=wavData)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()
def authenticationByWavURL(self, userId, passwd, urlToAuthenticationWav, contentLanguage=""):
password = self.getSHA256(passwd)
headers = {'PlatformID': '2', 'Content-Type': 'audio/wav', "UserId": userId, "VsitPassword": password, "VsitDeveloperId": self.developerId, "VsitwavURL": urlToAuthenticationWav, "ContentLanguage":contentLanguage}
try:
response = requests.post(
self.urlAuthentication + "/bywavurl", headers=headers)
return response.text
except requests.exceptions.HTTPError as e:
return e.read()