-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeech.py
36 lines (27 loc) · 939 Bytes
/
Speech.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
import subprocess
import time
import Platform
if Platform.is_raspberrypi():
subprocess.call(['amixer', 'cset', 'numid=3', '1']) #select jack output
subprocess.call(['amixer', 'cset', 'numid=1', '400']) #set volume to maximum
__popen__ = None
def say(sentence):
global __popen__
if __popen__ is not None:
__popen__.wait()
print("Saying '{0}'".format(sentence))
cmd = ['mpg123', '-q', "http://translate.google.com/translate_tts?tl=en&q={0}".format(sentence)]
if Platform.is_raspberrypi():
__popen__ = subprocess.Popen(cmd)
def play(file):
global __popen__
if __popen__ is not None:
__popen__.wait()
print("Playing '{0}'".format(file))
cmd = ['mpg123', '-q', file]
if Platform.is_raspberrypi():
__popen__ = subprocess.Popen(cmd)
if __name__ == "__main__":
say("hello")
say("supercalifragilisticexpialidocious")
say("world")