ggerganov commited on
Commit
2a7b373
·
unverified ·
1 Parent(s): 936213e

livestream.sh : simple tool to transcribe audio livestreams (#185)

Browse files
examples/livestream.sh ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Transcribe audio livestream by feeding ffmpeg output to whisper.cpp at regular intervals
4
+ # Idea by @semiformal-net
5
+ # ref: https://github.com/ggerganov/whisper.cpp/issues/185
6
+ #
7
+ # TODO:
8
+ # - Currently, there is a gap between sequential chunks, so some of the words are dropped. Need to figure out a
9
+ # way to produce a continuous stream of audio chunks.
10
+ #
11
+
12
+ url="http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/ak/bbc_world_service.m3u8"
13
+ step_ms=10000
14
+ model="base.en"
15
+
16
+ if [ -z "$1" ]; then
17
+ echo "Usage: $0 stream_url [step_ms] [model]"
18
+ echo ""
19
+ echo " Example:"
20
+ echo " $0 $url $step_ms $model"
21
+ echo ""
22
+ echo "No url specified, using default: $url"
23
+ else
24
+ url="$1"
25
+ fi
26
+
27
+ if [ -n "$2" ]; then
28
+ step_ms="$2"
29
+ fi
30
+
31
+ if [ -n "$3" ]; then
32
+ model="$3"
33
+ fi
34
+
35
+ # Whisper models
36
+ models=( "tiny.en" "tiny" "base.en" "base" "small.en" "small" "medium.en" "medium" "large" )
37
+
38
+ # list available models
39
+ function list_models {
40
+ printf "\n"
41
+ printf " Available models:"
42
+ for model in "${models[@]}"; do
43
+ printf " $model"
44
+ done
45
+ printf "\n\n"
46
+ }
47
+
48
+ if [[ ! " ${models[@]} " =~ " ${model} " ]]; then
49
+ printf "Invalid model: $model\n"
50
+ list_models
51
+
52
+ exit 1
53
+ fi
54
+
55
+ running=1
56
+
57
+ trap "running=0" SIGINT SIGTERM
58
+
59
+ printf "[+] Transcribing stream with model '$model', step_ms $step_ms (press Ctrl+C to stop):\n\n"
60
+
61
+ while [ $running -eq 1 ]; do
62
+ ffmpeg -y -re -probesize 32 -i $url -ar 16000 -ac 1 -c:a pcm_s16le -t ${step_ms}ms /tmp/whisper-live0.wav > /dev/null 2> /tmp/whisper-live.err
63
+ if [ $? -ne 0 ]; then
64
+ printf "Error: ffmpeg failed to capture audio stream\n"
65
+ exit 1
66
+ fi
67
+ mv /tmp/whisper-live0.wav /tmp/whisper-live.wav
68
+ ./main -t 8 -m ./models/ggml-small.en.bin -f /tmp/whisper-live.wav --no-timestamps -otxt 2> /tmp/whispererr | tail -n 1 &
69
+ done
examples/stream.wasm/emscripten.cpp CHANGED
@@ -51,7 +51,7 @@ void stream_main(size_t index) {
51
 
52
  wparams.language = "en";
53
 
54
- printf("stream: using %d threads\n", N_THREAD);
55
 
56
  std::vector<float> pcmf32;
57
 
 
51
 
52
  wparams.language = "en";
53
 
54
+ printf("stream: using %d threads\n", wparams.n_threads);
55
 
56
  std::vector<float> pcmf32;
57
 
examples/talk.wasm/emscripten.cpp CHANGED
@@ -68,7 +68,7 @@ void talk_main(size_t index) {
68
 
69
  g_gpt2 = gpt2_init("gpt-2.bin");
70
 
71
- printf("talk: using %d threads\n", N_THREAD);
72
 
73
  std::vector<float> pcmf32;
74
 
 
68
 
69
  g_gpt2 = gpt2_init("gpt-2.bin");
70
 
71
+ printf("talk: using %d threads\n", wparams.n_threads);
72
 
73
  std::vector<float> pcmf32;
74