soraefir 52e9726ba7
All checks were successful
Nix Build / build-nixos (push) Successful in 4m53s
jq->jaq
2024-04-13 19:16:52 +02:00

61 lines
2.1 KiB
Nix

{ lib, config, pkgs, ... }: {
config = lib.mkIf (config.homecfg.make.gui) {
home.packages = with pkgs; [
custom.vosk.base
jaq
(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")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' 2>/dev/null
;;
"None-prog")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty, .partial // empty | select(length > 0)' 2>/dev/null
;;
*)
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jaq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' | python ~/.config/script/transcript-translate.py $TRANS
;;
esac
'';
};
}