【问题标题】:Python Speech Recognition,Pyaudio not listening but giving thisPython语音识别,Pyaudio不听但给出这个
【发布时间】:2020-09-05 06:59:49
【问题描述】:

我正在尝试使用 python 中的语音识别和 pyaudio 将语音转换为文本。它在转换预先录制的音频文件时工作正常,但是当我使用麦克风(外部)录制时,它没有在听而是显示:

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map

这是我的代码:

import speech_recognition as sr
r = sr.Recognizer()
mic = sr.Microphone()
with mic as source:
  print('say somthing')
  audio = r.listen(source)
 
print(r.recognize_google(audio))

【问题讨论】:

标签: python artificial-intelligence speech-to-text pyaudio


【解决方案1】:

试试这个代码块。即使在实时输入中,这在我的系统中也能正常工作。

import speech_recognition as sr
def myCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.listen(source, phrase_time_limit = 5)  
    try:
        command = r.recognize_google(audio).lower()
        print("you said: " + command)
        
    except sr.UnknownValueError:
        print("Sorry, Cant understand, Please say again")
        command = myCommand()
    return command

【讨论】:

  • 我可以隐藏这些行吗(ALSA lib 等)
  • 识别不佳,显示完全不同的文字
  • 那么您的驱动程序有问题。因为这对我来说非常好。尝试更新驱动程序。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-12
  • 2021-04-17
  • 2019-12-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多