首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Python语音识别‘子进程错误’

Python语音识别‘子进程错误’
EN

Stack Overflow用户
提问于 2015-01-09 03:44:48
回答 1查看 568关注 0票数 0

因此,我正在试用python中的语音识别模块(https://pypi.python.org/pypi/SpeechRecognition/),并尝试以下代码:

代码语言:javascript
代码运行次数:0
运行
复制
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data

try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

当这个程序运行时,我得到以下错误:

代码语言:javascript
代码运行次数:0
运行
复制
Thomass-MBP:Turret thomashitch$ python Speech.py 
Traceback (most recent call last):
  File "Speech.py", line 4, in <module>
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data
  File "/Library/Python/2.7/site-packages/SpeechRecognition-1.1.4-py2.7.egg/speech_recognition/__init__.py", line 208, in listen
    return AudioData(source.RATE, self.samples_to_flac(source, frame_data))
  File "/Library/Python/2.7/site-packages/SpeechRecognition-1.1.4-py2.7.egg/speech_recognition/__init__.py", line 129, in samples_to_flac
    raise ChildProcessError("FLAC conversion utility not available - consider installing the FLAC command line application using brew install flac")
NameError: global name 'ChildProcessError' is not defined

额外信息:在运行代码几秒钟后,代码才崩溃并产生错误。

有没有人知道是什么导致了这个错误,以及我该如何解决它?

谢谢,汤姆

EN

回答 1

Stack Overflow用户

发布于 2021-06-16 22:26:04

如果此操作不起作用,请尝试将您的python版本升级到3.6.6或3.8.4,它可以在这些版本的python中运行

代码语言:javascript
代码运行次数:0
运行
复制
import speech_recognition as sr
        
        def speechrecognizer(): 
            try:
                r = sr.Recognizer()
                with sr.Microphone() as audio:
                    print('Listening...')
                    voice = r.listen(audio)
                    print("Thinking...")
                    query = r.recognize_google(voice,language='en-in')
                    str(query)
                    print(f"{query}") 
        
            except:
              pass
            return query
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27848303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档