pythonpython-3.xspeech-recognitionalsapulseaudio

problem with alsa in speech recognition(Python 3)


I have sound on my ubuntu20, I can play any audio; but the problem is when I'm using speech recognition, alsa doesn't work properly. I used speech recognition in windows, it was pain, but it worked. I have installed pyaudio,... so yeah it's not library problem.

I have done:

   1.Reinstalling alsa and pulseAudio.

   2.Checking which program is using sound card.

   3.Trying to specific device to be used in Microphone().

When i use: python -c "import pyaudio;audio=pyaudio.PyAudio();print([audio.get_device_info_by_index(i) for i in range(audio.get_device_count())])"

returns:

  ALSA lib pcm_dsnoop.c:604:(snd_pcm_dsnoop_open) unable to create IPC semaphore
  ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
  ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
  ALSA lib pcm.c:2642:(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_route.c:869:(find_matching_chmap) Found no matching channel map
  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 pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

  ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

  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
  ALSA lib pcm_dsnoop.c:604:(snd_pcm_dsnoop_open) unable to create IPC semaphore

  [{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.005804988662131519, 
  'defaultLowInputLatency': 0.005804988662131519, 'maxInputChannels': 2L, 'structVersion': 2L, 
  'hostApi': 0L, 'index': 0, 'defaultHighOutputLatency': 0.034829931972789115, 
  'maxOutputChannels': 2L, 'name': u'HDA Intel PCH: ALC3246 Analog (hw:0,0)', 
  'defaultHighInputLatency': 0.034829931972789115}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 1, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'HDA Intel 
  PCH: HDMI 0 (hw:0,3)', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 2, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'HDA Intel 
  PCH: HDMI 1 (hw:0,7)', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 3, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'HDA Intel 
  PCH: HDMI 2 (hw:0,8)', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 4, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'HDA Intel 
  PCH: HDMI 3 (hw:0,9)', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 5, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'HDA Intel 
  PCH: HDMI 4 (hw:0,10)', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 48000.0, 
  'defaultLowOutputLatency': 0.021333333333333333, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 6, 
  'defaultHighOutputLatency': 0.021333333333333333, 'maxOutputChannels': 128L, 'name': 
  u'sysdefault', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 7, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': 
  u'front', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 8, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': 
  u'surround40', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 9, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': 
  u'surround51', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 10, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 2L, 'name': 
  u'surround71', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 11, 
  'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 8L, 'name': 
  u'hdmi', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.007755102040816327, 'defaultLowInputLatency': 
  0.007755102040816327, 'maxInputChannels': 128L, 'structVersion': 2L, 'hostApi': 0L, 
  'index': 12, 'defaultHighOutputLatency': 0.023219954648526078, 'maxOutputChannels': 128L, 
  'name': u'samplerate', 'defaultHighInputLatency': 0.023219954648526078}, 
  {'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.007755102040816327, 
  'defaultLowInputLatency': 0.007755102040816327, 'maxInputChannels': 128L, 'structVersion': 
  2L, 'hostApi': 0L, 'index': 13, 'defaultHighOutputLatency': 0.023219954648526078, 
  'maxOutputChannels': 128L, 'name': u'speexrate', 'defaultHighInputLatency': 
  0.023219954648526078}, {'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 
  0.005804988662131519, 'defaultLowInputLatency': 0.005804988662131519, 'maxInputChannels': 
  8L, 'structVersion': 2L, 'hostApi': 0L, 'index': 14, 'defaultHighOutputLatency': 
  0.034829931972789115, 'maxOutputChannels': 8L, 'name': u'upmix', 
  'defaultHighInputLatency': 0.034829931972789115}, {'defaultSampleRate': 44100.0, 
  'defaultLowOutputLatency': 0.005804988662131519, 'defaultLowInputLatency': 
  0.005804988662131519, 'maxInputChannels': 6L, 'structVersion': 2L, 'hostApi': 0L, 'index': 
  15, 'defaultHighOutputLatency': 0.034829931972789115, 'maxOutputChannels': 6L, 'name': 
  u'vdownmix', 'defaultHighInputLatency': 0.034829931972789115}, {'defaultSampleRate': 
  48000.0, 'defaultLowOutputLatency': 0.021333333333333333, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 16, 
  'defaultHighOutputLatency': 0.021333333333333333, 'maxOutputChannels': 128L, 'name': 
  u'default', 'defaultHighInputLatency': -1.0}, {'defaultSampleRate': 48000.0, 
  'defaultLowOutputLatency': 0.021333333333333333, 'defaultLowInputLatency': -1.0, 
  'maxInputChannels': 0L, 'structVersion': 2L, 'hostApi': 0L, 'index': 17, ' 
  defaultHighOutputLatency': 0.021333333333333333, 'maxOutputChannels': 2L, 'name': u'dmix', 
  'defaultHighInputLatency': -1.0}]

Error:

 ALSA lib pcm_dsnoop.c:604:(snd_pcm_dsnoop_open) unable to create IPC semaphore
 ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
 ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
 ALSA lib pcm.c:2642:(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_route.c:869:(find_matching_chmap) Found no matching channel map
 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 pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

 

I'm using VS code and it's probably bug.The question is how can I get rid of it?


Solution

  • Hey guys i fixed that by installing voice control using sudo apt-get install pavucontrol.Run it by using pavucontrol in therminal.In voice control put recording device to 0.My laptop had built in mic and alsa know find it.