Skip to content

Commit

Permalink
Go back to two files for piper and updated piper gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
edurenye committed Mar 14, 2024
1 parent 1e1a1f5 commit 5b69166
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 23 deletions.
5 changes: 3 additions & 2 deletions docker-compose.gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ services:
service: wyoming-piper
<<: [ *gpu ]
build:
dockerfile: GPU.Dockerfile
args:
- BASE=nvidia/cuda:11.2.2-cudnn8-runtime-ubuntu20.04
- EXTRA_DEPENDENCIES=onnxruntime-gpu
- RUN_SCRIPT=run-gpu.sh
volumes:
- ./piper/__main__.py:/usr/local/lib/python3.10/dist-packages/wyoming_piper/__main__.py
- ./piper/process.py:/usr/local/lib/python3.10/dist-packages/wyoming_piper/process.py
- ./piper/__main__.py:/usr/local/lib/python3.8/dist-packages/wyoming_piper/__main__.py
- ./piper/process.py:/usr/local/lib/python3.8/dist-packages/wyoming_piper/process.py

wyoming-whisper:
extends:
Expand Down
12 changes: 3 additions & 9 deletions piper/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
ARG BASE=debian:bullseye-slim
FROM $BASE

ARG EXTRA_DEPENDENCIES
ARG RUN_SCRIPT=run-nongpu.sh
FROM debian:bullseye-slim
ARG TARGETARCH
ARG TARGETVARIANT

Expand All @@ -21,7 +17,6 @@ RUN \
&& pip3 install --no-cache-dir -U \
setuptools \
wheel \
$EXTRA_DEPENDENCIES \
&& pip3 install --no-cache-dir \
"wyoming-piper @ https://github.com/rhasspy/wyoming-piper/archive/refs/tags/v${WYOMING_PIPER_VERSION}.tar.gz" \
\
Expand All @@ -32,9 +27,8 @@ RUN \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /
COPY $RUN_SCRIPT ./
ENV RUN_SCRIPT_ENV=$RUN_SCRIPT
COPY run.sh ./

EXPOSE 10200

ENTRYPOINT ["bash", "/${RUN_SCRIPT_ENV}"]
ENTRYPOINT ["bash", "/run.sh"]
51 changes: 51 additions & 0 deletions piper/GPU.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG BASE=debian:bookworm-slim
FROM $BASE

ARG EXTRA_DEPENDENCIES
ARG RUN_SCRIPT='run-nongpu.sh'
ARG TARGETARCH
ARG TARGETVARIANT

# Install Piper
WORKDIR /usr/src
ARG WYOMING_PIPER_VERSION='1.5.0'
ARG BINARY_PIPER_VERSION='1.2.0'

RUN \
apt-get update \
&& apt-get install -y --no-install-recommends \
wget \
curl \
python3 \
python3-pip \
\
&& rm -rf /var/lib/apt/lists/*

RUN \
pip3 install --no-cache-dir -U \
setuptools \
wheel \
$EXTRA_DEPENDENCIES \
\
&& wget https://github.com/rhasspy/piper-phonemize/releases/download/v1.1.0/piper_phonemize-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl \
\
&& mv piper_phonemize-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl piper_phonemize-1.1.0-py3-none-any.whl \
\
&& pip3 install --no-cache-dir --force-reinstall --no-deps \
"piper-tts==${BINARY_PIPER_VERSION}" \
\
&& pip3 install --no-cache-dir --force-reinstall --no-deps \
piper_phonemize-1.1.0-py3-none-any.whl \
\
&& pip3 install --no-cache-dir \
"wyoming-piper @ https://github.com/rhasspy/wyoming-piper/archive/refs/tags/v${WYOMING_PIPER_VERSION}.tar.gz" \
\
&& rm -r piper_phonemize-1.1.0-py3-none-any.whl

WORKDIR /
COPY $RUN_SCRIPT ./
ENV RUN_SCRIPT_ENV="/${RUN_SCRIPT}"

EXPOSE 10200

ENTRYPOINT ["bash", "-c", "exec $RUN_SCRIPT_ENV \"${@}\"", "--"]
35 changes: 25 additions & 10 deletions piper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from pathlib import Path
from typing import Any, Dict, Set

from wyoming.info import Attribution, Info, TtsProgram, TtsVoice
from wyoming.info import Attribution, Info, TtsProgram, TtsVoice, TtsVoiceSpeaker
from wyoming.server import AsyncServer

from . import __version__
from .download import find_voice, get_voices
from .handler import PiperEventHandler
from .process import PiperProcessManager
Expand Down Expand Up @@ -72,13 +73,20 @@ async def main() -> None:
)
#
parser.add_argument("--debug", action="store_true", help="Log DEBUG messages")
parser.add_argument(
"--version",
action="version",
version=__version__,
help="Print version and exit",
)
args = parser.parse_args()

if not args.download_dir:
# Default to first data directory
args.download_dir = args.data_dir[0]

logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
_LOGGER.debug(args)

# Load voice info
voices_info = get_voices(args.download_dir, update_voices=args.update_voices)
Expand All @@ -98,20 +106,19 @@ async def main() -> None:
name="rhasspy", url="https://github.com/rhasspy/piper"
),
installed=True,
version=None,
languages=[
voice_info.get("language", {}).get(
"code",
voice_info.get("espeak", {}).get("voice", voice_name.split("_")[0]),
)
],
#
# Don't send speakers for now because it overflows StreamReader buffers
# speakers=[
# TtsVoiceSpeaker(name=speaker_name)
# for speaker_name in voice_info["speaker_id_map"]
# ]
# if voice_info.get("speaker_id_map")
# else None,
speakers=[
TtsVoiceSpeaker(name=speaker_name)
for speaker_name in voice_info["speaker_id_map"]
]
if voice_info.get("speaker_id_map")
else None,
)
for voice_name, voice_info in voices_info.items()
if not voice_info.get("_is_alias", False)
Expand Down Expand Up @@ -155,6 +162,7 @@ async def main() -> None:
TtsVoice(
name=custom_name,
description=description,
version=None,
attribution=Attribution(name="", url=""),
installed=True,
languages=[lang_code],
Expand All @@ -171,6 +179,7 @@ async def main() -> None:
),
installed=True,
voices=sorted(voices, key=lambda v: v.name),
version=__version__,
)
],
)
Expand Down Expand Up @@ -209,8 +218,14 @@ def get_description(voice_info: Dict[str, Any]):

# -----------------------------------------------------------------------------


def run():
asyncio.run(main())


if __name__ == "__main__":
try:
asyncio.run(main())
run()
except KeyboardInterrupt:
pass

2 changes: 1 addition & 1 deletion piper/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ async def get_process(self, voice_name: Optional[str] = None) -> PiperProcess:
piper_proc.last_used = time.monotonic_ns()

return piper_proc

2 changes: 1 addition & 1 deletion piper/run-gpu.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
python3 -m wyoming_piper \
--piper '/usr/share/piper/piper' \
--piper 'piper' \
--cuda \
--uri 'tcp://0.0.0.0:10200' \
--data-dir /data \
Expand Down
File renamed without changes.

0 comments on commit 5b69166

Please sign in to comment.