【问题标题】:Speech recognition module gives unexpected keyword argument 'exception on overflow' error语音识别模块给出了意外的关键字参数“溢出异常”错误
【发布时间】:2017-07-27 19:10:11
【问题描述】:

我正在尝试使用语音识别模块将语音转换为文本。

我的代码以:

开头
import speech_recognition as sr
r = sr.Recognizer()
m = sr.Microphone()
with m as source:
    print("Say Something...")
    audio = r.listen(source)

但是这会产生以下错误:

Traceback (most recent call last):
  File "<pyshell#8>", line 3, in <module>
    data = r.listen(source)
  File "/usr/local/lib/python3.4/dist-
packages/speech_recognition/__init__.py", line 553, in listen
    buffer = source.stream.read(source.CHUNK)
  File "/usr/local/lib/python3.4/dist-
packages/speech_recognition/__init__.py", line 161, in read
return self.pyaudio_stream.read(size, exception_on_overflow = False)
TypeError: read() got an unexpected keyword argument 'exception_on_overflow'

请有人解释发生了什么以及如何解决这个问题。

【问题讨论】:

    标签: python python-3.x speech-recognition speech-to-text


    【解决方案1】:

    试试这个:

    import speech_recognition as sr
    # obtain audio from the microphone
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print ('Attention! Say something')
        audio = r.listen(source)
    
    # recognize speech using Google Speech Recognition
    try:
    # for testing purposes, we're just using the default API key
    # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
        data='something'
        data = r.recognize_google(audio,language='en-US')
    
    except sr.UnknownValueError:
        print ('Attention ! Google could not understand audio')
        data='Could not understand anything'
    except sr.RequestError as e:
    
       print ('Attention ! Could not request results from Google service.')
    
    print data
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 2023-03-13
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 2022-09-30
      • 1970-01-01
      相关资源
      最近更新 更多