1、安装SpeechRecognition第三方库
pip install SpeechRecognition
2、安装pocketsphinx第三方库,安装时,可能会报错error: command 'swig.exe' failed: No such file or directory
这时候需要安装,swig
swig下载地址:https://www.aliyundrive.com/s/XGvEKWH9r3c
下载之后,放在你想放的地方,然后配置环境变量
注意,无论是cmd,还是pycharm安装,都需要重启
最后执行命令:pip install pocketsphinx,可以正常安装
3、代码:
import speech_recognition as sr
def wav2txt():
r = sr.Recognizer()
# sudio = ""
with sr.AudioFile('./test.wav') as src:
sudio = r.record(src)
print(sudio)
print(r.recognize_sphinx(sudio))