'Installing Flac command line tool on Windows

Situation

I am trying to make SpeechRecognition work in Python.

  • OS: Windows 10
  • System: RaspBerry PI 4 4GB
  • Python Version: 3.9.0 32bit

Source code

import speech_recognition as sr

r = sr.Recognizer()
with sr.Microphone() as source:
    r.pause_threshold = 0.5
    voice = r.listen(source)
    command = r.recognize_google(voice, language="nl-NL")
    command = command.lower()
    r.adjust_for_ambient_noise(source, duration=0.5)

Output

C:\Users\user\Documents\user\user-master\userv2\user\Static>py test.py
Traceback (most recent call last):
  File "C:\Users\user\Documents\user\user-master\userv2\user\Static\test.py", line 7, in <module>
    command = r.recognize_google(voice, language="nl-NL")
  File "C:\Users\user\AppData\Local\Programs\Python\Python39-32\lib\site-packages\speech_recognition\__init__.py", line 826, in recognize_google
    flac_data = audio_data.get_flac_data(
  File "C:\Users\user\AppData\Local\Programs\Python\Python39-32\lib\site-packages\speech_recognition\__init__.py", line 445, in get_flac_data
    flac_converter = get_flac_converter()
  File "C:\Users\user\AppData\Local\Programs\Python\Python39-32\lib\site-packages\speech_recognition\__init__.py", line 1196, 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

So I downloaded Flac from https://xiph.org/flac/download. I installed the latest version for Windows. Next, I unzipped the file and ran the 64-bit .exe files and 32-bit .exe files.

When I type 'Flac' in the command prompt, It says:

'flac' is not recognized as an internal or external command,
operable program or batch file.

Do I need to add Flac to my System Environment Variables? If yes how so? If not; what is going on?



Solution 1:[1]

After some research I found that you can put the .exe file in your C:\Windows\System32 folder in order to use flac command tools in the command prompt.

Solution 2:[2]

I was facing the same problem. Finally I resolved using the following steps:

  1. Go to flac download page
  2. Choose OS (Windows, in your case)
  3. Download win.zip version (latest), probably at the end of the page. I downloaded this one (1.3.4-win.zip)
  4. Move to the download directory and extract it (You can simple use Extract Here)
  5. Move to win64 or win32 according to your system architecture
  6. Copy flac.exe and paste it inside C:\Windows\System32 this directory.

Try running your code. If it executes successfully, No need to do last step. If not, perform 7th step too.

  1. Remove .exe .i.e. Rename it to flac

I had to perform the last step too. That's all

Solution 3:[3]

Try this code

import speech_recognition as sr
from time import ctime
import os
import playsound 
from gtts import gTTS

def speak(audioString):
    tts = gTTS(text=audioString, lang='en')
    tts.save("audio.mp3")
    playsound.playsound("audio.mp3", True)
    os.remove("audio.mp3")

def recordAudio():
    # Record Audio
    r = sr.Recognizer()
    
    with sr.Microphone() as source:
        print("Say somthing...")
        audio = r.listen(source, phrase_time_limit=2)

    data = ""
    try:
        data = r.recognize_google(audio)
        print("You said: " + data)
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service; {0}".format(e))

    return data

def jarvis(data):
    if "how are you" in data:
        speak("I am fine")

    if "what time" in data:
        speak(ctime())

speak("Hi Osama, what can I do for you?")

while True:
    data = recordAudio()
    jarvis(data)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Incendium
Solution 2 ARHAM RUMI
Solution 3 every skills