I am running a docker container with the python code that records the sound for few seconds using the host MacBook Pro build in microphone.
Part of my challenge is to determine how to provide access/share Macbook Pro microphone inside the Docker container. Most of the existing questions on stack overflow or elsewhere provide solutions for Linux based distros but I don't have much luck to do the same with mac os.
The OS version details:
System Version: macOS 10.14.2 (18C54)
Kernel Version: Darwin 18.2.0
Docker:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:39 2019
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false
The python code is simple and working as expected on the host.
import sounddevice as sd
import numpy as np
fs = 48000
duration=5
rec = sd.rec(int(duration * fs), samplerate=fs, channels=1, blocking=True)
print(rec)
Here is the docker file:
FROM python:3
RUN apt-get -y update
RUN apt-get -y install libasound-dev
RUN apt-get -y install portaudio19-dev
WORKDIR /usr/src/app
COPY requirements.txt ./
COPY AudioRecordingTest.py ./
RUN pip install -r requirements.txt
CMD [ "python", "./AudioRecordingTest.py" ]
docker build -t audiorecording:1.0 .
docker run -it --rm --device --privileged=true DONT_KNOW_ABOUT_THIS_PART:/dev/snd audiorecording:1.0
Ideally should able to mount/share the microphone as you do when Linux is the host. If not what are the other possible solutions?
docker run -it --rm --device --privileged=true DONT_KNOW_ABOUT_THIS_PART:/dev/snd audiorecording:1.0
pulseaudio
using homebrew but that directory doesn't exists. – Precocity