# -*- coding: utf-8 -*- 



def talk(data):
		
	#ear.startListening() #fix onclick micro
	
	if data:
		if data!="":
			if data[0:2]=="l ":
				data=data.replace("l ", "l'")
			data=data.replace(" l ", " l'")
			mouth.speak(unicode(data,'utf-8'))
		
	if IsInmoovArduino==1 and MoveEyesRandom==1:
		if random.randint(1,3)==1:
			i01.head.eyeX.moveTo(0)
			sleep(2)
			i01.head.eyeX.moveTo(180)
			sleep(1)
			i01.head.eyeX.moveTo(90)

def talkBlocking(data):
		
	if data!="":
		mouth.speakBlocking(unicode(data,'utf-8'))
		
def Parse(utfdata):
	#Light(1,1,0)
	utfdata = urllib2.urlopen(utfdata).read()
	utfdata = utfdata.replace("&#039;", "'").replace("http://fr.answers.yahoo.com/question/ind...", "")
	try:
		utfdata = utfdata.decode( "utf8" ).replace(" : ", random.choice(troat))
	except: 
		pass
	#print utfdata
	#Light(1,1,1)
	return utfdata;

##############################################################
# We listen when the robot is starting to speak to avoid ear listening
# If you click on the webkit mic icon, this trick is broken
##############################################################
def onEndSpeaking(text):
	global IcanStartToEar
	global MoveHeadRandom
	global RamdomSpeak
	global Ispeak
	global TimeNoSpeak
	
	MoveHeadTimer.stopClock()
	Ispeak=0
	VieAleatoire.startClock()
	TimeNoSpeak="OFF"
	#Light(0,0,0)
	
	MoveHeadRandom=1
	
	if IcanStartToEar==1:
		try:
			ear.resumeListening()
		except: 
			pass
	WebkitSpeachReconitionFix.startClock()
	IcanStartToEar=1
	RamdomSpeak=0

	
	#sleep(0.2)
	
def onStartSpeaking(text):
	
	global RamdomSpeak
	global MoveHeadRandom
	global Ispeak
	
	if DEBUG==1:
		print "dbg : RamdomSpeak:",RamdomSpeak
	global RobotIsSleepingSoft