Skip to content

Commit

Permalink
Make sure we have a 16kHZ WAV file (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Sep 24, 2024
1 parent b414f8a commit a518fdc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion examples/whisper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y gosu=1.14-1 --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r nobody \
&& useradd -r -g nobody scyllaridae \
&& chmod +x /app/docker-entrypoint.sh /app/cmd.sh
&& chmod +x /app/docker-entrypoint.sh /app/cmd.sh \
&& chown scyllaridae /app/models

ENTRYPOINT ["/app/docker-entrypoint.sh"]
25 changes: 19 additions & 6 deletions examples/whisper/cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,32 @@
set -eou pipefail

if [ ! -f /app/models/ggml-medium.en.bin ]; then
bash ./models/download-ggml-model.sh medium.en
bash ./models/download-ggml-model.sh medium.en > /dev/null 2>&1
fi

# take stdin and buffer it into a temp file
input_temp=$(mktemp /tmp/whisper-input-XXXXXX)

cat > "$input_temp"

# make sure we have a 16kHz WAV file
output_file="${input_temp}_16khz.wav"
ffmpeg -hide_banner -loglevel error -i "$input_temp" -ar 16000 -ac 1 "$output_file"

# generate the VTT file
/app/main \
-m /app/models/ggml-medium.en.bin \
--output-vtt \
-f "$input_temp" \
--output-file "$input_temp" > /dev/null 2>&1
-f "$output_file" \
--output-file "$input_temp" > /dev/null 2>&1 || true

cat "$input_temp.vtt"
# make sure a VTT file was created
STATUS=$(head -1 "$input_temp.vtt" | grep WEBVTT || echo "FAIL")
if [ "$STATUS" != "FAIL" ]; then
cat "$input_temp.vtt"
fi

rm "$input_temp" "$input_temp.vtt"
rm "$input_temp" "$input_temp.vtt" "$output_file"

if [ "$STATUS" == "FAIL" ]; then
exit 1
fi

0 comments on commit a518fdc

Please sign in to comment.