繁体   English   中英

Windows安装Flac命令行工具

[英]Installing Flac command line tool on Windows

情况

我正在尝试让SpeechRecognition在 Python 中工作。

  • 操作系统:Windows 10
  • 系统:树莓派 4 4GB
  • Python 版本:3.9.0 32bit

源代码

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

所以我从https://xiph.org/flac/download下载了 Flac。 我为 Windows 安装了最新版本。接下来,我解压缩文件并运行 64 位 .exe 文件和 32 位 .exe 文件。

当我在命令提示符中键入“Flac”时,它说:

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

我需要将 Flac 添加到我的系统环境变量吗? 如果是的话怎么办? 如果不; 到底是怎么回事?

经过一些研究,我发现您可以将 .exe 文件放在 C:\Windows\System32 文件夹中,以便在命令提示符下使用 flac 命令工具。

我遇到了同样的问题。 最后我解决了使用以下步骤:

  1. Go转flac下载页面
  2. 选择操作系统(Windows,在你的情况下)
  3. 下载win.zip版本(最新),可能在页面末尾。 我下载了这个(1.3.4-win.zip)
  4. 移至下载目录并解压(您可以简单地使用Extract Here
  5. 根据您的系统架构移动到win64win32
  6. 复制flac.exe粘贴到C:\Windows\System32这个目录里面。

尝试运行您的代码。 如果执行成功,则无需执行最后一步。 如果没有,也执行第 7 步。

  1. 删除.exe .ie 重命名为flac

我也必须执行最后一步。 就这样

试试这个代码

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM