编程语言
首页 > 编程语言> > python离线语音转文字

python离线语音转文字

作者:互联网

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))

标签:pocketsphinx,python,sr,swig,离线,sudio,语音,pip,安装
来源: https://blog.csdn.net/jiaweide123/article/details/118655470