FLAC conversion utility not available – consider installing the FLAC command line application on Spyder/Windows 10

Question:

I’m working on a speech recognition and following the example shown in this PythonCode page on Windows 10 with Spyder 5.1.5/Anaconda (Python 3.8.10).

I installed SpeechRecognition and pydub with conda install -c conda-forge, and when I run the following script:

with sr.AudioFile(filename) as source:
    audio_data = r.record(source)
    text = r.recognize_google(audio_data)
    print(text)

or more specifically (text = r.recognize_google(audio_data)), this error message shows up:

OSError: FLAC conversion utility not available - consider installing the FLAC command line application by running `apt-get install flac` or your operating system's equivalent

There’s a similar question but I couldn’t find the solution for the Windows environment where I don’t have apt-get install flac or brew.

Following this post, I’ve downloaded the flac.exe file and placed under C:WindowsSystem32. I can run flac on command line, but the same error shows up when I run the python script.

Does anyone know how to fix this problem?

Asked By: alpha

||

Answers:

According to the source code it is searching for a flac without exe extension that will not work in Windows. If that fails it looks for a file with a specific name (flac-win32.exe) in module folder.

You can either try to remove the extension of the file in the System32 folder or put the file in the module folder.

Answered By: viilpe

viilpe’s answer is correct, and would have worked for me except for the fact that my Windows computer refused to rename the file as just ‘flac’.

I ran pretty much this exact speech recognition code in Spyder, but I kept getting the same error as alpha. I tried viilpe’s solution, but it still didn’t work for me. I don’t know if something has updated or changed between now and 2017, but even though I put the flac file in my System32 folder and renamed it flac, my computer still treated it as being named ‘flac.exe’. I had to edit the source code, changing the line:

def get_flac_converter():
"""Returns the absolute path of a FLAC converter executable, or raises an OSError if none can be found."""
flac_converter = shutil_which("flac")  # check for installed version first

to:

def get_flac_converter():
"""Returns the absolute path of a FLAC converter executable, or raises an OSError if none can be found."""
flac_converter = shutil_which("flac.exe")  # check for installed version first

This allowed the module to find my flac file. For reference, these are lines 1094 – 1096 in the init.py file for the speech_recognition module.

So, for anyone getting this error in 2022 or later, and renaming your flac file doesn’t work, try this.

Answered By: Sam