gpt4 book ai didi

python - 语音识别无法正常工作(未检测到麦克风)

转载 作者:行者123 更新时间:2023-12-02 23:29:34 36 4
gpt4 key购买 nike

我想用语音识别做一个小程序。

这是我的代码(经典代码):

import speech_recognition as sr
r = sr.Recognizer()

with sr.Microphone() as source:
print("SAY SOMETHING")
audio = r.listen(source,timeout=3, phrase_time_limit=3)
print("TIME OVER")
try:
print("TEXTE : "+r.recognize_google(audio, language="fr-FR"))
except Exception:
print("ERROR")

但是,当我尝试启动程序时,出现此错误:

ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:869:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channeljack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Traceback (most recent call last):
File "record.py", line 6, in <module>
with sr.Microphone() as source:
File "/usr/lib/python2.7/site- packages/speech_recognition/__init__.py", line 86, in __init__
device_info = audio.get_device_info_by_index(device_index) if
device_index is not None else audio.get_default_input_device_info()
File "/usr/lib64/python2.7/site-packages/pyaudio.py", line 949, in
get_default_input_device_info
device_index = pa.get_default_input_device()
IOError: No Default Input Device Available



当我做 arecord -l时,我有这个:

**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC298 Analog [ALC298 Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0



附言:麦克风可以与Skype或Google等任何软件配合使用

最佳答案

尝试:更改默认的麦克风设备。

关于python - 语音识别无法正常工作(未检测到麦克风),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56189463/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com