def googleTTS(text='hello', lang='en', fname='result.wav', player='mplayer'):
	""" Send text to Google's text to speech service
	and returns created speech (wav file). """
	pub_face_commands = rospy.Publisher('/face/control', faceRequests)
	face = faceRequests()        
	limit = min(100, len(text))#100 characters is the current limit.
	text = text[0:limit]
	url = "http://translate.google.com/translate_tts"
	values = urllib.urlencode({"q": text, "textlen": len(text), "tl": lang})
	hrs = {"User-Agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7"}
	req = urllib2.Request(url, data=values, headers=hrs)
	while True:
		try:
			p = urllib2.urlopen(req)
			break
		except urllib2.HTTPError:
			print "------ Caught Exception in google text to speech urlopen --------"
			time.sleep(0.2)
	f = open(fname, 'wb')
	f.write(p.read())
	f.close()
	face.talking = True
	face.question = text
	pub_face_commands.publish(face)
	play_wav(fname, player)
	face.talking = False
	face.question = ""
	pub_face_commands.publish(face)
	os.remove(fname)
示例#2
0
def googleTTS(text='hello', lang='en', fname='result.wav', player='mplayer'):
    """ Send text to Google's text to speech service
	and returns created speech (wav file). """
    pub_face_commands = rospy.Publisher('/face/control', faceRequests)
    face = faceRequests()
    limit = min(100, len(text))  #100 characters is the current limit.
    text = text[0:limit]
    url = "http://translate.google.com/translate_tts"
    values = urllib.urlencode({"q": text, "textlen": len(text), "tl": lang})
    hrs = {
        "User-Agent":
        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.63 Safari/535.7"
    }
    req = urllib2.Request(url, data=values, headers=hrs)
    while True:
        try:
            p = urllib2.urlopen(req)
            break
        except urllib2.HTTPError:
            print "------ Caught Exception in google text to speech urlopen --------"
            time.sleep(0.2)
    f = open(fname, 'wb')
    f.write(p.read())
    f.close()
    face.talking = True
    face.question = text
    pub_face_commands.publish(face)
    play_wav(fname, player)
    face.talking = False
    face.question = ""
    pub_face_commands.publish(face)
    os.remove(fname)
示例#3
0
    def face(self, args):
        faceArgs = args.split()
        face = faceRequests()
        face.emotion = faceArgs[1]
        if len(faceArgs) < 3:
            face.talking = False
        elif faceArgs[2] == '1':
            face.talking = True
        elif faceArgs[2] == '0':
            face.talking == False

        self.pub_face_commands.publish(face)
示例#4
0
 def update(self, is_talking=False, message=''):
     self.pub.publish(faceRequests(talking=is_talking, question=message))
示例#5
0
 def update(self, is_talking=False, message=''):
     self.pub.publish(faceRequests(talking=is_talking, question=message))