Skip to content

Instantly share code, notes, and snippets.

@geimist
Forked from reitzig/Dockerfile
Created March 31, 2023 12:58
Show Gist options
  • Save geimist/1bd786343482e02160ea3c8eb5fdeeb1 to your computer and use it in GitHub Desktop.
Save geimist/1bd786343482e02160ea3c8eb5fdeeb1 to your computer and use it in GitHub Desktop.
Run whisper.cpp as Container
FROM debian:11 AS build
RUN apt-get update \
&& apt-get install -y libsdl2-dev alsa-utils g++ make wget
RUN mkdir /whisper && \
wget -q https://github.com/masterful/whisper.cpp/tarball/master -O - | \
tar -xz -C /whisper --strip-components 1
WORKDIR /whisper
ARG model
RUN bash ./models/download-ggml-model.sh "${model}"
RUN make main stream
FROM debian:11 AS whisper
RUN apt-get update \
&& apt-get install -y libsdl2-dev alsa-utils \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /root
ARG model
RUN mkdir /root/models
COPY --from=build "/whisper/models/ggml-${model}.bin" "/root/models/ggml-${model}.bin"
COPY --from=build /whisper/main /usr/local/bin/whisper
COPY --from=build /whisper/stream /usr/local/bin/stream
#!/usr/bin/env bash
set -eu
MODEL="base"
LANG="de"
audio_file="${1}"
file_name="$(basename "${audio_file}")"
wav_file="${audio_file%.*}.wav"
media_dir="$(realpath "$(dirname "${audio_file}")")"
script_dir="$(realpath "$(dirname "${0}")")"
docker build -t whisper-${MODEL} --build-arg model=${MODEL} "${script_dir}"
ffmpeg -i "${audio_file}" -ar 16000 "${wav_file}"
docker run --rm -it \
-v "${media_dir}":/media \
whisper \
whisper \
--model /root/models/ggml-${MODEL}.bin \
--language ${LANG} \
-t 2 \
--output-txt -nt \
-f "/media/$(basename "${wav_file}")"
@geimist
Copy link
Author

geimist commented Mar 31, 2023

I would not call docker build on every run, but check for it beforehand.

if [ ! $(docker images | grep -q "whisper-${MODEL}" ) ]; then
    docker build -t whisper-${MODEL} --build-arg model=${MODEL} "${script_dir}"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment