0

Goal

  • Suspend a Python process listening to pcm.record_right (for Google-Assistant)
  • Continue using pcm.record_left in a different python process (for Snowboy hotword detection)

Use Case

  • I want to use Snowboy to detect a hotword and then pass further voice interaction over to Google Assistant. Once the conversation finishes, I want to disable Google Assistant until I request it from Snowboy again.
  • I'm working with the Google-Assistant Library SDK and want to ensure that it is not listening, unless I permit it! (So using the SDK's mic-mute command isn't enough.)
  • I am using a Raspberry Pi 3B+ and an external USB stereo mic (Blue Snowball).
  • The reason that I want to suspend and un-suspend the Assistant process is that if I stop and start the program entirely, it takes too long (between when Snowboy detects the hotword and when the Assistant is ready).

What I've Tried

  • I've used the .asoundrc settings below. When I suspend the Assistant process (accessing the right mic), I run arecord using record_left, but get the error below. For testing purposes, I use kill -STOP <pid> and kill -CONT <pid>.
  • I also tried sharing the mic (using dsnoop) without separating the left and right channels, but got the same error.
  • I've also tried to trace where Google's SDK disables the mic, but their sample Python code loads a shared object called libassistant_embedder.so which is not open-source.

Questions

  • Is it possible to suspend a linux process that is using an ALSA device and still leave the device available?
  • If not, does anyone know if JACK-Audio might be able to do this?
  • Any other approaches that might work?

Error

ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave arecord: main:788: audio open error: Device or resource busy

Contents of ~/.asoundrc

pcm.!default {
  type asym
  capture.pcm "mic"
  playback.pcm "speaker"
}
pcm.mic {
  type plug
  slave {
    pcm "hw:1,0"
  }
}
pcm.speaker {
  type plug
  slave {
    pcm "hw:0,0"
  }
}
# see: https://alsa.opensrc.org/Dsnoop, section 1.2.3
pcm.record_left {
    type dsnoop
    ipc_key 234884
    slave {
        pcm "hw:1,0"
        channels 2
        rate 48000
    }
    bindings.0  0  #pick one of the stereo mic channels
}
pcm.record_right {
    type dsnoop
    ipc_key 2241234
    slave {
        pcm "hw:1,0"
        channels 2
        rate 48000
    }    
    bindings.0  1  #pick the other of the stereo mic channels
}
2
  • Not sure if ALSA can do that. Is Pulseaudio an option? It decouples transport from the sources/sinks, so use a Pulseaudio module to create two sources for right and left. Then you can suspend applications reading from one source, while applications reading from the other source continue.
    – dirkt
    Commented Jan 15, 2019 at 7:08
  • Thanks @dirkt, I'm open to all options. Reading up on Pulseaudio now.
    – Thor
    Commented Jan 16, 2019 at 5:01

1 Answer 1

0

Not sure if ALSA can do that.

Is Pulseaudio an option? It decouples transport from the sources/sinks, so use a Pulseaudio module to create two sources for right and left. Then you can suspend applications reading from one source, while applications reading from the other source continue.

You'll need two module-remap-source. Use pacmd or pactrl to make them. Play around until it works (remove them first with unload-module if you want to change anything), then put it into the Pulseaudio configuration files. Use pavucontrol to get an idea what sources/sinks you have, and what applications are using them, and to set volumes.

3
  • Thanks for the compass headings @dirkt! I got pulseaudio installed and played with a few pacmd commands. Slow going since day-job keeps me busy on other things, but I'll keep at PA and report back.
    – Thor
    Commented Jan 17, 2019 at 5:05
  • 1
    Hi @dirkt, thanks again. I got this working with pulseaudio. I was able to get two processes to connect to the default pulse-audio mic source using .asoundrc with pcm.!default pulse ctl.!default pulse I didn't even have to separate the left and right channels nor use the module-remap-source since pulseaudio didn't complain when one of the connected processes was suspended.
    – Thor
    Commented Jan 20, 2019 at 16:44
  • That's even simpler. :-)
    – dirkt
    Commented Jan 20, 2019 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .