-
Notifications
You must be signed in to change notification settings - Fork 0
/
gloria
executable file
·38 lines (32 loc) · 1.21 KB
/
gloria
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
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import sys, subprocess, urllib
def getSpeechyw(phrase):
googleAPIurl = "http://translate.google.com/translate_tts?ie=UTF-8&tl=en-US&"
param = {'q': phrase}
data = urllib.urlencode(param)
googleAPIurl += data # Append the parameters
return googleAPIurl
def ywsay(text): # This will call mpg123 and will play the sound
subprocess.call(["mplayer",getSpeechyw(text)], shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def getSpeechzw(phrase):
googleAPIurl = "http://translate.google.com/translate_tts?ie=UTF-8&tl=zh-CN&"
param = {'q': phrase}
data = urllib.urlencode(param)
googleAPIurl += data # Append the parameters
return googleAPIurl
def zwsay(text): # This will call mpg123 and will play the sound
subprocess.call(["mpg123",getSpeechzw(text)], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ywsay("Choose your language, my lord.")
xz = raw_input("")
if xz == "zw":
zwsay("主人,需要我做些什么吗?")
yy = raw_input(":")
if __name__ == "__main__":
zwsay(yy)
else:
ywsay("May i help you? my lord.")
yy = raw_input(":")
if __name__ == "__main__":
ywsay(yy)