我不能在python中使用语音识别



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

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:UsersJeanAppDataLocalProgramsPythonPython38libsite-packagesspeech_recognition__init__.py",
> line 652, in listen
>     buffer = source.stream.read(source.CHUNK)   File "C:UsersJeanAppDataLocalProgramsPythonPython38libsite-packagesspeech_recognition__init__.py",
> line 161, in read
>     return self.pyaudio_stream.read(size, exception_on_overflow=False)   File
> "C:UsersJeanAppDataLocalProgramsPythonPython38libsite-packagespyaudio.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 !") 

试试吧,希望它会根据您想要的输出工作。

相关内容

  • 没有找到相关文章

最新更新