From 4ba5dc4d20e8fb92f3059e16cc4cfd3648aa88be Mon Sep 17 00:00:00 2001 From: Mieszko Syty Date: Sat, 20 Apr 2024 15:28:42 +0200 Subject: [PATCH] feat(wyoming-piper): Enable CUDA, use ESPEAK_NG_DATA_DIR env --- packages/smart-home/wyoming/piper/Dockerfile | 1 + packages/smart-home/wyoming/piper/build.sh | 15 +++++-- .../piper/wyoming-piper_cuda_path.diff | 39 +++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 packages/smart-home/wyoming/piper/wyoming-piper_cuda_path.diff diff --git a/packages/smart-home/wyoming/piper/Dockerfile b/packages/smart-home/wyoming/piper/Dockerfile index e577333ad..0208ca95e 100644 --- a/packages/smart-home/wyoming/piper/Dockerfile +++ b/packages/smart-home/wyoming/piper/Dockerfile @@ -20,6 +20,7 @@ ENV PIP_BREAK_SYSTEM_PACKAGES=1 \ PIPER_DEBUG="true" COPY build.sh /tmp/wyoming/build_wyoming-piper.sh +COPY *.diff /tmp/wyoming/ WORKDIR /usr/src diff --git a/packages/smart-home/wyoming/piper/build.sh b/packages/smart-home/wyoming/piper/build.sh index 82811564a..485171925 100755 --- a/packages/smart-home/wyoming/piper/build.sh +++ b/packages/smart-home/wyoming/piper/build.sh @@ -17,10 +17,9 @@ pip3 install --no-cache-dir -U \ # Clone wyoming-piper layer git clone https://github.com/rhasspy/wyoming-piper /tmp/wyoming-piper -# TODO: Enable CUDA -# wget https://patch-diff.githubusercontent.com/raw/rhasspy/wyoming-piper/pull/5.diff -O /tmp/cuda_patch.diff -# git -C /tmp/wyoming-piper apply /tmp/cuda_patch.diff -# git -C /tmp/wyoming-piper status +# Enable CUDA +git -C /tmp/wyoming-piper apply /tmp/wyoming/wyoming-piper_cuda_path.diff +git -C /tmp/wyoming-piper status pip3 install --no-cache-dir --verbose -r /tmp/wyoming-piper/requirements.txt pip3 wheel --wheel-dir=/opt/ --no-deps --verbose /tmp/wyoming-piper pip3 install --no-cache-dir --verbose /opt/wyoming_piper*.whl @@ -41,8 +40,16 @@ sed -i \ -e "s#--noise-w.*#--noise-w \"$PIPER_NOISE_W\" \\\\#g" \ -e "s#--speaker.*#--speaker \"$PIPER_SPEAKER\" \\\\#g" \ -e "s#--voice.*#--voice \"$PIPER_VOICE\" \\\\#g" \ + -e "s#--download-dir /data#--download-dir $PIPER_CACHE#g" \ -e "s#--max-piper-procs.*#--max-piper-procs \"$PIPER_MAX_PROC\" \\\\#g" \ /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run +# Add download dir (PIPER_CACHE) to data dirs array +sed -i "15a\ --data-dir ${PIPER_CACHE} \\\\" /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run +# Enable CUDA +sed -i '15a\ --cuda \\' /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run +# Set path to espeak-ng data directory +sed -i "15a\ --espeak-data-dir ${ESPEAK_NG_DATA_DIR} \\\\" /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run +cat /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/piper/run # Fix: Disable native Discovery handled by HA Supervisor sed -i '$d' /tmp/addons/piper/rootfs/etc/s6-overlay/s6-rc.d/discovery/run diff --git a/packages/smart-home/wyoming/piper/wyoming-piper_cuda_path.diff b/packages/smart-home/wyoming/piper/wyoming-piper_cuda_path.diff new file mode 100644 index 000000000..8e82e1f57 --- /dev/null +++ b/packages/smart-home/wyoming/piper/wyoming-piper_cuda_path.diff @@ -0,0 +1,39 @@ +diff --git a/wyoming_piper/__main__.py b/wyoming_piper/__main__.py +index 08b20f1..f88312b 100755 +--- a/wyoming_piper/__main__.py ++++ b/wyoming_piper/__main__.py +@@ -77,6 +77,15 @@ async def main() -> None: + version=__version__, + help="Print version and exit", + ) ++ parser.add_argument( ++ "--cuda", ++ action="store_true", ++ help="Use GPU" ++ ) ++ parser.add_argument( ++ "--espeak-data-dir", ++ help="Path to espeak-ng data directory" ++ ) + args = parser.parse_args() + + if not args.download_dir: +diff --git a/wyoming_piper/process.py b/wyoming_piper/process.py +index a7e90a7..98b0712 100644 +--- a/wyoming_piper/process.py ++++ b/wyoming_piper/process.py +@@ -148,6 +148,14 @@ class PiperProcessManager: + if self.args.noise_w: + piper_args.extend(["--noise-w", str(self.args.noise_w)]) + ++ if self.args.espeak_data_dir: ++ piper_args.extend(["--espeak_data", str(self.args.espeak_data_dir)]) ++ ++ if self.args.cuda: ++ piper_args.extend(["--debug"]) ++ piper_args.extend(["--cuda"]) ++ piper_args.extend(["--use-cuda"]) ++ + _LOGGER.debug( + "Starting piper process: %s args=%s", self.args.piper, piper_args + )