-
Notifications
You must be signed in to change notification settings - Fork 0
/
speak.py
34 lines (26 loc) · 851 Bytes
/
speak.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
import subprocess
def say (text):
command = "echo '" + text + "'| espeak -v en+m2 -m"
subprocess.call(command,shell=True)
def play(file) :
command = "play " + file
subprocess.call(command,shell=True)
def escape_XML(str) :
str.replace('"',"\042")
str.replace('&',"\046")
str.replace("'","\047")
str.replace('<',"\074")
str.replace('>',"\076")
return str
def ssml_break(msec):
return '<break time="'+str(msec)+'"msec/>'
def ssml_digits(digits):
return '<say-as interpret-as="tts:digits">'+str(digits)+"</say-as>"
def substitute(word,substitutes) :
try :
replacement = substitutes[word]
return '<sub alias="' + replacement +'">'+word+'</sub>'
except :
return word
def expand(text,substitutes) :
return " ".join([substitute(word,substitutes) for word in text.split(" ")])