使用segress_recognition时ALSA错误消息

发布于 2025-02-05 14:00:14 字数 3460 浏览 2 评论 0原文

i am working on raspberry pi 4

def record_audio_en():
    with sr.Microphone(device_index=1) as source:  # microphone as source

        voice_data = ''
        try:
            recognizer.energy_threshold = 2000
            recognizer.pause_threshold = 1
        except:
            pass
        try:
            audio = recognizer.listen(source, None,3.8)  # listen for the audio via source
            voice_data = recognizer.recognize_google(audio, language='en-US')  # convert audio to text
        
        except sr.RequestError:

            error_handling("there is no internet connection")
        except:
            pass
        print(f">> {voice_data.lower()}")  # print what user said
        return voice_data.lower()

I am trying to run this code but each time I am facing the same error

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card

I am using microphone through sound card and it is working on the system and when trying to record sound file.但不使用Python代码。

录制声音作品

pi@raspberrypi:~ $ arecord --format=S16_LE --rate=16000 --file-type=wav out.wav
Recording WAVE 'out.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
pi@raspberrypi:~ $ aplay out.wave

我尝试了许多解决方案:

1-创建arecordrc文件以配置ALSA,但它不起作用。

pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

麦克风:

卡1

设备0

pcm.!default {
  type asym
  capture.pcm "mic"
}

pcm.mic {
  type plug
  slave {
    pcm "hw:1,0"
  }
}

2-在elsa.conf文件中更改,我已将卡从0更改为1。

defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.device 0

没有其他方法,还有其他方法吗?

i am working on raspberry pi 4

def record_audio_en():
    with sr.Microphone(device_index=1) as source:  # microphone as source

        voice_data = ''
        try:
            recognizer.energy_threshold = 2000
            recognizer.pause_threshold = 1
        except:
            pass
        try:
            audio = recognizer.listen(source, None,3.8)  # listen for the audio via source
            voice_data = recognizer.recognize_google(audio, language='en-US')  # convert audio to text
        
        except sr.RequestError:

            error_handling("there is no internet connection")
        except:
            pass
        print(f">> {voice_data.lower()}")  # print what user said
        return voice_data.lower()

I am trying to run this code but each time I am facing the same error

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.USB-Audio.pcm.hdmi.0:CARD=1,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card

I am using microphone through sound card and it is working on the system and when trying to record sound file. but not working with python code.

recording sound works

pi@raspberrypi:~ $ arecord --format=S16_LE --rate=16000 --file-type=wav out.wav
Recording WAVE 'out.wav' : Signed 16 bit Little Endian, Rate 16000 Hz, Mono
pi@raspberrypi:~ $ aplay out.wave

I had tried many solutions:

1- create arecordrc file to configure alsa but it did not work.

pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

mic:

card 1

device 0

pcm.!default {
  type asym
  capture.pcm "mic"
}

pcm.mic {
  type plug
  slave {
    pcm "hw:1,0"
  }
}

2- changing in elsa.conf file, i had changed card from 0 to 1.

defaults.ctl.card 1
defaults.pcm.card 1
defaults.pcm.device 0

nothing working, would there be another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文