Python:OSError:[Errno -9985]在Raspberry PI 3B +上使用Snowboy和SpeechRecognition时设备不可用

马苏达

我正在3B +上建立个人助理。我现在想做的是使用Snowboy检测我的热词(工作正常),然后在检测到该热词后,使用SpeechRecognizer接收语音命令。热词检测工作正常,调用sr.Microphone()时发生错误。

示例代码:

import speech_recognition as sr
import snowboydecoder

def detected_callback():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Ready...')
        r.adjust_for_ambient_noise(source, duration=.2)
        audio = r.listen(source)

    try:
        command = r.recognize_google(audio).lower()
        print('You said: ' + command + '\n')

    except sr.UnknownValueError:
        print('Your last command couldn\'t be heard')
        comand = None

detector = snowboydecoder.HotwordDetector("SnowboyDependencies/Ancilla.pmdl", sensitivity=.5, audio_gain=1)
detector.start(detected_callback)

我收到以下输出:

INFO:snowboy:Keyword 1 detected at time: 2020-03-24 21:53:35
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2171
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2840
Traceback (most recent call last):
  File "sttTest.py", line 43, in <module>
    detector.start(detected_callback)
  File "/home/pi/AncillaFiles/SnowboyDependencies/snowboydecoder.py", line 221, in start
    callback()
  File "sttTest.py", line 27, in detected_callback
    with sr.Microphone(device_index = 2, sample_rate = 44100, chunk_size = 512) as source:
  File "/home/pi/.local/lib/python3.7/site-packages/speech_recognition/__init__.py", line 141, in __enter__
    input=True,  # stream is an input stream
  File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9985] Device unavailable

Snowboy工作正常。该程序将按预期运行,直到检测到该热门单词为止。我认为这一定与Snowboy和SpeechRecognition尝试使用麦克风这一事实有关。另外请注意,SpeechRecognition可以正常工作。如果我创建一个仅使用SpeechRecognition而不是Snowboy的程序,它将按预期工作。

我在运行Raspbian Buster的Raspberry Pi 3b +上使用Python3。

如果我可以提供更多信息,请告诉我。

马苏达

解决方案是在初始化麦克风Ex之前终止snowboy:

import speech_recognition as sr
import snowboydecoder

def detected_callback():
    detector.terminate() #change here
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Ready...')
        r.adjust_for_ambient_noise(source, duration=.2)
        audio = r.listen(source)

    try:
        command = r.recognize_google(audio).lower()
        print('You said: ' + command + '\n')

    except sr.UnknownValueError:
        print('Your last command couldn\'t be heard')
        comand = None

detector = snowboydecoder.HotwordDetector("SnowboyDependencies/Ancilla.pmdl", sensitivity=.5, audio_gain=1)
detector.start(detected_callback)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试在Raspberry Pi 3B上运行Lancache时出现“内存不足” Nginx错误

来自分类Dev

使用Ubuntu ARM64的Raspberry Pi 3B +上没有网络

来自分类Dev

使用 pip 错误安装 matplotlib(使用 raspberry pi 3b)

来自分类Dev

无法使用UBoot + Grub从USB驱动器引导raspberry pi 3b

来自分类Dev

将Raspberry Pi 3B +(Raspian Stretch)变成蓝牙耳机(HSP)

来自分类Dev

Raspberry Pi 3 B 型蓝牙和 Uart (Rx/Tx)

来自分类Dev

Python,Windows 和 Raspberry pi 3 之间的套接字

来自分类Dev

使用OpenCV,Python,Raspberry Pi 3的Ball Tracker

来自分类Dev

Raspberry PI 3、SerialPort 和奇怪的响应

来自分类Dev

Raspberry Pi Zero上的Python非法指令

来自分类Dev

在Rasberry Pi 3B +的serial0上输出时,如果写入syscall被其他内核进程中断,则将传输一个虚假字节

来自分类Dev

使用更新的Windows 10 IoT核心版时,Pi 3B在启动时出现0xc000014c错误

来自分类Dev

在Raspberry PI上使用Python和OpenCV进行图像处理

来自分类Dev

