Pyaudio 识别器错误找不到路径

Pyaudio recognizer error cannot find path

我写了一个基本的程序,基本上使用了pyttsx、speechrecognition和tkinter库。我有如下功能。

def dunno():
    with sr.Microphone() as source:
        audio = r.listen(source)
    try:
        print('1')
        textEntry = r.recognize(audio)
        print('2')
        print(textEntry)
        engine.say("You said: "+ textEntry)
        engine.runAndWait()
    except LookupError:
        engine.say("Sorry I couldn't understand what you said")
        engine.runAndWait()

我还定义了我的识别器和麦克风如下:

r = sr.Recognizer()

然后我使用 pyinstaller 通过命令提示符创建了一个 exe 文件,如下所示:

pyinstaller --onedir --onefile --name=somesing "C:\Users\ABCD\Desktop\SomeFolder\mycodefile.py"

正在创建 .exe 文件,没有任何问题。我还为另一个没有语音识别的版本创建了另一个 .exe 文件,但它运行良好。这个给出了一个错误的输出,如:

1
The system cannot find the path specified
1
The system cannot find the path specified
1
The system cannot find the path specified

这里我调用了函数dunno() 3次,都报错了。 python 脚本工作得很好,但 exe 文件不工作。

编辑:我也尝试过使用 wav 文件。我认为问题不在于麦克风。应该是关于里面的识别器的。

我认为问题是无法找到 speech_recognition 的捆绑 FLAC 转换实用程序,因为 PyInstaller 没有不知道这是必需的。

因此,您需要明确要求 PyInstaller 在构建过程中包含它。尝试使用以下内容创建名为 hook-speech_recognition.py 的文件:

from PyInstaller.hooks.hookutils import collect_data_files
datas = collect_data_files('speech_recognition')

构建时,将文件所在目录的路径作为值提供给 --additional-hooks-dir 参数,如下所示:

--additional-hooks-dir=<path_to_directory_of_hook_file>

Yoel 是正确的(但代码中的 speech_recognition 应该用双引号引起来)。

我在 this commit 中添加了有关如何使用 PyInstaller 设置库的详细说明。

我还向 PyInstaller 提交了 pull request 以默认包含 speech_recognition 集成。合并后,将不再需要添加这些挂钩。