Capturing microphone inside container with python

My goal is to capture audio from my mic from within a container and send it over mqtt.

To get this to work i’m using a python packaged called pyaudio to capture the audio. Which work fine on my desktop, but doesn’t work when i put the python script inside of a docker container i was working on. It won’t allow me to install to even install it.

I’m pretty sure that its pyaudio because i had a hard time install it on my desktop because it had many missing dependency in the pip install. When i remove pip install pyaudio i can install the add-on.

So i tried to add the original portaudio that pyaudio is a wrapper for and it didn’t seem to make any different.

Questions
Am i doing anything obviously wrong

Or is there another way i could grab audio from within a docker container

Or is there a way to see the errors that the docker container has when its installing. I didn’t see any errors inside home-assistant.log

#My Docker file

FROM %%BASE_IMAGE%%

ENV LANG C.UTF-8

# Copy data for add-on
COPY run.sh /
COPY index.py /
RUN chmod a+x /run.sh
RUN apk add --no-cache \
	    py-pip \
	    python \
	    python-dev \
	    portaudio-dev \
	&& pip install -U pip \
    && pip install \
           paho-mqtt \
           pyaudio

CMD [ "/run.sh" ]

When building dockerfike from command line you normally see results as commands are executed

What is run/create command for container?

So i’m working with Hass.io and the basic tutorial for addons
https://home-assistant.io/developers/hassio/addon_tutorial/

I might be answer your question wrong, but for the run/create command it create based on your
config values you set for the add-on. So i the audio attribute to pipe the devices forward to the container.

{
  "name": "mictest",
  "version": "30",
  "slug": "mictest",
  "description": "mictest",
  "startup": "system",
  "boot": "auto",
  "options": {},
  "audio": ["ALSA_OUTPUT", "ALSA_INPUT"],
  "schema": {},
  "privileged": ["SYS_ADMIN","NET_ADMIN", "SYS_RAWIO"],
  "tmpfs": "size=10m,rw"
}

I haven’t worked with hass.io or it’s addons but docs say you can "go to the Hass.io panel and in the supervisor card click on “View logs”. This should bring you to a page with the logs of the supervisor. "

The dockerfile is standard and should run in docker separately if you create a container. You can try testing dockerfile outside has.io.

Thanks for all the help.

I got it to work i need gcc and g++ to build pyaudio

FROM homeassistant/i386-base:latest

LABEL io.hass.version="51.0"

ENV LANG C.UTF-8

# Copy data for add-on
COPY run.sh /
COPY index.py /
RUN chmod a+x /run.sh
RUN apk add --no-cache \
	    py-pip \
	    python \
	    python-dev \
	    portaudio-dev \
	    gcc \
	    g++ \
    && pip install \
           paho-mqtt \
           pyaudio

EXPOSE 3000

#CMD [ "/run.sh" ]

Here i found this to run docs local to debug docker file quickly.