袖珍狮身人面像和虚拟助手

问题描述

我正在尝试将虚拟助手作为我的主要项目。所以我想安装pocket sphinx 包来离线运行它。如果有人知道这一点,请回答这个问题。

解决方法

我知道您正在使用 Pocketsphinx 进行语音到文本的转换。如果它用于将语音转换为 Python 中的文本(也可以离线)的 Pocketsphinx 包。 下面的注释用于安装软件包。

pip install SpeechRecognition
conda install swig
pip install pocketsphinx

安装pocketsphinx 后,您可能会收到类似“需要Microsoft Visual C++ 14.0 或更高版本。使用“Microsoft C++ 构建工具”获取它的错误:GNU bash 请安装“Microsoft Visual C++ 14.0”,然后执行“pip install pocketsphinx” 一旦安装了上述软件包,您就可以开始测试一些“.wav”文件以进行语音到文本的转换。

import speech_recognition as sr
AUDIO_FILE='C:\\Users\\Downloads\\test.wav'
    
r=sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
    audio=r.record(source)
text=r.recognize_sphinx(audio)
with open("result.txt","w") as text_file:
    text_file.write(format(text))