-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTest_Voice.py
56 lines (46 loc) · 1.9 KB
/
Test_Voice.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
'''
Test program to demo Text to Speech routine in say.py
SETUP - change constants below to match your environment:
* change the IP to the IP of your Sonos box
* change the PATH to a path you program can read and write to and
Sonos has access to (e.g. your music library on NAS
* copy the alert file(s) to this location
* try the program
* Note: takes words from command line (in inverted commas)
or if none on command line uses DEFAULT_TEXT below
@author: David
'''
import sys
from soco import SoCo
from say import text2mp3 # this is the say_it function in say.py
# Constants to customise for your environment
IP = "192.168.0.73" #Sonos player to use
PATH = '//nas/music' #eg a Music share - Sonos must be able to access
#Constants of your choice
ALERT = 'alert4.mp3' #alert MP3 in PATH to use at start of MP3 (optional)
LANGUAGE = 'en' # language for speech (en = English)
# text below used if nothing input on command line
DEFUALT_TEXT = '%greet. Today is %day the %date, and the time is %time'
#=============================================================================
def main():
'''
Test stub to call the say routine.
Command line provides the words to say in inverted commas
If omitted then uses a default text
'''
#use text argument from command line if present - else use default
if len(sys.argv) < 2:
txt = DEFUALT_TEXT
else:
txt = sys.argv[1]
print ('Testing using %s character string "%s"' % (len(txt), txt) )
ok, file_name = text2mp3(txt, PATH, LANGUAGE, ALERT)
#if TTS worked OK, use file name returned to play MP3 on Sonos
if ok:
zp = SoCo(IP)
zp.play_uri('x-file-cifs:%s' % file_name)
print 'Listen to your Sonos - check volume turned up!'
#=============================================================================
if __name__ == "__main__":
main()
print 'End'