Jan-24-2017, 10:43 AM
(Jan-24-2017, 08:29 AM)wavic Wrote: Hello!
Why is that indentation after audio = re.listen(source)?
Do some tests. Ifaudio
stores all the data which flows from the microphone do this mean that you try to recognize and run the open command, again and again, if you send it to google. Does google stop when returns the first word? Does that recognizing speech module run the listening in a separate thread? The audio variable has to be some kind of FIFO file object.
Get the data from that file and throw it to google, try to catch the response and run the command as you did it already in the continuous while loop.
I can't give you an example of all that because I never usedtmpfile
module before. I don't know this recognizing speech module and have no time to look at it right now. I hope this is pointing to a right direction
import speech_recognition as sr
import pyttsx
import decision
import opCl
speech_engine = pyttsx.init('nsss')
speech_engine.setProperty('rate', 150)
OPEN_COGNATES=['open']
CLOSE_COGNATES=['close']
def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()
##print text
re = sr.Recognizer()
def listen():
with sr.Microphone() as source:
re.adjust_for_ambient_noise(source)
speak("minimum energy threshold is {:.2f}".format(re.energy_threshold))
speak("Say something!")
while True:
print">>",
audio = re.listen(source)
try:
##return re.recognize_sphinx(audio)
##speak("now to recognise it,")
value=re.recognize_google(audio)
print value
speak("I heard you say {}".format(value))
value=value.strip().split()
name=" ".join(value[1:])
if value[0] in OPEN_COGNATES:
speak(opCl.openCmd(name))
pass
elif value[0] in CLOSE_COGNATES:
speak(opCl.closeCmd(name))
pass
else:
pass
except sr.UnknownValueError as e:
speak("Could not understand audio")
print e
except sr.RequestError as e:
speak("Recog Error; {0}".format(e))
print e
speak("A moment of silence please:- ")
listen()
##print listen()
import pyttsx
import decision
import opCl
speech_engine = pyttsx.init('nsss')
speech_engine.setProperty('rate', 150)
OPEN_COGNATES=['open']
CLOSE_COGNATES=['close']
def speak(text):
speech_engine.say(text)
speech_engine.runAndWait()
##print text
re = sr.Recognizer()
def listen():
with sr.Microphone() as source:
re.adjust_for_ambient_noise(source)
speak("minimum energy threshold is {:.2f}".format(re.energy_threshold))
speak("Say something!")
while True:
print">>",
audio = re.listen(source)
try:
##return re.recognize_sphinx(audio)
##speak("now to recognise it,")
value=re.recognize_google(audio)
print value
speak("I heard you say {}".format(value))
value=value.strip().split()
name=" ".join(value[1:])
if value[0] in OPEN_COGNATES:
speak(opCl.openCmd(name))
pass
elif value[0] in CLOSE_COGNATES:
speak(opCl.closeCmd(name))
pass
else:
pass
except sr.UnknownValueError as e:
speak("Could not understand audio")
print e
except sr.RequestError as e:
speak("Recog Error; {0}".format(e))
print e
speak("A moment of silence please:- ")
listen()
##print listen()
i dont know how to give here indented code. but consider the code is error free, as it is. There is no error either from google speech engine or syntactically. but the thing is after opening an application, the application blocks my code. which i dont want.