FLAC conversion utility not available - consider installing the FLAC command line application

为君一笑 提交于 2019-12-11 16:40:04

问题


I am making a simple speech_recognition program in python3.6.3 here is the python code:

import speech_recognition as sr
import os

r = sr.Recognizer()
r.energy_threshold = 10000
with sr.Microphone() as source:
    print('Say something')
    audio = r.listen(source)
    print("Done")


try:
    text = r.recognize_google(audio)
    print(text)
    os.system("say '"+'I think you said,'+text+'!'+"'")

except Exception as e:
    print(e)

When I run it I get this error:

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

The surprising thing is I already have flac installed using brew. And I checked the flac installation using the terminal like this: $which flac /usr/local/bin/flac

this shows that flac is installed but no still being recognized. I will be my pleasure to have some help with this.


回答1:


The logic in that speech_recognition module is looking first for a flac executable in your $PATH. Double check on the command-line that flac is available:

$ which flac

This should tell you something like /usr/local/bin/flac , if you have installed flac with homebrew as you say. If so, make sure this $PATH environment variable is exposed to the Python program you are running. A debug trick to help, stick these lines in your program:

path = os.getenv('PATH')
print("Path is: %s" % (path,))
print("shutil_which gives location: %s" % (sr.shutil_which('flac'))

which will give you a more definitive clue about why flac isn't being picked up.




回答2:


if you have an issue with python finding flac and you already have flac installed with homebrew, then it means flac is probably located in this directory /usr/local/bin while python is looking for it in this directory usr/bin or usr/sbin. First check if flac is installed by running brew list flac. if it is installed, you will have to run this command in the terminal:

sudo ln -s /usr/local/bin/flac /usr/bin. OR sudo ln -s /usr/local/bin/flac /usr/sbin if you do this It might probably work fine.



来源:https://stackoverflow.com/questions/49737909/flac-conversion-utility-not-available-consider-installing-the-flac-command-lin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!