Last active
September 14, 2024 13:07
-
-
Save reitzig/6582edd485a5d0a8b68600dab3b0861b to your computer and use it in GitHub Desktop.
Run whisper.cpp as Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ggerganov/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}")" |
Thanks to build caches, there's basically no overhead in running it every time, but you never have to rebuild yourself when changing things. YMMV, though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice 👍
I would not call
docker build
on every run, but check for it beforehand.