我正在尝试安装google assistant sdk,使用raspberry pi 3模型b和使用具有麦克风和扬声器(http://www.ebay.com/itm/Sabrent-External-Sound-Box-USB-SBCV/252367546463)的Sabrent usb的音频。运行代码时出错。
python -m googlesamples.assistant
错误堆栈:
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/pi/env/lib/python2.7/site-packages/googlesamples/assistant/__main__.py", line 273, in <module>
main()
File "/home/pi/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/pi/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/pi/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/pi/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/pi/env/lib/python2.7/site-packages/googlesamples/assistant/__main__.py", line 146, in main
flush_size=audio_flush_size
File "/home/pi/env/local/lib/python2.7/site-packages/googlesamples/assistant/audio_helpers/__init__.py", line 140, in __init__
blocksize=int(block_size/2), # blocksize is in number of frames.
File "/home/pi/env/local/lib/python2.7/site-packages/sounddevice.py", line 1491, in __init__
**_remove_self(locals()))
File "/home/pi/env/local/lib/python2.7/site-packages/sounddevice.py", line 1017, in __init__
'Error opening {0}'.format(self.__class__.__name__))
File "/home/pi/env/local/lib/python2.7/site-packages/sounddevice.py", line 2671, in _check
raise PortAudioError(msg)
sounddevice.PortAudioError: Error opening RawStream: Invalid sample rate
答案 0 :(得分:0)
令人惊讶的是,这个错误恰恰意味着它所说的。您的声音设备不支持您尝试使用的采样率(可能在Google事物中可配置;您没有说明它或您尝试过的样本)。 USB设备通常只支持48kHz的DAT格式音频。 ALSA(Linux最常用的声音驱动程序集)并没有掩盖这一事实。可以要求它进行转换,例如使用asoundrc来设置默认插件。
答案 1 :(得分:0)
我和你一样处于同样的问题但是,我可以通过编辑/home/pi/.asoundrc来解决这个问题,如下所示
pcm.!default { type asym capture.pcm "usb_mic" playback.pcm "jack_speaker" } pcm.usb_mic { type plug slave { pcm "hw:1,0" } } pcm.jack_speaker { type plug slave { pcm "hw:0,0" } }
https://github.com/googlesamples/assistant-sdk-python/issues/4
答案 2 :(得分:0)
我通过定义速率解决了这个问题,如下所示。在阅读文档here之前,我在网上没有其他东西可以为我解决这个问题,并且暗中摸索如何实现它。原来对我有用。
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "hw:0,0"
rate 48000
}
capture.pcm {
type plug
slave.pcm "hw:1,0"
}
}