-1

I'm trying to run two assistants at the same time. On the one hand I can run Alexa without any problems. On the other hand I can run the Google Assistant without any problems.

However when I try to run both at the same time, it gives me errors because one has exclusive access to my microphone.

After some reading I found out about the dsnoop plugin. This should allow me to share the microhpone between applications. So I tried changing my .asoundrc file to use dsnoop.

I tested this with arecord in two terminals and I can record at the same time without any problems. But as soon as I want to start the Google Assistant I get an error:

(Google) pi@Thomas:~ $ googlesamples-assistant-pushtotalk
INFO:root:Connecting to embeddedassistant.googleapis.com
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 "/home/pi/Assistants-Pi/Google/bin/googlesamples-assistant-pushtotalk", line 8, in <module>
    sys.exit(main())
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/googlesamples/assistant/grpc/pushtotalk.py", line 351, in main
    flush_size=audio_flush_size
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/googlesamples/assistant/grpc/audio_helpers.py", line 190, in __init__
    blocksize=int(block_size/2),  # blocksize is in number of frames.
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/sounddevice.py", line 1345, in __init__
    **_remove_self(locals()))
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/sounddevice.py", line 861, in __init__
    'Error opening {0}'.format(self.__class__.__name__))
  File "/home/pi/Assistants-Pi/Google/lib/python3.7/site-packages/sounddevice.py", line 2653, in _check
    raise PortAudioError(errormsg, err)
sounddevice.PortAudioError: Error opening RawStream: Invalid sample rate [PaErrorCode -9997]

I tried entering all different sample rates in my .asoundrc but none seem to work. Does anybody else have this problem or knows how to solve it?

This is how my .asoundrc file now looks (which works for arecord side by side in two terminals):

pcm.!default {
    type asym
    playback.pcm {
        type plug
        slave.pcm "output"
    }
    capture.pcm {
        type plug
        slave.pcm "input"
    }
}
pcm.output {
    type hw
    card 0
    rate 16000
}
ctl.!default {
    type hw
    card 0
}
pcm.input {
    type dsnoop
    card 1
}
IgorNikolaev
  • 1,053
  • 1
  • 12
  • 28

1 Answers1

0

this works for me (dsnoop part only - other is more complicated):

pcm.dsnoopUB1 {
    type dsnoop         # this plugin splits one capture stream to more
    ipc_key 2052        # (IPC = Inter-Process Communication) must be unique
    ipc_key_add_uid 0   # multi-user sharing
    ipc_perm 0666       # permissions for multi-user sharing
    slave {pcm "hw:UB1,0"; channels 1}  # HW identification (see arecord -l), micrpohone - mostly mono
}

pcm.!default {
    type asym
    playback.pcm "plug:assistJK"
    capture.pcm "plug:dsnoopUB1"
}

I tested it again and my conclusion is you need only ipc_key defined. In my case it works - I can start two (or more) instances of google assistant sdk without any problem.

Tomas
  • 1
  • 1
  • While it’s acceptable to provide code-only answers, it’s often more useful for the community if you can also provide an explanation of the code and help people understand _why_ it addresses the problem. That can reduce the number of follow-up questions, and help new developers understand the underlying concepts. Would you mind updating your question with additional detail? – Jeremy Caney May 11 '20 at 02:04