my code is recording voice, but for some reason google recognizer or sphinx not converting the voice to text. If i print the audio there is voice. the output is "Sorry, I did not get that" witch is the exception default. Can you look in to my code and see what I'm doing wrong. In regular Python this Voice recognition work fine. `
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock, mainthread
import speech_recognition as sr
from kivy.lang import Builder
from plyer import stt
from plyer import tts
Builder.load_string("""
<Principal>:
id: HomeScreen
BoxLayout:
orientation: 'vertical'
Button:
text:'speak'
on_release: root.Btnclick()
Label:
id: lblMessage
text: 'Hello' """)
class Principal(Screen):
def Btnclick(self):
self.ids.lblMessage.text = "Say something!"
Clock.schedule_once(lambda d: self.GetAudio(), 0)
def GetAudio(self):
r = sr.Recognizer()
r.energy_threshold =4000
r.dynamic_energy_threshold = True
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source,duration=5)
#r.energy_threshold = 400
r.dynamic_energy_threshold = True
print("Say something!")
audio = r.listen(source)
try:
print("you Said: "+r.recognize_sphinx(audio, language = "en-US"))
#tts.speak("you Said: "+r.recognize_sphinx(audio, language = "en-US"))
self.ids.lblMessage.text = "you Said: "+r.recognize_sphinx(audio, language = "en-US")
except:
print("Sorry, I did not get that")
#tts.speak("Sorry, I did not get that")
self.ids.lblMessage.text = "Sorry, I did not get that"
class MainApp(App):
def build(self):
for i in sr.Microphone.list_microphone_names():
print(i)
sm = ScreenManager()
self.sm = sm
sm.add_widget(Principal(name='Principal'))
return sm
def on_pause(self):
return False
if __name__ == '__main__':
MainApp().run()
This is the output am getting
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
Say something!
<speech_recognition.AudioData object at 0x0000027124A64190>
Sorry, I did not get that