Pyaudio recognizer error cannot find path

570 views Asked by At

I have written a basic program that uses pyttsx, speechrecognition and tkinter libraries basically. I have a function like as follows.

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

Also I have defined my Recognizer and microphone as follows:

r = sr.Recognizer()

Then I have created an exe file using pyinstaller by using command prompt like as follows:

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

It is creating the .exe file without any problem. Also I have created another .exe file for another version that is without speech recognition but it and it is working well. This one gives an output with error like:

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

Here I have called the function dunno() three times and have taken this error. The python script is working really nice butexe file is not working.

Edit: I have tried with a wav file too. I don't think problem is about Microphone. It should be about the recognizer inside.

2

There are 2 answers

0
Yoel On BEST ANSWER

I think the problem is that speech_recognition's bundled FLAC conversion utility can't be located since PyInstaller doesn't know it's required.

Therefore, you need to explicitly ask PyInstaller to include it during the build process. Try creating a file called hook-speech_recognition.py with the following content:

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

When building, supply the path to the directory in which you placed the file as a value to the --additional-hooks-dir argument, as follows:

--additional-hooks-dir=<path_to_directory_of_hook_file>
2
Anthony Zhang On

Yoel is correct (but speech_recognition in the code should be in double quotes).

I have added detailed instructions for how to set up the library with PyInstaller in this commit.

I have also submitted a pull request to PyInstaller to include speech_recognition integration by default. Once merged, adding these hooks will no longer be necessary.