简体   繁体   中英

Invalid sample rate while installing Google assistant SDK on Raspberry Pi model b Sabrent usb that has both mic and speakers

I am trying to install google assistant sdk, using raspberry pi 3 model b and for audio using Sabrent usb that has both mic and speakers ( http://www.ebay.com/itm/Sabrent-External-Sound-Box-USB-SBCV/252367546463 ). Error i am getting when running the code.

python -m googlesamples.assistant

Error Stack:

    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

Surprisingly, this error means exactly what it says. Your sound device does not support the sample rate you've attempted to use (which might be configurable in that Google thing; you didn't indicate what it, or you, tried). It's quite common for USB devices to only support DAT format audio, at 48kHz. ALSA (the most common set of sound drivers for Linux) does not hide this fact. It is possible to ask it to convert, for instance using an asoundrc to set up a default plugin.

I was at exactly same issue like you but, I could resolve this issue by editting /home/pi/.asoundrc like following

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

I solved this problem by defining the rate, as you can see below. Nothing else I could find online solved this for me until I read the docs here and I took a shot in the dark about how to implement it. Turns out it works for me.

pcm.!default {
  type asym
        playback.pcm {
        type plug
        slave.pcm "hw:0,0"
        rate 48000
   }
   capture.pcm {
     type plug
     slave.pcm "hw:1,0"
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM