Fixed the voice to text

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

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

Loading…
Cancel
Save