speech_recognition
speech_recognition copied to clipboard
FLAC conversion utility not available
Steps to reproduce
- (How do you make the issue happen? Does it happen every time you try it?)
- (Make sure to go into as much detail as needed to reproduce the issue. Posting your code here can help us resolve the problem much faster!)
- (If there are any files, like audio recordings, don't forget to include them.)
Expected behaviour
(What did you expect to happen?)
it can run normally.
Actual behaviour
Although I have installed the necessary libraries for speech recognition, such as PyAudio, PocketSphinx, and FLAC, and can run the FLAC utility in the command line, my program still cannot find the path to FLAC and displays the error message "OSError: FLAC conversion utility not available". (What happened instead? How is it different from what you expected?)
Although I have installed the necessary libraries for speech recognition, such as PyAudio, PocketSphinx, and FLAC, and can run the FLAC utility in the command line, my program still cannot find the path to FLAC and displays the error message "OSError: FLAC conversion utility not available".
(If the library threw an exception, paste the full stack trace here).
Traceback (most recent call last):
File "D:\1SoftWare\0Code\anaconda\envs\DataScience\lib\site-packages\IPython\core\interactiveshell.py", line 3433, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-8c38be5ab2f3>", line 1, in <module>
runfile('D:\\0Data\\0AI_Python\\0project\\1NLP\\语音与文字\\main.py', wdir='D:\\0Data\\0AI_Python\\0project\\1NLP\\语音与文字')
File "D:\1SoftWare\0Code\IDE\0Python\PyCharm 2022.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\1SoftWare\0Code\IDE\0Python\PyCharm 2022.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:\0Data\0AI_Python\0project\1NLP\语音与文字\main.py", line 61, in <module>
voice_input()
File "D:\0Data\0AI_Python\0project\1NLP\语音与文字\main.py", line 56, in voice_input
text = r.recognize_google(audio,language='zh-CN')
File "D:\1SoftWare\0Code\anaconda\envs\DataScience\lib\site-packages\speech_recognition\__init__.py", line 879, in recognize_google
flac_data = audio_data.get_flac_data(
File "D:\1SoftWare\0Code\anaconda\envs\DataScience\lib\site-packages\speech_recognition\__init__.py", line 495, in get_flac_data
flac_converter = get_flac_converter()
File "D:\1SoftWare\0Code\anaconda\envs\DataScience\lib\site-packages\speech_recognition\__init__.py", line 1733, in get_flac_converter
raise 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")
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
System information
The issue was that, after the final debugging, I found that the problem was in the initialization file where the path to FLAC was searched for as "flac". However, for the Windows system, it should be "flac.exe". After changing the path to "flac.exe", the program can run normally.
(Delete all the statements that don't apply.)
My system is <INSERT SYSTEM HERE>. (For example, "Ubuntu 16.04 LTS x64", "Windows 10 x64", or "macOS Sierra".)
My Python version is <INSERT VERSION HERE>. (You can check this by running python -V
.)
My Pip version is <INSERT VERSION HERE>. (You can check this by running pip -V
.)
My SpeechRecognition library version is <INSERT VERSION HERE>. (You can check this by running python -c "import speech_recognition as sr;print(sr.__version__)"
.)
My PyAudio library version is <INSERT VERSION HERE> / I don't have PyAudio installed. (You can check this by running python -c "import pyaudio as p;print(p.__version__)"
.)
My microphones are: (You can check this by running python -c "import speech_recognition as sr;print(sr.Microphone.list_microphone_names())"
.)
My working microphones are: (You can check this by running python -c "import speech_recognition as sr;print(sr.Microphone.list_working_microphones())"
.)
I installed PocketSphinx from <INSERT SOURCE HERE>. (For example, from the Debian repositories, from Homebrew, or from the source code.)
I had the same error so I looked at the implementation and found out that on my Windows x64 PC the platform.machine() returns an empty string, which is not accounted for while checking the user machine, leading to it jumping straight to the error, even if the packaged binaries are present and useable. I used to be able to run this module just fine so it seems to be a problem with the Python install on my end, but still, having this issue solved would be a plus for portability. Here are my specs: OS: Windows 11 Home 23H2 x86_64 CPU: AMD Ryzen 5 3600 6-Core Processor
btw there seems to be a workaround for Windows but in no way should be used in a published application
I found out what the issue for this is. When you install it one of the site-package files is this audio.py file. This is where it checks for flac using these two functions
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
if flac_converter is None: # flac utility is not installed
raise 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"
)
# mark FLAC converter as executable if possible
try:
# handle known issue when running on docker:
# run executable right after chmod() may result in OSError "Text file busy"
# fix: flush FS with sync
if not os.access(flac_converter, os.X_OK):
stat_info = os.stat(flac_converter)
os.chmod(flac_converter, stat_info.st_mode | stat.S_IEXEC)
if "Linux" in platform.system():
os.sync() if sys.version_info >= (3, 3) else os.system("sync")
except OSError:
pass
return flac_converter
def shutil_which(pgm):
"""Python 2 compatibility: backport of ``shutil.which()`` from Python 3"""
path = os.getenv("PATH")
for p in path.split(os.path.pathsep):
p = os.path.join(p, pgm)
if os.path.exists(p) and os.access(p, os.X_OK):
return p
which calls the first function WITH 'flac' AS THE ARGUMENT. I'm on windows so it needs to be called with flac.exe! They also don't bother to just use the shutil.which("flac") when python 3 is available.
btw there seems to be a workaround for Windows but in no way should be used in a published application
Like referenced here, changing flac.exe to flac resolves the issue for this reason.