nixconfig/home/gui/vosk/default.nix
2023-10-12 16:16:29 +02:00

69 lines
1.8 KiB
Nix

{
pkgs,
lib,
inputs,
...
}: {
home.packages = with pkgs; [
custom.vosk
custom.voskcli
custom.vosk-lang.en-us
custom.vosk-lang.ja
custom.vosk-lang.de
custom.vosk-lang.ru
jq
(python3.withPackages(ps: with ps; [ translatepy ]))
];
xdg.configFile."script/transcript-translate.py".text = ''
#!/bin/python
import sys;
from translatepy.translators.google import GoogleTranslate;
if len(sys.argv) != 2:
print("No language provided.")
exit
translator = GoogleTranslate()
while True:
for line in sys.stdin:
sys.stdout.write(translator.translate(line,sys.argv[1]).result+"\n")
'';
xdg.configFile."script/transcript.sh".text = ''
#!/bin/sh
MODELS=(
"English:${pkgs.custom.vosk-lang.en-us}/usr/share/vosk-models/en-us"
"German:${pkgs.custom.vosk-lang.de}/usr/share/vosk-models/de"
"Russian:${pkgs.custom.vosk-lang.ru}/usr/share/vosk-models/ru"
"Japanese:${pkgs.custom.vosk-lang.ja}/usr/share/vosk-models/ja"
)
MODEL_OPTS=""
for pair in "''${MODELS[@]}"; do
MODEL_OPTS+="$pair\n"
done
MODEL_OPT=$(echo -e "$MODEL_OPTS" | wofi --dmenu -p "Choose model:")
MODEL=$(echo "$MODEL_OPT" | awk -F ':' '{print $2}')
TRANSS="None\nNone-prog\nEnglish\nGerman\nRussian\nJapanese"
TRANS=$(echo -e "$TRANSS" | wofi --dmenu -p "Choose translation:")
export VOSK_MODEL=$MODEL
case $TRANS in
"None")
voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' 2>/dev/null
;;
"None-prog")
voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty, .partial // empty | select(length > 0)' 2>/dev/null
;;
*)
voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' | python ~/.config/script/transcript-translate.py $TRANS
;;
esac
'';
}