Skip to content

Commit

Permalink
feat(wyoming-piper): Enable CUDA, use ESPEAK_NG_DATA_DIR env
Browse files Browse the repository at this point in the history
  • Loading branch information
ms1design committed Apr 20, 2024
1 parent 5a4b38c commit 4ba5dc4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/smart-home/wyoming/piper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 11 additions & 4 deletions packages/smart-home/wyoming/piper/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions packages/smart-home/wyoming/piper/wyoming-piper_cuda_path.diff
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 4ba5dc4

Please sign in to comment.