语音识别不起作用
这是我的代码:

import speech_recognition

robot_ear = speech_recognition.Recognizer()
with speech_recognition.Microphone() as mic:
    print ("Robot: I'm listening")
    audio = robot_ear.listen(mic)

you = robot_ear.recognize_google(audio)

print(you)

但是计算机没有响应我所说的话
> Traceback (most recent call last):   File "nghe1.py", line 6, in
> <module>
>     audio = robot_ear.listen(mic)   File "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py",
> line 652, in listen
>     buffer = source.stream.read(source.CHUNK)   File "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\speech_recognition\__init__.py",
> line 161, in read
>     return self.pyaudio_stream.read(size, exception_on_overflow=False)   File
> "C:\Users\Jean\AppData\Local\Programs\Python\Python38\lib\site-packages\pyaudio.py",
> line 608, in read
>     return pa.read_stream(self._stream, num_frames, exception_on_overflow)

请告诉我如何解决这个问题

最佳答案

我已经在python中完成了语音识别,代码非常简单:

import speech_recognition as sr

rObject = sr.Recognizer()
audio = ''
with sr.Microphone() as source:
    print("Speak...")
    audio = rObject.listen(source, phrase_time_limit = 0)
    print("Stop.")
    try:
        text = rObject.recognize_google(audio, language ='en-US')
        print("You : "+ text)
    except:
        speak("Could not understand your audio...PLease try again !")
尝试一下,希望它能根据您想要的输出工作。

关于error-handling - 我无法在python中使用语音识别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62300947/

10-10 00:54