Jan-07-2017, 03:20 AM
Windows 7, Python 2.7, Bing text-to-speech API.
I' m having trouble understanding why when I run the function it seems to be outputting
instead of
'1'
if the recursion bit of the function is activated.
If the speech recognizer correctly interprets my command "Hey PC", and outputs it as a string ('Hey PC') or similar variant, I want it to output 1, or else I want it to to keep retrying until it correctly outputs 1.
Below are some of my outputs in IDLE when running the script.
Thank you.
I' m having trouble understanding why when I run the function it seems to be outputting
None
instead of
'1'
if the recursion bit of the function is activated.
import win32com.client BING_KEY = "XXXXXXXX" import speech_recognition as sr import win32com.client as wincl s = sr.Recognizer() def hey_pc(): print(" Hey PC = Command") with sr.Microphone() as source: audio = s.listen(source) try: x= (s.recognize_bing(audio, key=BING_KEY)) if x in ['hey PC']: return 1 else: hey_pc() except: print('Try again') hey_pc() # Main part of program below t = hey_pc() print tSo the code is my attempt at a hobby project involving voice commands.
If the speech recognizer correctly interprets my command "Hey PC", and outputs it as a string ('Hey PC') or similar variant, I want it to output 1, or else I want it to to keep retrying until it correctly outputs 1.
Below are some of my outputs in IDLE when running the script.
Hey PC == Command 1 #outputs 1 if the SR guesses/interprets my voice correctly on the first try (thus the recursive part of the function is not activated)
Hey PC == Command Hey PC == Command Hey PC == Command Hey PC == Command None # outputs None, if doesn't guess correctly on the first attempt but eventually guesses it after a number of attempts
Hey PC == Command Try again Hey PC == Command Hey PC == Command None # Once again outputs None, if doesn't guess correctly on the first attempt but eventually guesses it after a number of attemptsI don't understand why I"m getting "None." I want the function to recursively continue until it can correctly output one.
Thank you.