Python语音识别无法使用SpeechRecognition 3.8.1库工作
在我的Python 3.8.6项目中,我为我的windows 10计算机安装了“pip安装SpeechRecognition”。下面是代码示例Python语音识别无法使用SpeechRecognition 3.8.1库工作,python,python-3.x,speech-recognition,speech-to-text,Python,Python 3.x,Speech Recognition,Speech To Text,在我的Python 3.8.6项目中,我为我的windows 10计算机安装了“pip安装SpeechRecognition”。下面是代码示例 import speech_recognition as sr listener = sr.Recognizer() try: with sr.Microphone() as source: print('Listening...') voice = lis
import speech_recognition as sr
listener = sr.Recognizer()
try:
with sr.Microphone() as source:
print('Listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
print(command)
except:
print("Something else went wrong")
pass
Something else went wrong
运行此代码后,输出如下:
import speech_recognition as sr
listener = sr.Recognizer()
try:
with sr.Microphone() as source:
print('Listening...')
voice = listener.listen(source)
command = listener.recognize_google(voice)
print(command)
except:
print("Something else went wrong")
pass
Something else went wrong
我已经在笔记本电脑中内置了麦克风,而且我还使用外置USB麦克风进行了检查。那么这里有什么问题?是否需要任何硬件配置来解决此问题?在PyPI上的语音识别中,您可以看到有一个PyAudio部分。这意味着您必须在计算机上安装PyAudio。但是,如果您插入了PyAudio,并且出现错误,则需要在不使用try-except块的情况下共享错误,这样我们就可以分析错误并给出解决方案
要安装PyAudio,请在终端中执行pip install PyAudio
有时pip install pyaudio
会引发类似以下错误:
Collecting PyAudio
Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Installing collected packages: PyAudio
Running setup.py install for PyAudio ... error
Complete output from command C:\Users\username\AppData\Local\Programs\Python\Python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\username\\AppData\\Local\\Temp\\pip-install-e5le61j0\\PyAudio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\username\AppData\Local\Temp\pip-record-adj3zivl\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win32-3.7
copying src\pyaudio.py -> build\lib.win32-3.7
running build_ext
building '_portaudio' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
----------------------------------------
Command "C:\Users\username\AppData\Local\Programs\Python\Python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\username\\AppData\\Local\\Temp\\pip-install-e5le61j0\\PyAudio\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\username\AppData\Local\Temp\pip-record-adj3zivl\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\username\AppData\Local\Temp\pip-install-e5le61j0\PyAudio\
修复此错误的步骤:
- 转到终端并执行python--version,对于Optimus Prime,他的版本是python 3.8.6
- 查找Python安装是64位还是32位,可以通过转到Python终端查看
- 根据您的Python版本和Python安装(64位/32位)下载
- 在下载控制盘文件(.whl)的目录中打开终端
- 然后执行
pip安装
你完了 首先不要阻止异常。请确保安装了pyAudio