-
Notifications
You must be signed in to change notification settings - Fork 2
/
googlespeech.py
97 lines (84 loc) · 4.39 KB
/
googlespeech.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
"""
class googlespeech:
speaker_name = form.Textbox('name', description='Speaker ID: ')
sex = myform.MyRadio('sex', [('M','Male ', 'M'), ('F','Female ', 'F'), ('F','Child ', 'C')], description='Speaker Sex: ')
sex.value = 'M' # default if not checked
filepaths = utilities.read_filepaths()
appdir = '.'
datadir = filepaths['DATA']
uploadfile = make_uploadfile()
delstopwords = make_delstopwords()
delunstressedvowels = make_delunstressedvowels()
filterbandwidths = make_filterbandwidths()
email = make_email()
taskname = form.Hidden('taskname')
submit = form.Button('submit', type='submit', description='Submit')
soundvalid = [form.Validator('Please upload a sound file.',
lambda x:x.uploadfile)]
def GET(self):
googlespeech = myform.MyForm(self.uploadfile,
self.delstopwords,
self.delunstressedvowels,
self.filterbandwidths,
self.email,
self.taskname,
self.speaker_name,
self.sex,
self.submit)
form = googlespeech()
return render.googlespeech(form)
def POST(self):
googlespeech = myform.MyForm(self.uploadfile,
self.delstopwords,
self.delunstressedvowels,
self.filterbandwidths,
self.email,
self.taskname,
self.sex,
self.speaker_name,
self.submit)
form = googlespeech()
x = web.input(uploadfile={})
#sanitize filename
filename, extension = utilities.get_basename(x.uploadfile.filename)
if extension not in ['.wav', '.mp3']:
form.note = "Please upload a .wav or .mp3 file."
return render.speakersyt(form)
else:
gstorage = get_storage_service(self.filepaths['GOOGLESPEECH'])
service = get_speech_service(self.filepaths['GOOGLESPEECH'])
taskname, audiodir, error = utilities.make_task(self.datadir)
filename, extension = utilities.get_basename(x.uploadfile.filename)
utilities.write_speaker_info(os.path.join(self.datadir, taskname+'.speaker'), x.name, x.sex)
utilities.send_init_email('googleasr', x.email, filename)
# upload entire file onto google cloud storage
samprate, total_size, chunks, error = utilities.process_audio(audiodir,
filename,
extension,
x.uploadfile.file.read(),
dochunk=None)
result = gcloudupload.delay(gstorage,
audiodir,
filename,
taskname,
x.email)
while not result.ready():
pass
# uncomment to test throttle by sending 4 speech reqs
# for i in range(4):
result = asyncrec.delay(service,
self.datadir,
taskname,
audiodir,
filename,
samprate,
x.email)
while not result.ready():
pass
#TODO: why do we need datadir, audiodir, etc? Reduce redundancy in these filenames
utilities.gen_argfiles(self.datadir, taskname, filename, 'googleasr', x.email, samprate, x.delstopwords, x.filterbandwidths, x.delunstressedvowels)
result = align_extract.delay(os.path.join(self.datadir, taskname), self.appdir)
while not result.ready():
pass
return render.success("You may now close this window. We will email you the results.")
"""