diff --git a/docker-compose.gpu.yml b/docker-compose.gpu.yml index 800cbf6..1aa0b75 100644 --- a/docker-compose.gpu.yml +++ b/docker-compose.gpu.yml @@ -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: diff --git a/piper/Dockerfile b/piper/Dockerfile index c3004f4..c795edc 100644 --- a/piper/Dockerfile +++ b/piper/Dockerfile @@ -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 @@ -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" \ \ @@ -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"] diff --git a/piper/GPU.Dockerfile b/piper/GPU.Dockerfile new file mode 100644 index 0000000..c3b6c32 --- /dev/null +++ b/piper/GPU.Dockerfile @@ -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 \"${@}\"", "--"] diff --git a/piper/__main__.py b/piper/__main__.py index ea81455..548d7d0 100644 --- a/piper/__main__.py +++ b/piper/__main__.py @@ -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 @@ -72,6 +73,12 @@ 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: @@ -79,6 +86,7 @@ async def main() -> None: 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) @@ -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) @@ -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], @@ -171,6 +179,7 @@ async def main() -> None: ), installed=True, voices=sorted(voices, key=lambda v: v.name), + version=__version__, ) ], ) @@ -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 + diff --git a/piper/process.py b/piper/process.py index 63d7047..e479c25 100644 --- a/piper/process.py +++ b/piper/process.py @@ -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 - + diff --git a/piper/run-gpu.sh b/piper/run-gpu.sh index bcdfac8..cef02f0 100755 --- a/piper/run-gpu.sh +++ b/piper/run-gpu.sh @@ -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 \ diff --git a/piper/run-nongpu.sh b/piper/run.sh similarity index 100% rename from piper/run-nongpu.sh rename to piper/run.sh