forked from Kitt-AI/snowboy
-
Notifications
You must be signed in to change notification settings - Fork 124
/
training_service.py
52 lines (43 loc) · 1.3 KB
/
training_service.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
#! /usr/bin/evn python
import sys
import base64
import requests
def get_wave(fname):
with open(fname) as infile:
return base64.b64encode(infile.read())
endpoint = "https://snowboy.kitt.ai/api/v1/train/"
############# MODIFY THE FOLLOWING #############
token = ""
hotword_name = "???"
language = "en"
age_group = "20_29"
gender = "M"
microphone = "??" # e.g., macbook pro microphone
############### END OF MODIFY ##################
if __name__ == "__main__":
try:
[_, wav1, wav2, wav3, out] = sys.argv
except ValueError:
print "Usage: %s wave_file1 wave_file2 wave_file3 out_model_name" % sys.argv[0]
sys.exit()
data = {
"name": hotword_name,
"language": language,
"age_group": age_group,
"gender": gender,
"microphone": microphone,
"token": token,
"voice_samples": [
{"wave": get_wave(wav1)},
{"wave": get_wave(wav2)},
{"wave": get_wave(wav3)}
]
}
response = requests.post(endpoint, json=data)
if response.ok:
with open(out, "w") as outfile:
outfile.write(response.content)
print "Saved model to '%s'." % out
else:
print "Request failed."
print response.text