commit eb2825add592b2b50dac106970ea041ec6ae25c8
parent 74b7ac0dd261c74c0a7c727e039da71a8b74f1bb
Author: MTRNord <mtrnord1@gmail.com>
Date: Thu, 26 Jan 2023 22:59:16 +0100
Initial version of the matrix-live version
Diffstat:
5 files changed, 72 insertions(+), 125 deletions(-)
diff --git a/.editorconfig b/.editorconfig
@@ -0,0 +1,12 @@
+# EditorConfig is awesome: https://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+# Unix-style newlines with a newline ending every file
+[*]
+end_of_line = lf
+insert_final_newline = true
+charset = utf-8
+indent_style = space
+indent_size = 4
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,3 @@
+whisper.cpp/
+trancribe.cfg
+test/
diff --git a/README.md b/README.md
@@ -1,41 +1,21 @@
# transcribe
-transcription@home with and for fyyd.de
+A fork for matrix-live transcription@home by fyyd.de
-ACHTUNG! Das hier ist nicht ready to go, wenn auf Deinem Rechner/Server nicht schon vorab einige Dinge installiert und lauffähig sind.
-Das ist vor allem eine lauffähige Entwicklungsumgebung, weil die eigentliche Software, die das transkribieren übernimmt erst noch compiliert werden muss.
-Dafür kann ich keinen Support leisten, also solltest Du wissen, wo links+rechts ist, schließlich ist das ein Beta-Test :)
+This is not fully tested. You need a decent CPU. You also need these deps:
-Die Scripte sind auf macOS und Ubuntu getestet, sollten also soweit keine Probleme bereiten.
-Aktuell ist das alles noch ohne dauerhaftes Transkribieren angelegt. Du startest das Skript und es wird transkribiert, bis nichts mehr da ist. Dann endet die Software und startet erst wieder, wenn Du das Script noch einmal startest. Das wird sich aber noch ändern... irgendwann :)
+- ffmpeg
+- git
+- yt-dlp
-Darüber hinaus müssen bereits installiert sein:
+Next you need to run `./setup.sh` this will ask how many cores you want to use and it will test the setup.
+It also downloads and compiles the core of this: [whisper.cpp](https://github.com/ggerganov/whisper.cpp)
-ffmpeg
-curl
-git
-jq
+To start transcribing you can run `./transcribe.sh`.
+You can cancel it with ctrl+c at any time. or create a `.trancribe-stop` file in the parent folder to stop after the current transcription.
-Benötigt wird auch ein acccesstoken für fyyd (bzw die API). Das kannst Du Dir unter
+You find the vtt outputs in the `./whisper.cpp/output/` folder.
+The name contains the video id.
+Youtube allows you to upload these:
-https://fyyd.de/dev/app/
-
-abholen. Erstelle eine neue App (Name egal) und trage eine Beschreibung und die zwei URLs ein (auch hier: völlig egal).
-Dann drücke auf den roten Button "regenerate client creddntials" und kopiere das Token rechts unten ("user access token FOR YOU").
-
-Wechsel auf der Kommandozeile in den Ordner dieses repos und starte setup.sh. Entweder mit ./setup.sh oder /bin/bash setup.sh.
-
-Das Script checkt jetzt, ob ffmpeg, curl und git da sind und lädt dann das repo von [whisper.cpp](https://github.com/ggerganov/whisper.cpp) herunter und compiliert es.
-
-Danach wirst Du gefragt, wieviele Threads Du zur Verfügung stellen möchtest. Das ist Deine Entscheidung, aber die Transkription wird mit sehr niedriger
-Prio gestartet, sodass es die Performance Deines Rechners nicht sonderlich stören sollte. Du kannst das später in der fyyd.cfg auch wieder ändern.
-
-Danach wirst Du nach dem Token gefragt. Gib's ein und fertig.
-
-Dann startet ein Test. Es wird eine 5min kurze Audiodatei von mir transkribiert. Aus dem Test folgt dann eine Empfehlung, ob das überhaupt lohnt :)
-
-Wenn alles parat ist, kannst Du mal die transcribe.sh starten und schauen, was passiert...
-
-Unterbrechung mit CTRL+C ist jederzeit möglich, dann wird fyyd signalisiert, dass die Transkription abgebrochen wurde. Oder Du legst im Ordner eine
-Datei namens .fyyd-stop an, dann wird nach der Transkription gestoppt.
-
-Und jetzt: los! :)
+- https://support.google.com/youtube/answer/2734796?hl=en#zippy=%2Cupload-a-file
+- https://support.google.com/youtube/answer/2734698#zippy=%2Cadvanced-file-formats
diff --git a/setup.sh b/setup.sh
@@ -3,9 +3,9 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd $SCRIPT_DIR
-if [ -f ./fyyd.cfg ]
+if [ -f ./trancribe.cfg ]
then
- source "./fyyd.cfg"
+ source "./trancribe.cfg"
fi
@@ -25,15 +25,9 @@ then
exit
fi
-if ! command -v curl &> /dev/null
+if ! command -v yt-dlp &> /dev/null
then
- echo "Can't find curl. Please install."
- exit
-fi
-
-if ! command -v jq &> /dev/null
-then
- echo "Can't find jq. Please install."
+ echo "Can't find yt-dlp. Please install."
exit
fi
@@ -82,17 +76,6 @@ if [ "$THREADS" -ne 0 ]
THREAD_OPT=" -t $THREADS"
fi
-if [ -z "$ACCESSTOKEN" ]
- then
- echo -n "please provide the accesstoken for fyyd (return to set later in fyyd.cfg): "
- read token_input
- if [ ! -z "$token_input" ]
- then
- echo "READ"
- ACCESSTOKEN=$token_input
- fi
-fi
-
START=`date +%s`
echo -e "\nstarting test. this might take some minutes, please wait...\n"
@@ -129,8 +112,7 @@ fi
echo
cd ..
-rm -f fyyd.cfg
-echo "THREADS=$THREADS" >> ./fyyd.cfg
-echo "ATOKEN=$ACCESSTOKEN" >> ./fyyd.cfg
-echo "PIDFILE=~/.fyyd-transcribe.pid" >> ./fyyd.cfg
-echo "MODEL=medium" >> ./fyyd.cfg
+rm -f trancribe.cfg
+echo "THREADS=$THREADS" >> ./trancribe.cfg
+echo "PIDFILE=~/.trancribe-transcribe.pid" >> ./trancribe.cfg
+echo "MODEL=medium" >> ./trancribe.cfg
diff --git a/transcribe.sh b/transcribe.sh
@@ -2,9 +2,9 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-if [ -f ./fyyd.cfg ]
+if [ -f ./trancribe.cfg ]
then
- source "./fyyd.cfg"
+ source "./trancribe.cfg"
else
echo "no config found. please run setup.sh first."
exit 0
@@ -23,10 +23,9 @@ function stop {
function ctrl_c() {
echo "------------------------------"
- echo "STOPPING... notify fyyd"
+ echo "STOPPING..."
echo "bye bye"
echo "------------------------------"
- curl -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/error/$ID" -d "error=0"
rm -f $PIDFILE
exit
}
@@ -62,79 +61,53 @@ pid() {
pid
echo "Starting engines! Let's transcribe some episodes"
-cd whisper.cpp
+pushd whisper.cpp
+
+#------------------------------------------------------------------------------------
+# get data for one episode to transcribe from matrix youtube
+#------------------------------------------------------------------------------------
+
+echo "getting data from youtube"
+mkdir -p ./playlist
+pushd ./playlist
+yt-dlp "https://www.youtube.com/playlist?list=PLl5dnxRMP1hXBHqokHol6DTVIbnsf57Mr" -x --audio-format wav --audio-quality 0 -o "%(id)s.%(ext)s"
+popd
while :
do
-
- #------------------------------------------------------------------------------------
- # get data for one episode to transcribe from fyyd.de
- #------------------------------------------------------------------------------------
-
- echo "getting data from fyyd"
- DATA=`echo $(curl -s -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/next")`
-
- ID=`echo $DATA |jq -r .data.episode_id`
- URL=`echo $DATA |jq -r .data.enclosure_url`
- TOKEN=`echo $DATA |jq -r .data.token`
- LANG=`echo $DATA |jq -r .data.lang`
- DURATION=`echo $DATA |jq -r .data.duration`
- TITLE=`echo $DATA |jq -r .data.title`
-
+
# exit if nothing to do
- if [ -z $ID ]
+ if ! [ -n "$(find "./playlist/" -maxdepth 1 -type f 2>/dev/null)" ];
then
echo "nothing to transcribe. exit!"
exit 0;
fi
#------------------------------------------------------------------------------------
- # download episode
+ # transcribe wav to vtt
#------------------------------------------------------------------------------------
-
- echo "starting download of episode $ID, \"$TITLE\", duration $DURATION seconds"
- curl -s -L $URL > $TOKEN
- if [ $? -ne 0 ]
- then
- echo "error downloading"
- curl -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/error/$ID" -d "error=900"
- continue
-
- fi
-
-
- #------------------------------------------------------------------------------------
- # convert whatever was donwloaded to 16kHz WAV
- #------------------------------------------------------------------------------------
-
- echo "converting to wav"
+ files=(./playlist/*.wav)
+ next_file="${files[0]}"
+ echo "Working on \"${next_file}\" next"
+ FILENAME=$(basename ${next_file})
+ mv "${next_file}" ./${FILENAME}_orig
- ffmpeg -y -i $TOKEN -acodec pcm_s16le -ac 1 -ar 16000 $TOKEN.wav >/dev/null 2>/dev/null
-
- if [ $? -eq 1 ]
- then
- echo "error converting to wav"
- curl -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/error/$ID" -d "error=901"
- continue
- fi
+ ffmpeg -y -i ./${FILENAME}_orig -acodec pcm_s16le -ac 1 -ar 16000 ./${FILENAME} >/dev/null 2>/dev/null
+ rm ./${FILENAME}_orig
- rm $TOKEN
-
- #------------------------------------------------------------------------------------
- # transcribe wav to vtt
- #------------------------------------------------------------------------------------
+ DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 ./${FILENAME} 2>&1)
+ echo "start working on episode ${FILENAME}, duration $DURATION seconds"
START=`date +%s`
echo "starting whisper"
- nice -n 18 ./main -su -m models/ggml-$MODEL.bin -t $THREADS -l $LANG -ovtt $TOKEN.wav >/dev/null 2>/dev/null
+ nice -n 18 ./main -su -m models/ggml-$MODEL.bin -t $THREADS -l en -ovtt ./${FILENAME} >/dev/null 2>/dev/null
if [ $? -ne 0 ]
then
echo "error transcribing"
- curl -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/error/$ID" -d "error=902"
continue
fi
@@ -145,19 +118,14 @@ do
echo -n "Rate: "
printf "%.2f" $(echo "$DURATION/$TOOK" | bc -l)
echo "x"
-
-
- #------------------------------------------------------------------------------------
- # push transcript to fyyd
- #------------------------------------------------------------------------------------
-
- curl -H "Authorization: Bearer $ATOKEN" "https://api.fyyd.de/0.2/transcribe/set/$ID" --data-binary @$TOKEN.wav.vtt
- rm $TOKEN.wav
- rm $TOKEN.wav.vtt
+ rm ./${FILENAME}
+ #rm ./${FILENAME}.vtt
+ mkdir -p ./output
+ mv ./${FILENAME}.vtt ./output/${FILENAME}.vtt
- if [ -f ~/.fyyd-stop ]; then
- rm ~/.fyyd-stop
+ if [ -f ~/.trancribe-stop ]; then
+ rm ~/.trancribe-stop
echo "stopping hard"
exit
fi
@@ -167,4 +135,6 @@ do
done
+popd
+
rm $PIDFILE