forked from robotstreamer/robotstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio.py
47 lines (30 loc) · 1.11 KB
/
audio.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
#import wave
#import contextlib
import uuid
import os
import tempfile
#def wavDuration(fname):
#
# with contextlib.closing(wave.open(fname,'r')) as f:
# frames = f.getnframes()
# rate = f.getframerate()
# duration = frames / float(rate)
# return duration
def espeakBytes(message):
tempDir = tempfile.gettempdir()
tempFilePath = os.path.join(tempDir, "text_" + str(uuid.uuid4()))
outFilePath = os.path.join(tempDir, "out_" + str(uuid.uuid4()))
f = open(tempFilePath, "w")
f.write(message)
f.close()
os.system('cat ' + tempFilePath + ' | espeak -ven --stdout > ' + outFilePath)
length = os.path.getsize(outFilePath)
os.remove(tempFilePath)
os.remove(outFilePath)
return length
def main():
#print('duration:', wavDuration('/home/pi/myaudio'))
print('duration hello:', espeakBytes("hello"))
print('duration hello world:', espeakBytes("hello world"))
if __name__ == "__main__":
main()