我是Raspbian上的Alsa的新手,我需要我的麦克风为豪猪/雪人热门单词检测提供16khz采样率。但是,我无法找到一种方法来做到这一点。我需要在我的“最后一年”项目中执行此操作,并且已经坚持了一个星期左右,但我无能为力。相同的麦克风/声卡可以在Windows(豪猪)上正常工作,但Raspbian可以提供“ errno -9997无效采样率”。
编辑代码:
import snowboydecoder
import sys
import signal
interrupted = False
def signal_handler(signal, frame):
global interrupted
interrupted = True
def interrupt_callback():
global interrupted
return interrupted
if len(sys.argv) == 1:
print("Error: need to specify model name")
print("Usage: python demo.py your.model")
sys.exit(-1)
model = sys.argv[1]
# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
print('Listening... Press Ctrl+C to exit')
# main loop
detector.start(detected_callback=snowboydecoder.play_audio_file,
interrupt_check=interrupt_callback,
sleep_time=0.03)
detector.terminate()
这是我的错误:
Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->capture, inParams, self->primeBuffers, hwParamsCapture, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2719
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
Traceback (most recent call last):
File "demo.py", line 27, in <module>
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
File "/home/pi/Downloads/snowboy/snowboydecoder.py", line 115, in __init__
stream_callback=audio_callback)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
IOError: [Errno -9997] Invalid sample rate
问题很可能与alsa有关,但无法即时将速率转换为16khz。如果有人知道该怎么做,那将有很大帮助。