From 36814b5a7aba475c3d18c0ae463aafcd75cf6615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Fra=C3=9F?= Date: Wed, 21 May 2025 21:56:49 +0000 Subject: [PATCH] =?UTF-8?q?[mod]=20l=C3=A4uft?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + notizen.md | 8 ++++++ readme.md | 17 +++++++++++-- source/helpers.php | 28 ++++++++++++++++++++ source/index.html.php | 2 +- source/logic.php | 59 ++++++++++++++++++++++++++++++++++++++++--- tools/build | 3 ++- tools/clear | 3 +++ tools/update-piper | 20 +++++++++++++++ 9 files changed, 134 insertions(+), 7 deletions(-) create mode 100755 tools/clear create mode 100755 tools/update-piper diff --git a/.gitignore b/.gitignore index ba98a06..9fd9837 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.geany /build/ +/lib/piper/ diff --git a/notizen.md b/notizen.md index 695030d..fe52be4 100644 --- a/notizen.md +++ b/notizen.md @@ -1,3 +1,7 @@ +# Notizen + +## Ziele + - soll eine kleine Web-Anwendung werden - einzige Domäne im Modell ist die der Dokumente - Eigenschaften von Dokumenten: @@ -9,3 +13,7 @@ - für jedes bestehende Dokument soll es Funktionen zum Aufbereiten und Herunderladen geben in den Formaten pdf und ogg - für die Erstellung der Audio-Variante soll nach Möglichkeit [Piper](https://github.com/rhasspy/piper) verwendet werden + +## Zu erledigen + +- asynchrones Erstellen der Audio-Dateien (solange nicht fertig, eine Markierung in der Liste anzeigen) diff --git a/readme.md b/readme.md index 8d1bf12..a40a398 100644 --- a/readme.md +++ b/readme.md @@ -5,6 +5,18 @@ proof-of-concept für Partei-Arbeits-Dokumenten-Verwaltung, welche hörbare Versionen der Dokumente bereitstellt +## Einrichtung + +### Voraussetzungen + +- curl + + +### Anweisungen + +- `tools/update-piper` ausführen + + ## Erstellung ### Voraussetzungen @@ -14,7 +26,7 @@ proof-of-concept für Partei-Arbeits-Dokumenten-Verwaltung, welche hörbare Vers ### Anweisungen -- `tools/build` ausführen +- nach Einrichtung `tools/build` ausführen ## Ausführung @@ -22,7 +34,8 @@ proof-of-concept für Partei-Arbeits-Dokumenten-Verwaltung, welche hörbare Vers ### Voraussetzungen - PHP auf Kommandozeile (Debian-Paket-Name: `php-cli`) -- Browser +- ffmpeg (Debian-Paket-Name: `ffmpeg`) +- beliebigen Browser ### Anweisungen diff --git a/source/helpers.php b/source/helpers.php index 546ac3b..87ab5c2 100644 --- a/source/helpers.php +++ b/source/helpers.php @@ -237,4 +237,32 @@ function navigate(string $target) : void } +/** + */ +function generate_audio(string $name, string $input) : string +{ + $path_wav = string_coin( + '/tmp/{{name}}.wav', + [ + 'name' => $name, + ] + ); + $path_ogg = string_coin( + '{{name}}.ogg', + [ + 'name' => $name, + ] + ); + $command = string_coin( + 'echo "{{input}}" | piper/piper --model piper/voice.onnx --output_file {{path_wav}} ; ffmpeg -y -i {{path_wav}} {{path_ogg}}', + [ + 'input' => $input, + 'path_wav' => $path_wav, + 'path_ogg' => $path_ogg, + ] + ); + exec($command); + return $path_ogg; +} + ?> diff --git a/source/index.html.php b/source/index.html.php index f74147a..751d3f0 100644 --- a/source/index.html.php +++ b/source/index.html.php @@ -60,7 +60,7 @@ function nav(string $mode, array $args) : void ] ), 'link_read' => '#not_implemented', - 'link_hear' => '#not_implemented', + 'link_hear' => \rosavox\logic\docs_audio_path($entry['id']), 'text' => $entry['value']['title'], ] ), diff --git a/source/logic.php b/source/logic.php index 15b0056..b9390dc 100644 --- a/source/logic.php +++ b/source/logic.php @@ -13,6 +13,55 @@ class docs_state } +/** + */ +function docs_audio_name(int $id) : string +{ + return \sprintf('%04u', $id); +} + + +/** + */ +function docs_audio_path(int $id) : string +{ + return \sprintf('%s.ogg', docs_audio_name($id)); +} + + +/** + */ +function docs_generate_audio(int $id, $doc) : void +{ + $pause = ' . '; + \rosavox\helpers\generate_audio( + docs_audio_name($id), + \rosavox\helpers\string_coin( + "{{title}}{{pause}}Autoren: {{authors}}{{pause}}Formulierung: {{content}}{{macro_reasoning}}", + [ + 'pause' => $pause, + 'title' => $doc['title'], + 'authors' => implode(', ', $doc['authors']), + 'content' => $doc['content'], + 'macro_reasoning' => ( + ($doc['reasoning'] === null) + ? + '' + : + \rosavox\helpers\string_coin( + "{{pause}}Begründung: {{reasoning}}", + [ + 'pause' => $pause, + 'reasoning' => $doc['reasoning'], + ] + ) + ) + ] + ) + ); +} + + /** */ function docs_list() : array @@ -30,10 +79,13 @@ function docs_read(int $id) : array /** + * @todo async generating */ function docs_create(array $doc) : int { - return docs_state::$crud->create($doc); + $id = docs_state::$crud->create($doc); + docs_generate_audio($id, $doc); + return $id; } @@ -42,6 +94,7 @@ function docs_create(array $doc) : int function docs_update(int $id, array $doc) : void { docs_state::$crud->update($id, $doc); + docs_generate_audio($id, $doc); } @@ -64,8 +117,8 @@ function docs_add_examples() : void 'Björn Biernot', 'Doreen Dauerdurst', ], - 'content' => 'Wir haben Durst!', - 'reasoning' => null, + 'content' => 'Der Landesverband möge beschließen, dass zu Beginn eines jeden Parteitags für jeden Deligierten mindestens zwei Flaschen Bier auf den zugehörigen Platz zu stellen sind.', + 'reasoning' => 'Wir haben Durst!', ] ); } diff --git a/tools/build b/tools/build index 24151c9..7e29a0b 100755 --- a/tools/build +++ b/tools/build @@ -9,5 +9,6 @@ dir_source="source" ## exec mkdir -p ${dir_build} +cp -r -u lib/* ${dir_build}/ cp -r -u -v ${dir_source}/* ${dir_build}/ -cd ${dir_build} && ln -f -s index.html.php index.php +cd ${dir_build} && ln -f -s index.html.php index.php ; cd - diff --git a/tools/clear b/tools/clear new file mode 100755 index 0000000..984fcde --- /dev/null +++ b/tools/clear @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +rm -r -f build/* diff --git a/tools/update-piper b/tools/update-piper new file mode 100755 index 0000000..999763b --- /dev/null +++ b/tools/update-piper @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +## const + +dir_lib=lib +voice="v1.0.0/de/de_DE/eva_k/x_low/de_DE-eva_k-x_low.onnx" + + +## exec + +mkdir -p ${dir_lib} +cd ${dir_lib} +curl -s -L https://github.com/rhasspy/piper/releases/download/v1.2.0/piper_amd64.tar.gz | tar -x -z +cd - + +for voice in ${voices} +do + curl -s -L https://huggingface.co/rhasspy/piper-voices/resolve/${voice}?download=true > ${dir_lib}/piper/voice.onnx + curl -s -L https://huggingface.co/rhasspy/piper-voices/resolve/${voice}.json?download=true.json > ${dir_lib}/piper/voice.onnx.json +done