diff --git a/Dockerfile b/Dockerfile index 113a7bb..8327e76 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,48 +1,14 @@ ########################################## FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 AS build -ARG PIPER_BRANCH="2023.11.14-2" +ARG TARGETARCH=linux_x86_64 +ARG WYOMING_PIPER_VERSION="1.5.2" +ARG PIPER_PHONEMIZE_VERSION='1.0.0' +ARG ONNXRUNTIME_VERSION="1.20.1" ENV LANG C.UTF-8 ENV DEBIAN_FRONTEND=noninteractive -RUN \ - apt-get update &&\ - apt-get install -y --no-install-recommends \ - wget \ - curl \ - vim \ - git \ - build-essential \ - cmake \ - ca-certificates \ - curl \ - pkg-config - -WORKDIR /build - -RUN \ - git clone -b "${PIPER_BRANCH}" https://github.com/rhasspy/piper.git /build - -RUN cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install -RUN cmake --build build --config Release -RUN cmake --install build - -WORKDIR /dist -RUN mkdir -p piper && \ - cp -dR /build/install/* ./piper/ - -RUN /dist/piper/piper --help - -########################################## -FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 AS dist - -ARG TARGETARCH=linux_x86_64 -ARG WYOMING_PIPER_VERSION="1.5.0" - -ENV DEBIAN_FRONTEND=noninteractive -ENV PYTHONUNBUFFERED=1 - RUN \ apt-get update && apt-get upgrade -y &&\ apt-get install -y --no-install-recommends \ @@ -54,42 +20,76 @@ RUN \ python3 \ python3-dev \ python3-venv \ - python3-pip + python3-pip \ + build-essential \ + cmake \ + ca-certificates \ + pkg-config RUN \ - mkdir -p /data /app/piper &&\ - ln -s /app/piper /usr/share/espeak-ng-data &&\ - python3 -m venv /app + cd /tmp && wget -q https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz &&\ + tar xzvf onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz &&\ + cp -rfv /tmp/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}/lib/* /app/lib + +WORKDIR /build + +RUN \ + git clone https://github.com/rhasspy/piper.git /build + +RUN ONNXRUNTIME_DIR=/app/lib cmake -Bbuild -DCMAKE_INSTALL_PREFIX=install +RUN ONNXRUNTIME_DIR=/app/lib cmake --build build --config Release +RUN ONNXRUNTIME_DIR=/app/lib cmake --install build + +WORKDIR /app +RUN mkdir -p /data /app/piper &&\ + python3 -m venv /app &&\ + cp -rfv /build/install/* /app/piper/ &&\ + chmod 755 /app/piper/piper /app/piper/espeak-ng + +RUN /app/piper/piper --help -COPY --from=build /dist/piper/* /app/piper/ COPY requirements.txt /app/ +COPY run.sh /app/ +COPY patches/* /tmp/ + RUN \ . /app/bin/activate && \ - /app/bin/python3 -m pip install --no-cache-dir --no-deps \ + /app/bin/python3 -m pip install --no-cache-dir \ -r /app/requirements.txt \ &&\ \ /app/bin/python3 -m pip install --no-cache-dir \ - "wyoming-piper @ https://github.com/rhasspy/wyoming-piper/archive/refs/tags/v${WYOMING_PIPER_VERSION}.tar.gz" \ - &&\ - \ - PIPER_VERSION=$(wget "https://api.github.com/repos/rhasspy/piper/releases/latest" -O -|awk '/tag_name/{print $4;exit}' FS='[""]') && \ - \ - wget "https://github.com/rhasspy/piper/releases/download/${PIPER_VERSION}/piper_${TARGETARCH}.tar.gz" -O -|tar -zxvf - -C /usr/share - -# Patch to enable CUDA arguments for piper -COPY patches/* /tmp/ + "wyoming-piper @ https://github.com/rhasspy/wyoming-piper/archive/refs/tags/v${WYOMING_PIPER_VERSION}.tar.gz" + RUN \ cd /app/lib/python3.10/site-packages/wyoming_piper/; \ for file in /tmp/wyoming_piper*.diff;do patch -p0 --forward < $file;done; \ - cp /app/lib/python3.10/site-packages/onnxruntime/capi/libonnxruntime* /app/lib/ &&\ - mv /app/piper/lib*.so* /app/lib/ + cp /build/install/lib*.so* /app/lib/ -# Clean up -RUN rm -rf /root/.cache/pip /var/lib/apt/lists/* /tmp/* +########################################## +FROM nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04 AS dist + +ENV PYTHONUNBUFFERED=1 + +RUN \ + mkdir -p /data /app &&\ + apt-get update && apt-get upgrade -y &&\ + apt-get install -y --no-install-recommends \ + wget \ + curl \ + vim \ + python3 \ + python3-dev \ + python3-venv \ + python3-pip \ + ca-certificates + +RUN rm -rf /root/.cache/pip /var/lib/apt/lists/* WORKDIR /app -COPY run.sh /app/ +COPY --from=build /app . + +RUN ln -s /app/piper/espeak-ng-data /usr/share/espeak-ng-data EXPOSE 10200 diff --git a/README.md b/README.md index 507c299..7a62898 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,8 @@ docker pull ghcr.io/slackr31337/wyoming-piper-gpu:latest Use environment variable to set piper voice PIPER_VOICE="en_US-lessac-medium" - +PIPER_LENGTH="1.0" +PIPER_NOISE="0.667" +PIPER_NOISEW="0.333" +PIPER_SPEAKER="0" +PIPER_SILENCE="1.2" diff --git a/requirements.txt b/requirements.txt index 857ed19..1035eaa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ piper-tts>=1.2.0 -onnxruntime==1.14.0 -onnxruntime-gpu==1.14.0 +onnxruntime-gpu==1.20.1 diff --git a/run.sh b/run.sh index db6001f..605f9bc 100644 --- a/run.sh +++ b/run.sh @@ -1,10 +1,9 @@ #!/usr/bin/env bash -export LD_LIBRARY_PATH=/app/lib/:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=/app/lib/:/usr/local/cuda-12.3/targets/x86_64-linux/lib:$LD_LIBRARY_PATH # Run wyoming-piper server source /app/bin/activate - /app/bin/python3 -m wyoming_piper \ --piper '/app/piper/piper' \ --uri 'tcp://0.0.0.0:10200' \ @@ -12,6 +11,7 @@ source /app/bin/activate --noise-scale "${PIPER_NOISE:-0.667}" \ --noise-w "${PIPER_NOISEW:-0.333}" \ --speaker "${PIPER_SPEAKER:-0}" \ + --sentence-silence "${PIPER_SILENCE:-1.2}" \ --voice "${PIPER_VOICE:-en_US-amy-medium}" \ --max-piper-procs "${PIPER_PROCS:-1}" \ --data-dir /data \