Open Lvjinhong opened 1 year ago
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.
Steps to reproduce
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".
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. (For example, "Ubuntu 16.04 LTS x64", "Windows 10 x64", or "macOS Sierra".)
My Python version is. (You can check this by running
python -V
.)My Pip version is. (You can check this by running
pip -V
.)My SpeechRecognition library version is. (You can check this by running
python -c "import speech_recognition as sr;print(sr.__version__)"
.)My PyAudio library version is / 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. (For example, from the Debian repositories, from Homebrew, or from the source code.)