Google Assistant snap (python + sound problems)

I’m a total beginner to please be gental.

I’m trying to build a snap that can build on Google Assistant. I naively thought I could just include

google-assistant-grpc, google-assistant-sdk, google-auth-oauthlib[tool], tenacity , sounddevice

As python packages, add pulseaudio as a plug and have a working system. Seems sound in a python snap is a bit tricky, can anyone tell me in broad terms what I’d need to do to get things working?

Currently, attempting to run google’s push to talk sample produces this error:

Traceback (most recent call last):
File “/snap/ga-matt-test/x12/bin/googlesamples-assistant-pushtotalk”, line 7, in
from googlesamples.assistant.grpc.pushtotalk import main
File “/snap/ga-matt-test/x12/lib/python3.5/site-packages/googlesamples/assistant/grpc/pushtotalk.py”, line 32, in
from . import (
File “/snap/ga-matt-test/x12/lib/python3.5/site-packages/googlesamples/assistant/grpc/audio_helpers.py”, line 25, in
import sounddevice as sd
File “/snap/ga-matt-test/x12/lib/python3.5/site-packages/sounddevice.py”, line 2678, in
_initialize()
File “/snap/ga-matt-test/x12/lib/python3.5/site-packages/sounddevice.py”, line 2634, in _initialize
_check(_lib.Pa_Initialize(), ‘Error initializing PortAudio’)
ffi.error: symbol ‘Pa_Initialize’ not found in library ‘’: /snap/ga-matt-test/x12/usr/bin/python3: undefined symbol: Pa_Initialize

Thanks

try adding “libpulse0” to your stage-packages …

Also, feel free to post your snapcraft.yaml for us to help with. Make sure to paste it inside three backticks so it shows as code - then it’s easier to copy/paste. Also note you may need to set some environment variables for pulse to work but as ogra suggests, add libpulse0 to stage packages first.

Yeah, I was just digging out my yaml when your post appeared. Not including it was pretty stupid.

name: ga-matt-test 
version: '0.3.3'
summary: Google assistant client for rPI
description: |
  Simple install for Google Assistant on rPI

grade: devel
confinement: devmode


apps:
  login:
    command: bin/google-oauthlib-tool
    plugs: [home, network]
  pushtotalk:
    command: bin/googlesamples-assistant-pushtotalk
    plugs: [pulseaudio, home, network]

parts:
  google-assistant:
    source: ./src
    source-tag: 0.3.3
    plugin: python
    python-packages: ['google-assistant-grpc','google-assistant-sdk','google-auth-oauthlib[tool]','tenacity','sounddevice']
    stage-packages: ['libpulse0']

It has literally none of my own code in it yet!

I’ve tried adding libpulse0 as suggested but the error remains the same.

Thanks both

I feared this may be the case.

For pulseaudio to work in snaps you need the following magic triplet of ingredients.

  1. pulseaudio plug
  2. libpulse0 in stage packages
  3. LD_LIBRARY_PATH set to find the above library

Here’s an example snap which does this via a launcher.

https://github.com/snapcrafters/pulsemixer

A part for the launcher script:

  launcher:
    plugin: dump
    source: snap/scripts
    organize:
      'launcher': bin/

And a launcher which sets the environment. Line 14 (and the if chunk above it) are needed. You’ll also need to change the launcher for your app to launch the app via the launcher. The pulsemixer snap should help there.

https://github.com/snapcrafters/pulsemixer/blob/master/snap/scripts/launcher#L14

Just shout if anything isn’t clear.

I tried all that over the weekend and it doesn’t seem to work. The actual error I posted is about PortAudio which means I’m running into problems earlier than pulseaudio’s involvement (I assume but TBH I’m guessing, so far I’ve managed to avoid having anything to do with sound).

I’ve also tried adding a part for portaudio and I can see it sitting in /lib and /usr/lib but I’m still getting the same problem.

Is it possible that I need to build the assistant stuff myself rather than using the versions pip installs?