Spaces:
Sleeping
Sleeping
examples : add simple script for generating Karaoke video
Browse files- examples/generate-karaoke.sh +49 -0
examples/generate-karaoke.sh
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
executable="./main"
|
| 4 |
+
model="base.en"
|
| 5 |
+
model_path="models/ggml-$model.bin"
|
| 6 |
+
|
| 7 |
+
# require sox and ffmpeg to be installed
|
| 8 |
+
if ! command -v sox &> /dev/null
|
| 9 |
+
then
|
| 10 |
+
echo "sox could not be found"
|
| 11 |
+
exit 1
|
| 12 |
+
fi
|
| 13 |
+
|
| 14 |
+
if ! command -v ffmpeg &> /dev/null
|
| 15 |
+
then
|
| 16 |
+
echo "ffmpeg could not be found"
|
| 17 |
+
exit 2
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
if [ ! -f "$executable" ]; then
|
| 21 |
+
echo "'$executable' does not exist. Please build it first."
|
| 22 |
+
exit 3
|
| 23 |
+
fi
|
| 24 |
+
|
| 25 |
+
if [ ! -f "$model_path" ]; then
|
| 26 |
+
echo "'$model_path' does not exist. Please download it first."
|
| 27 |
+
exit 4
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
# record some raw audio
|
| 31 |
+
sox -d rec.wav
|
| 32 |
+
|
| 33 |
+
# resample to 16kHz
|
| 34 |
+
ffmpeg -y -i ./rec.wav -ar 16000 -ac 1 -c:a pcm_s16le ./rec16.wav > /dev/null 2>&1
|
| 35 |
+
|
| 36 |
+
# run Whisper
|
| 37 |
+
echo "Processing ..."
|
| 38 |
+
./main -m models/ggml-base.en.bin rec16.wav -owts > /dev/null 2>&1
|
| 39 |
+
|
| 40 |
+
# generate Karaoke video
|
| 41 |
+
echo "Generating video ..."
|
| 42 |
+
source rec16.wav.wts > /dev/null 2>&1
|
| 43 |
+
|
| 44 |
+
# play the video
|
| 45 |
+
echo "Playing ./rec16.wav.mp4 ..."
|
| 46 |
+
ffplay -loglevel 0 -autoexit ./rec16.wav.mp4
|
| 47 |
+
|
| 48 |
+
echo "Done"
|
| 49 |
+
exit 0
|