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.
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: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: