From 39fa1c9c1223929b6883b26963bd7b2a51b76adc Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 12:43:38 -0700 Subject: [PATCH 01/19] feat: init adding pulseaudio --- Dockerfile | 2 +- docker/run | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93d22e1..2dfb6eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils + apt-get install --yes --no-install-recommends alsa-utils libpulse0 WORKDIR /app diff --git a/docker/run b/docker/run index 3f79e84..1380ea3 100755 --- a/docker/run +++ b/docker/run @@ -16,9 +16,14 @@ if [ -z "${device}" ]; then exit 1 fi +if [ -z "${command}" ]; then + command = "aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" +fi + /app/script/run \ --uri tcp://0.0.0.0:10601 \ - --program "aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" \ + --program "${command}" \ --rate 22050 \ --width 2 \ --channels 1 "${args[@]}" + \ No newline at end of file From 4cbc4c80b45059e9cf10108b49e65441e85974fa Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 12:57:13 -0700 Subject: [PATCH 02/19] fix: flipping command to program --- docker/run | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docker/run b/docker/run index 1380ea3..4409847 100755 --- a/docker/run +++ b/docker/run @@ -16,13 +16,13 @@ if [ -z "${device}" ]; then exit 1 fi -if [ -z "${command}" ]; then - command = "aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" +if [ -z "${program}" ]; then + program = "aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi /app/script/run \ --uri tcp://0.0.0.0:10601 \ - --program "${command}" \ + --program "${program}" \ --rate 22050 \ --width 2 \ --channels 1 "${args[@]}" From 399e5811d02784c07a34b4f44cd182e3d8d0651c Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 13:00:14 -0700 Subject: [PATCH 03/19] fix: adding pulseaudio-utils --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2dfb6eb..76bf88e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils libpulse0 + apt-get install --yes --no-install-recommends alsa-utils pulseaudio-utils WORKDIR /app From 658670db660cf6c3e1d54097b8e60582ede909e3 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 13:05:34 -0700 Subject: [PATCH 04/19] fix: more adding pulseaudio --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 76bf88e..ea7ff5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils pulseaudio-utils + apt-get install --yes --no-install-recommends alsa-utils pulseaudio pulseaudio-utils WORKDIR /app From ba70c1f4865ac33d8e6bad81737d580be33a2d62 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 13:42:39 -0700 Subject: [PATCH 05/19] feat: more debug lines --- wyoming_snd_external/__main__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wyoming_snd_external/__main__.py b/wyoming_snd_external/__main__.py index 80bdc8a..9c922e1 100644 --- a/wyoming_snd_external/__main__.py +++ b/wyoming_snd_external/__main__.py @@ -94,6 +94,7 @@ async def handle_event(self, event: Event) -> bool: elif AudioStop.is_type(event.type): await self.write_event(Played().event()) elif AudioChunk.is_type(event.type): + _LOGGER.debug("Handling Chunk %s", self.command) await self._start_proc() chunk = AudioChunk.from_event(event) @@ -122,6 +123,7 @@ async def _stop_proc(self) -> None: if self._proc is None: return + _LOGGER.debug("Stopping %s", self.command) try: self._proc.stdin.write_eof() await self._proc.stdin.wait_closed() From 910210c9fb447cd90a76dab89a197237c48d1597 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 14:08:34 -0700 Subject: [PATCH 06/19] fix: defining program --- docker/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/run b/docker/run index 4409847..1d5b11a 100755 --- a/docker/run +++ b/docker/run @@ -17,7 +17,7 @@ if [ -z "${device}" ]; then fi if [ -z "${program}" ]; then - program = "aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" + program="aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi /app/script/run \ From b3e8d07774bc64456a311c18056c500caeb0701e Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sat, 27 Apr 2024 14:19:29 -0700 Subject: [PATCH 07/19] feat: adding more logging --- wyoming_snd_external/__main__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wyoming_snd_external/__main__.py b/wyoming_snd_external/__main__.py index 9c922e1..c8d1e33 100644 --- a/wyoming_snd_external/__main__.py +++ b/wyoming_snd_external/__main__.py @@ -114,9 +114,12 @@ async def _start_proc(self) -> None: return _LOGGER.debug("Running %s", self.command) - self._proc = await asyncio.create_subprocess_exec( - self.command[0], *self.command[1:], stdin=asyncio.subprocess.PIPE - ) + try: + self._proc = await asyncio.create_subprocess_exec( + self.command[0], *self.command[1:], stdin=asyncio.subprocess.PIPE + ) + except Exception as e: + _LOGGER.error("Unable to create subprocess. %s", e) assert self._proc.stdin is not None async def _stop_proc(self) -> None: From e3ea3dfc0ea40fe60dd7192f0c2fd78f51c2b4b3 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 09:50:59 -0700 Subject: [PATCH 08/19] fix: don't install pulse-utils --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ea7ff5d..209ee85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils pulseaudio pulseaudio-utils + apt-get install --yes --no-install-recommends alsa-utils pulseaudio WORKDIR /app From c013ee4907116f570c946681c5219ed195dd6dd2 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 10:14:23 -0700 Subject: [PATCH 09/19] fix: re-adding pulse-utils --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 209ee85..ea7ff5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils pulseaudio + apt-get install --yes --no-install-recommends alsa-utils pulseaudio pulseaudio-utils WORKDIR /app From 53a2df93b9621f68f4ffecb5bce6fd53c9c99215 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 10:24:22 -0700 Subject: [PATCH 10/19] fix: more pulse config --- Dockerfile | 4 ++++ docker/run | 2 ++ 2 files changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index ea7ff5d..a5f8bc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,10 @@ COPY wyoming_snd_external/ ./wyoming_snd_external/ RUN script/setup +RUN echo load-module module-alsa-sink device=hw:0,0 >> /etc/pulse/default.pa && \ + echo load-module module-alsa-source device=hw:0,0 >> /etc/pulse/default.pa && \ + echo load-module module-native-protocol-unix >> /etc/pulse/default.pa + COPY script/run ./script/ COPY docker/run ./ diff --git a/docker/run b/docker/run index 1d5b11a..aab3d31 100755 --- a/docker/run +++ b/docker/run @@ -20,6 +20,8 @@ if [ -z "${program}" ]; then program="aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi +pulseaudio --start + /app/script/run \ --uri tcp://0.0.0.0:10601 \ --program "${program}" \ From 84eeee2764ac00d1e93ebf683f23e956fe5bce0a Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 10:37:05 -0700 Subject: [PATCH 11/19] fix: more pulse tweaks --- Dockerfile | 3 ++- docker/run | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a5f8bc0..20597b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,8 @@ RUN script/setup RUN echo load-module module-alsa-sink device=hw:0,0 >> /etc/pulse/default.pa && \ echo load-module module-alsa-source device=hw:0,0 >> /etc/pulse/default.pa && \ - echo load-module module-native-protocol-unix >> /etc/pulse/default.pa + echo load-module module-native-protocol-unix >> /etc/pulse/default.pa && \ + echo load-module module-native-protocol-unix auth-anonymous=1 >> /etc/pulse/system.pa COPY script/run ./script/ COPY docker/run ./ diff --git a/docker/run b/docker/run index aab3d31..d89a406 100755 --- a/docker/run +++ b/docker/run @@ -20,7 +20,7 @@ if [ -z "${program}" ]; then program="aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi -pulseaudio --start +pulseaudio --system --disallow-exit --disallow-module-loading=1 --daemonize=yes -F /etc/pulse/system.pa /app/script/run \ --uri tcp://0.0.0.0:10601 \ From 306bae368aa3846603b40f985cab841d4cdd0fee Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 13:46:19 -0700 Subject: [PATCH 12/19] fix: more pulse tweaks. :| --- Dockerfile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20597b6..ec0b824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,10 @@ FROM python:3.11-slim-bookworm ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive +ENV PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native RUN apt-get update && \ - apt-get install --yes --no-install-recommends alsa-utils pulseaudio pulseaudio-utils + apt-get install --yes --no-install-recommends alsa-utils pulseaudio WORKDIR /app @@ -14,11 +15,6 @@ COPY wyoming_snd_external/ ./wyoming_snd_external/ RUN script/setup -RUN echo load-module module-alsa-sink device=hw:0,0 >> /etc/pulse/default.pa && \ - echo load-module module-alsa-source device=hw:0,0 >> /etc/pulse/default.pa && \ - echo load-module module-native-protocol-unix >> /etc/pulse/default.pa && \ - echo load-module module-native-protocol-unix auth-anonymous=1 >> /etc/pulse/system.pa - COPY script/run ./script/ COPY docker/run ./ From d0810c342e7da9b46197e96dd51e469bc90fc96f Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 14:02:06 -0700 Subject: [PATCH 13/19] test: trying with just bookworm --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ec0b824..479d76b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim-bookworm +FROM python:3.11-bookworm ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive From a3f852565bcd00825e70f08c03f4be8f40971afa Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 14:21:29 -0700 Subject: [PATCH 14/19] fix: cleanup --- Dockerfile | 1 - docker/run | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 479d76b..d807bc5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,6 @@ FROM python:3.11-bookworm ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive -ENV PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native RUN apt-get update && \ apt-get install --yes --no-install-recommends alsa-utils pulseaudio diff --git a/docker/run b/docker/run index d89a406..7e7483f 100755 --- a/docker/run +++ b/docker/run @@ -11,7 +11,7 @@ while [ -n "$1" ]; do shift done -if [ -z "${device}" ]; then +if [ -z "${device}" && -z "${program}" ]; then echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)." exit 1 fi From a97731333b2f310582bf41d0e1230d723185be6e Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Sun, 28 Apr 2024 15:23:38 -0700 Subject: [PATCH 15/19] feat: set ducking, not sure if we need to run pulseaudio as system --- Dockerfile | 1 + docker/run | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d807bc5..88c9e92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ COPY setup.py requirements.txt MANIFEST.in ./ COPY wyoming_snd_external/ ./wyoming_snd_external/ RUN script/setup +RUN echo load-module module-role-ducking trigger_roles=phone ducking_roles=music volume=0.0 >> /etc/pulse/default.pa COPY script/run ./script/ COPY docker/run ./ diff --git a/docker/run b/docker/run index 7e7483f..af1ba63 100755 --- a/docker/run +++ b/docker/run @@ -20,7 +20,7 @@ if [ -z "${program}" ]; then program="aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi -pulseaudio --system --disallow-exit --disallow-module-loading=1 --daemonize=yes -F /etc/pulse/system.pa +# pulseaudio --system --disallow-exit --disallow-module-loading=1 --daemonize=yes -F /etc/pulse/system.pa /app/script/run \ --uri tcp://0.0.0.0:10601 \ @@ -28,4 +28,3 @@ pulseaudio --system --disallow-exit --disallow-module-loading=1 --daemonize=yes --rate 22050 \ --width 2 \ --channels 1 "${args[@]}" - \ No newline at end of file From 0fe1b631a0ce7d52a1bcfd4ae893794742c8f5b9 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Thu, 19 Dec 2024 09:41:47 -0700 Subject: [PATCH 16/19] fix: syntax --- docker/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/run b/docker/run index af1ba63..4270f4d 100755 --- a/docker/run +++ b/docker/run @@ -11,7 +11,7 @@ while [ -n "$1" ]; do shift done -if [ -z "${device}" && -z "${program}" ]; then +if [[ -z "${device}" && -z "${program}" ]]; then echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)." exit 1 fi From 9f4554730c2b36b9ed22a370bddf356382661707 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Thu, 19 Dec 2024 10:04:27 -0700 Subject: [PATCH 17/19] fix: program device testing --- docker/run | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docker/run b/docker/run index 4270f4d..2059d9e 100755 --- a/docker/run +++ b/docker/run @@ -11,12 +11,11 @@ while [ -n "$1" ]; do shift done -if [[ -z "${device}" && -z "${program}" ]]; then - echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)." - exit 1 -fi - if [ -z "${program}" ]; then + if [ -z "${device}" ]; then + echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)." + exit 1 + fi program="aplay -D ${device} -r 22050 -c 1 -f S16_LE -t raw" fi From fcf462e5d0ecae2437ef70c27e61ad230dee2336 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Thu, 19 Dec 2024 10:18:53 -0700 Subject: [PATCH 18/19] debug: what is device and args --- docker/run | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker/run b/docker/run index 2059d9e..8c17cb9 100755 --- a/docker/run +++ b/docker/run @@ -11,6 +11,9 @@ while [ -n "$1" ]; do shift done +echo "args: ${args[@]}" +echo "device: ${device}" + if [ -z "${program}" ]; then if [ -z "${device}" ]; then echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)." From fe3f0e6502ff7730ed7fceed50d48b0171a79d51 Mon Sep 17 00:00:00 2001 From: Jessica Fritsch Date: Thu, 19 Dec 2024 11:49:59 -0700 Subject: [PATCH 19/19] test: removing debug statements --- docker/run | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker/run b/docker/run index 8c17cb9..2059d9e 100755 --- a/docker/run +++ b/docker/run @@ -11,9 +11,6 @@ while [ -n "$1" ]; do shift done -echo "args: ${args[@]}" -echo "device: ${device}" - if [ -z "${program}" ]; then if [ -z "${device}" ]; then echo "--device is required. Run 'aplay -L' for a list (prefer plughw: devices)."