[mod] läuft

This commit is contained in:
roydfalk 2025-05-21 21:56:49 +00:00
parent 990de81c42
commit 36814b5a7a
9 changed files with 134 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/.geany
/build/
/lib/piper/

View file

@ -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)

View file

@ -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

View file

@ -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;
}
?>

View file

@ -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'],
]
),

View file

@ -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!',
]
);
}

View file

@ -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 -

3
tools/clear Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
rm -r -f build/*

20
tools/update-piper Executable file
View file

@ -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