Python语音识别,Pyaudio不监听但显示此信息

我正在尝试使用Python中的语音识别和Pyaudio将语音转换为文本。转换预录制的音频文件时一切正常,但当我使用麦克风(外部)录音时,它不监听,反而显示以下信息:

ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rearALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfeALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.sideALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel mapALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel mapALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel mapALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map

这是我的代码:

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

回答:

尝试使用以下代码块。在我的系统中,即使是实时输入也能完美运行。

import speech_recognition as srdef 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

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注