-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspeakers_stt.sh
61 lines (40 loc) · 1.57 KB
/
speakers_stt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env sh
# Transcribe what you're hearing, one keybinding away
# Put something like this in your sway/config:
# bindsym $mod+Shift+return exec alacritty -e bash /home/tekakutli/code/tortoise-scripts/speakers_stt_sway.sh
# use C-c on the spawned terminal to stop recording and then for whisper to transcribe it
# close the window to discard the recording, in my case Mod+Q
#THIS ASUMES YOU ALREADY HAVE WHISPER.CPP INSTALLED, SOMEWHERE
#https://github.com/ggerganov/whisper.cpp
##########################
CURRENTDIR=$(pwd)
mkdir -p $PATH_DESTINY
cd $PATH_DESTINY
METAFILE="./metadata.csv"
if [ ! -f $METAFILE ]
then
touch $METAFILE
fi
STT_COUNTER=$(wc -l < metadata.csv)
echo $STT_COUNTER
STT_COUNTER=$(($STT_COUNTER+$CSV_OFFSET))
LIVE_RECORD="./recording.wav"
WAV_RECORD="./recording_whisper.wav"
pw-record $LIVE_RECORD
ffmpeg -y -i "$LIVE_RECORD" -ar 16000 -ac 1 -c:a pcm_s16le $WAV_RECORD
# TINY IS FAST AND ENOUGH
if [[ "$LANG_FROM" == "en" ]]; then
$PATH_TO_WHISPER/main -m $PATH_TO_MODELS/$WHISPER_MODEL -l $LANG_FROM -f "$WAV_RECORD" -otxt
else
$PATH_TO_WHISPER/main -m $PATH_TO_MODELS/$WHISPER_MODEL -l $LANG_FROM -tr -f "$WAV_RECORD" -otxt
fi
mkdir -p "./wavs"
TTT_COUNTER="STT-"$STT_COUNTER
# cp "$LIVE_RECORD" "./wavs/$TTT_COUNTER.wav"
cp "$LIVE_RECORD" "$TTT_COUNTER.wav"
# we remove dots at the end of the sentence, and lowercase everything
echo "$TTT_COUNTER"".wav|"$(cat "$WAV_RECORD".txt | sed 's/\.$//') >> metadata.csv
sed -i "s/| /|/" metadata.csv
tr '[:upper:]' '[:lower:]' < metadata.csv > metadata2.csv
mv metadata2.csv metadata.csv
cd $CURRENTDIR