speech_recognition
speech_recognition copied to clipboard
Flac and Machine issue using Mac m1
Steps to reproduce
I am using 2021 macbook pro m1 I follow the normal step on pypi.org using pycharm IDE just like: brew install pyaudio brew install portaudio sudo pip install pyaudio (replace pip with pip3 if using Python 3). pip install speechrecognition brew install flac
------------------------------------------>-----------------<-------------------------------------------------
It woks fine if I use it on command Line like this:
python -m speech_recognition
------------------------------------------>-----------------<------------------------------------------------- But if I use this code in my Pycharm IDE:
import speech_recognition as sr
try: print("A moment of silence, please...") while True: print("Say something!") with m as source: audio = r.listen(source) print("Got it! Now to recognize it...") try: # recognize speech using Google Speech Recognition value = r.recognize_google(audio)
print("You said {}".format(value))
except sr.UnknownValueError:
print("Oops! Didn't catch that")
except sr.RequestError as e:
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))
except KeyboardInterrupt: pass
I got an OSError about FLAC:
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
------------------------------------------>-----------------<-------------------------------------------------
So I took a look on init.py file It turn out that my machine is not on this list elif system == "Darwin" and machine in {"i686", "i786", "x86", "x86_64", "AMD64"}:
It also seems like "flac-mac" binary file is not on directory "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/speech_recognition/"
so, therefore this path won't be found "flac_converter = os.path.join(base_path, "flac-mac")" on init.py file.
------------------------------------------>-----------------<------------------------------------------------- ========> Time to Fix it <========> Heyyyy, Let Fix it. <================================== So, using command line type : which flac This will give you the path to flac, in my case I got "/opt/homebrew/bin/flac" So, let copy that with the name "flac-mac" like this:
"cp /opt/homebrew/bin/flac /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/speech_recognition/flac-mac"
So, the last step is to add your machine (for mac m1, it is 'arm64') on list just like this:
elif system == "Darwin" and machine in {"i686", "i786", "x86", "x86_64", "AMD64", "arm64"}:
----------------------------------->----------------<---------------------------------------------
If you want to know your machine and your system, run this code:
import platform system, machine = platform.system(), platform.machine() print(system) print(machine)
Please add "arm64" to the audio.py file. It is fixed right away.
elif system == "Darwin" and machine in {
"i686",
"i786",
"x86",
"x86_64",
"AMD64",
"arm64"
}:
@youssouf0123 @whateverfast Thank you for reporting and sharing how to fix. Merged into master