Kivy语音识别不是将语音转换为文本
我的代码是录制语音,但由于某种原因,Google识别器或狮身人面像不会将语音转换为文本。如果我打印音频,则有声音。输出是“对不起,我没有得到”女巫默认是例外。您能查看我的代码,看看我在做什么错。在常规的python中,这种语音识别效果很好。 `
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论