mcspeak/Dockerfile
Ryan Malloy 70511916b9 Add media ducking: fade external audio during TTS playback
Duck all PulseAudio sink-inputs (Firefox, Spotify, etc.) before speech,
crossfade the entry tone over the fading media, then restore volumes
after the exit tone. Uses pactl subprocesses for reliable PipeWire
compatibility — pulsectl-asyncio's native protocol writes are silently
dropped by PipeWire's PA compat layer.

New module media_duck.py with MediaDucker class. Unduck is consolidated
into the consumer's finally block to guarantee restoration on all exit
paths (normal, error, cancel, shutdown).
2026-03-03 21:38:56 -07:00

44 lines
1.4 KiB
Docker

FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
# PipeWire client tools — pw-play connects to the host's PipeWire socket
# pulseaudio-utils provides pactl for media ducking (volume control via PulseAudio compat)
RUN apt-get update && apt-get install -y --no-install-recommends \
pipewire-bin \
pulseaudio-utils \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV UV_COMPILE_BYTECODE=1
# Create venv
RUN uv venv
# Install CPU-only torch first (saves ~3GB vs CUDA — SNAC runs on CPU anyway)
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install torch --index-url https://download.pytorch.org/whl/cpu
# Install project dependencies (torch already satisfied, won't redownload)
COPY pyproject.toml ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --no-deps -r pyproject.toml 2>/dev/null || true
# Copy source and install project
COPY src/ src/
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install .
# Non-root user matching host uid for PipeWire socket access
RUN useradd -u 1000 -m tts \
&& mkdir -p /home/tts/.cache/huggingface /data \
&& chown -R tts:tts /home/tts/.cache /data
USER tts
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8371
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s \
CMD python -c "import socket; s=socket.create_connection(('127.0.0.1',8371),2); s.close()" || exit 1
CMD ["tts-mcp"]