0

I’m building a Python voice assistant using the speech_recognition library.
Everything works perfectly when I run the code from PyCharm or the terminal,
but when I convert it to an .exe using Auto Py to Exe / PyInstaller,
I get this error as soon as the recognizer tries to process audio:

pygame 2.6.1 (SDL 2.28.4, Python 3.12.1) 
Welcome to Vision! 
Say any of the models name to activate. 
Say 'exit' to quit. 
Waiting for wake word... Listening... Exception in thread Thread-1 (chatbot): 
Traceback (most recent call last):   
File "threading.py", line 1073, in _bootstrap_inner   File "threading.py", line 1010, in run   
File "vision_v3.py", line 126, in chatbot   
File "jarvis_functions\essential_functions\voice_input.py", line 47, in record_text   
File "speech_recognition\recognizers\google.py", line 253, in recognize_legacy   
File "speech_recognition\recognizers\google.py", line 56, in build   
File "speech_recognition\recognizers\google.py", line 88, in build_data   
File "speech_recognition\audio.py", line 256, in get_flac_data   
File "subprocess.py", line 992, in __init__   
File "subprocess.py", line 1407, in _get_handles   
File "subprocess.py", line 1416, in _make_inheritable 
OSError: [WinError 50] The request is not supported 

I've tried to include all my folders and .env file with Auto Py to Exe:

--add-data "D:\pycharm\opencv\Vision\jarvis_functions;jarvis_functions" --add-data "D:\pycharm\opencv\Vision\sound_files\beep;sound_files/beep" --add-data "D:\pycharm\opencv\Vision\sound_files\cam;sound_files/cam"

Converting audio to WAV manually using:

wav_data = audio.get_wav_data()

Verified that everything works in Python directly, but the .exe fails.

This is a simplified code snippet:

import speech_recognition as sr  
r = sr.Recognizer()   
def record_text(): 
    try:         
        with sr.Microphone() as source:             
        r.adjust_for_ambient_noise(source, duration=0.2)             
        audio = r.listen(source)             
        text = r.recognize_google(audio, language="bg-BG")             
        return text.lower()     
    except sr.RequestError as e:         
        print(f"API error: {e}")     
    except sr.UnknownValueError:         
        print("Could not understand audio.") 

Why does the PyInstaller .exe version fail with [WinError 50] inside get_flac_data() when speech_recognition works perfectly in normal Python?

Do I need to bundle a flac.exe file manually, or is there a better way to make speech_recognition use WAV instead of FLAC so it works in compiled executables?

1
  • use ``` to format block of code/output/error. and ` to format only inline code. Commented Oct 27 at 17:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.