【问题标题】:how to solve these ALSA errors如何解决这些 ALSA 错误
【发布时间】:2023-03-08 18:18:01
【问题描述】:
import speech_recognition as sr

listener= sr.Recognizer()
try:
    with sr.Microphone() as source:
        print("hai say something...")
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        print(command)
except:
    pass

这是我的代码。当我尝试运行它时,它显示以下错误

ALSA lib pcm_dsnoop.c:641:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
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_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_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_dmix.c:1089:(snd_pcm_dmix_open) unable to open slave
hai say something...

我正在使用 conda env。我已经搜索了很多关于 ALSA 错误的信息,但只解决了 jackd2 错误。请帮我解决这个错误。

【问题讨论】:

  • 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 这些错误通过使用这个链接解决了itectec.com/ubuntu/…
  • 我可以看到模块正在工作。因为当我在终端中写这个评论 python -m speech_recognition 时。演示代码正在运行。错误仍然存​​在,但它重新认识了我所说的

标签: python python-3.x speech-recognition alsa libalsa


【解决方案1】:
import speech_recognition as sr

r = sr.Recognizer()
m = sr.Microphone()

try:
    print("A moment of silence, please...")
    with m as source: r.adjust_for_ambient_noise(source)
    print("Set minimum energy threshold to {}".format(r.energy_threshold))
    while True:
        print("Say something!")
        with m as source: audio = r.listen(source)
        print("Got it! Now to recognize it...")
        try:
            # recognize speech using Google Speech Recognition
            value = r.recognize_google(audio)

            # we need some special handling here to correctly print unicode characters to standard output
            if str is bytes:  # this version of Python uses bytes for strings (Python 2)
                print(u"You said {}".format(value).encode("utf-8"))
            else:  # this version of Python uses unicode for strings (Python 3+)
                print("You said {}".format(value))
        except sr.UnknownValueError:
            print("Oops! Didn't catch that")
        except sr.RequestError as e:
            print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))
except KeyboardInterrupt:
    pass

此代码可以工作,但 ALSA 错误仍然存​​在。我不知道为什么。

【讨论】:

    【解决方案2】:

    我在使用 Google Cloud AI 时遇到了同样的问题。

    我能够使用此处找到的示例抑制错误: https://stackoverflow.com/a/36958122/13327155

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      • 2011-07-25
      • 2014-06-04
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      相关资源
      最近更新 更多