语音识别中的alsa问题(Python 3)

problem with alsa in speech recognition(Python 3)

我的ubuntu20有声音,可以播放任何音频;但问题是当我使用语音识别时,alsa 无法正常工作。我在 windows 中使用了语音识别,这很痛苦,但它确实有效。我已经安装了 pyaudio,...所以是的,这不是库问题。

我完成了:

   1.Reinstalling alsa and pulseAudio.

   2.Checking which program is using sound card.

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

当我使用: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}]

错误:

 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

 

我正在使用 VS 代码,可能 bug.The 问题是我怎样才能摆脱它?

大家好,我通过使用 sudo apt-get install pavucontrol 安装 voice control 来解决这个问题。运行 通过在 therminal.In 语音控制中使用 pavucontrol 将录音设备设置为 0。我的笔记本电脑内置麦克风,alsa 知道找到它。