Raspberry Pi 1 B上的c ++ bass和RapidXml

来自分类Dev

Raspberry Pi上的Tensorflow

来自分类Dev

Raspberry Pi和GitLab

来自分类Dev

NodeJS和Raspberry Pi

来自分类Dev

QEMU和Raspberry Pi

来自分类Dev

使用Python 3在(Raspberry Pi的)X服务器上显示全屏jpeg

来自分类Dev

使用Python 3在(Raspberry Pi的)X服务器上显示全屏jpeg

来自分类Dev

在Raspberry Pi上使用Python 3,如何调用MPlayer并传递URL

来自分类Dev

使用Raspberry Pi 3,OpenCV和Python的运动跟踪器

来自分类Dev

使用OpenCV,Python和Raspberry Pi 3的球追踪器(带摄像头模块)

来自分类Dev

Raspberry Pi 3上的Streisand Effect和Turnkey Linux

来自分类Dev

Geckodriver 和 Firefox 在 Raspberry Pi 3 上是否兼容?

来自分类Dev

在Raspberry Pi 2 Model B上安装Ubuntu

来自分类Dev

Raspberry Pi 3模型B上的Kali Linux-WiFi问题

来自分类Dev

raspberry pi 3 B 上的登录 Citadel 邮件服务器问题

来自分类Dev

Raspberry Pi 3 B+ 上的 Ubuntu Server 20.04 定期崩溃

Related 相关文章

  1. 1

    尝试在Raspberry Pi 3B上运行Lancache时出现“内存不足” Nginx错误

  2. 2

    使用Ubuntu ARM64的Raspberry Pi 3B +上没有网络

  3. 3

    使用 pip 错误安装 matplotlib(使用 raspberry pi 3b)

  4. 4

    无法使用UBoot + Grub从USB驱动器引导raspberry pi 3b

  5. 5

    将Raspberry Pi 3B +(Raspian Stretch)变成蓝牙耳机(HSP)

  6. 6

    Raspberry Pi 3 B 型蓝牙和 Uart (Rx/Tx)

  7. 7

    Python,Windows 和 Raspberry pi 3 之间的套接字

  8. 8

    使用OpenCV,Python,Raspberry Pi 3的Ball Tracker

  9. 9

    Raspberry PI 3、SerialPort 和奇怪的响应

  10. 10

    Raspberry Pi Zero上的Python非法指令

  11. 11

    在Rasberry Pi 3B +的serial0上输出时,如果写入syscall被其他内核进程中断,则将传输一个虚假字节

  12. 12

    使用更新的Windows 10 IoT核心版时,Pi 3B在启动时出现0xc000014c错误

  13. 13

    在Raspberry PI上使用Python和OpenCV进行图像处理

  14. 14

    Raspberry Pi 1 B上的c ++ bass和RapidXml

  15. 15

    Raspberry Pi上的Tensorflow

  16. 16

    Raspberry Pi和GitLab

  17. 17

    NodeJS和Raspberry Pi

  18. 18

    QEMU和Raspberry Pi

  19. 19

    使用Python 3在(Raspberry Pi的)X服务器上显示全屏jpeg

  20. 20

    使用Python 3在(Raspberry Pi的)X服务器上显示全屏jpeg

  21. 21

    在Raspberry Pi上使用Python 3,如何调用MPlayer并传递URL

  22. 22

    使用Raspberry Pi 3,OpenCV和Python的运动跟踪器

  23. 23

    使用OpenCV,Python和Raspberry Pi 3的球追踪器(带摄像头模块)

  24. 24

    Raspberry Pi 3上的Streisand Effect和Turnkey Linux

  25. 25

    Geckodriver 和 Firefox 在 Raspberry Pi 3 上是否兼容?

  26. 26

    在Raspberry Pi 2 Model B上安装Ubuntu

  27. 27

    Raspberry Pi 3模型B上的Kali Linux-WiFi问题

  28. 28

    raspberry pi 3 B 上的登录 Citadel 邮件服务器问题

  29. 29

    Raspberry Pi 3 B+ 上的 Ubuntu Server 20.04 定期崩溃

热门标签

归档