keyehzy commited on
Commit
2444077
·
1 Parent(s): e508930

Allow for Twitch.tv live transcription

Browse files

We rely on streamlink library to give us a stream, then we proceed similarly to
the radio livestream example.

Files changed (1) hide show
  1. examples/twitch.sh +78 -0
examples/twitch.sh ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -eo pipefail
3
+
4
+ step=10
5
+ model=base.en
6
+ threads=1
7
+
8
+ help()
9
+ {
10
+ echo "Example program for captioning a livestream from twitch.tv."
11
+ echo
12
+ echo "Usage: ./twitch.sh -s [step] -m [model] -t [threads] [url]"
13
+ echo "options:"
14
+ echo "-s Step in seconds (default is $step)."
15
+ echo "-m Choose model, options are: 'tiny.en' 'tiny' 'base.en' 'base' 'small.en' 'small' 'medium.en' 'medium' 'large-v1' 'large' (default is '$model')."
16
+ echo "-t Number of threads to use."
17
+ echo "-h Print this help page."
18
+ echo
19
+ }
20
+
21
+ while getopts ":s:m:t:h" option; do
22
+ case $option in
23
+ s)
24
+ step=$OPTARG;;
25
+ m)
26
+ model=$OPTARG;;
27
+ t)
28
+ threads=$OPTARG;;
29
+ h)
30
+ help
31
+ exit;;
32
+ \?)
33
+ help
34
+ exit;;
35
+ esac
36
+ done
37
+
38
+ url=${@:$OPTIND:1}
39
+
40
+ if [ -z $url ]; then
41
+ help
42
+ exit
43
+ fi
44
+
45
+ echo "Piping from streamlink url=$url model=$model step=$step threads=$threads"
46
+ streamlink $url best -O 2>/dev/null | ffmpeg -loglevel quiet -i - -y -probesize 32 -y -ar 16000 -ac 1 -acodec pcm_s16le /tmp/whisper-live0.wav &
47
+
48
+ if [ $? -ne 0 ]; then
49
+ printf "error: ffmpeg failed\n"
50
+ exit 1
51
+ fi
52
+
53
+ echo "Buffering stream... (this should take $step seconds)"
54
+ sleep $(($step))
55
+
56
+ set +e
57
+
58
+ echo "Starting..."
59
+
60
+ i=0
61
+ while true
62
+ do
63
+ err=1
64
+ while [ $err -ne 0 ]; do
65
+ if [ $i -gt 0 ]; then
66
+ ffmpeg -loglevel quiet -v error -noaccurate_seek -i /tmp/whisper-live0.wav -y -ss $(($i*$step-1)).5 -t $step -c copy /tmp/whisper-live.wav 2> /tmp/whisper-live.err
67
+ else
68
+ ffmpeg -loglevel quiet -v error -noaccurate_seek -i /tmp/whisper-live0.wav -y -ss $(($i*$step)) -t $step -c copy /tmp/whisper-live.wav 2> /tmp/whisper-live.err
69
+ fi
70
+ err=$(cat /tmp/whisper-live.err | wc -l)
71
+ done
72
+
73
+ ./main -t $threads -m ./models/ggml-$model.bin -f /tmp/whisper-live.wav --no-timestamps -otxt 2> /tmp/whispererr | tail -n 1
74
+
75
+ sleep 1
76
+
77
+ ((i=i+1))
78
+ done