2

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?

Ahmed saad
  • 31
  • 4

0 Answers0