Add local Whisper speech recognition

This commit is contained in:
Mikei386
2026-09-03 21:59:37 +02:00
parent f1fdca3efd
commit 42ec28c9f6
7 changed files with 189 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
FROM python:3.13.7-slim-bookworm
ARG WHISPER_CPP_VERSION=v1.9.1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential ca-certificates cmake curl ffmpeg git gosu \
&& git clone --branch "${WHISPER_CPP_VERSION}" --depth 1 \
https://github.com/ggml-org/whisper.cpp.git /opt/whisper.cpp \
&& cmake -S /opt/whisper.cpp -B /opt/whisper.cpp/build \
-DCMAKE_BUILD_TYPE=Release \
-DGGML_NATIVE=ON \
-DWHISPER_BUILD_TESTS=OFF \
-DWHISPER_BUILD_SERVER=OFF \
&& cmake --build /opt/whisper.cpp/build --config Release -j"$(nproc)" \
&& apt-get purge -y --auto-remove build-essential cmake git \
&& rm -rf /var/lib/apt/lists/* /root/.cache \
&& useradd --system --uid 10004 --home-dir /nonexistent --shell /usr/sbin/nologin whisper
WORKDIR /app
COPY router/stt_worker.py /app/stt_worker.py
COPY platform/docker/whisper/entrypoint.sh /usr/local/bin/mike-ai-whisper-entrypoint
RUN chmod 0755 /usr/local/bin/mike-ai-whisper-entrypoint
ENV WHISPER_HOST=0.0.0.0 \
WHISPER_PORT=8084 \
WHISPER_CLI=/opt/whisper.cpp/build/bin/whisper-cli \
WHISPER_MODEL=/models/ggml-large-v3-turbo.bin \
WHISPER_THREADS=8 \
WHISPER_LANGUAGE=de \
FFMPEG_BIN=/usr/bin/ffmpeg
VOLUME ["/models"]
EXPOSE 8084
ENTRYPOINT ["/usr/local/bin/mike-ai-whisper-entrypoint"]
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
set -eu
model=${WHISPER_MODEL:-/models/ggml-large-v3-turbo.bin}
model_url=${WHISPER_MODEL_URL:-https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo.bin}
model_dir=$(dirname "$model")
mkdir -p "$model_dir"
chown 10004:10004 "$model_dir"
if [ ! -s "$model" ]; then
partial="${model}.part"
echo "Downloading Whisper model to persistent storage"
# All writes below must use the volume owner. The container deliberately
# drops CAP_DAC_OVERRIDE, so even uid 0 cannot rename a file in the
# whisper-owned directory after capabilities have been removed.
if [ ! -s "$partial" ]; then
gosu whisper rm -f "$partial"
gosu whisper curl --fail --location --retry 5 --retry-delay 5 \
--output "$partial" "$model_url"
fi
gosu whisper mv "$partial" "$model"
fi
exec gosu whisper python /app/stt_worker.py