Fixed the voice to text

fetchIP
E. Almqvist 4 years ago
parent 1e0350d356
commit 2ffdb41cab
  1. 45
      speech/speech.py

@ -5,25 +5,28 @@ class voiceInput(object):
muted = True muted = True
def voiceToText( self, deviceIndex=30 ): # "Error codes", can be used to check stuff
try: what = "??"
with sr.Microphone( deviceIndex ) as src: error = "ERROR"
self.recognizer.adjust_for_ambient_noise( src, 0.2 )
print("Listening...") def start( self, deviceIndex=30 ): # a generator for everything that is said
audio = self.recognizer.listen( src, phrase_time_limit=5 ) while( True ): # loop
print("Thinking...") try:
text = self.recognizer.recognize_google(audio) if( not self.muted ): # this thing is not the NSA
print(text) with sr.Microphone( deviceIndex ) as src:
self.recognizer.adjust_for_ambient_noise( src, 0.2 )
return self.voiceToText(deviceIndex) print("Listening...")
audio = self.recognizer.listen( src, phrase_time_limit=5 )
except sr.RequestError as err: print("Thinking...")
print("Unable to request results: {0}".format(err)) text = self.recognizer.recognize_google(audio)
return self.voiceToText(deviceIndex) yield text
except sr.UnknownValueError: except sr.RequestError as err:
print("????") print("Unable to request results: {0}".format(err))
return self.voiceToText(deviceIndex) yield self.error
except sr.UnknownValueError:
yield self.what
def setMuted( self, setm: bool=True ): def setMuted( self, setm: bool=True ):
@ -32,7 +35,3 @@ class voiceInput(object):
def switchMute( self ): def switchMute( self ):
self.setMuted( not self.muted ) self.setMuted( not self.muted )
voice = voiceInput()
voice.setMuted(False)
print( "out:", voice.voiceToText() )

Loading…
Cancel
Save