[m]Pkgs: Fix Vosk

This commit is contained in:
soraefir 2023-11-26 00:39:26 +01:00
parent 4c2b988996
commit f693a59f6c
4 changed files with 70 additions and 76 deletions

View File

@ -1,65 +1,60 @@
{ lib, config, pkgs, ... }: {
config = lib.mkIf (config.homecfg.make.gui) {
# home.packages = with pkgs; [
# custom.vosk
# custom.vosk.cli
# custom.vosk.lang.en
# custom.vosk.lang.ja
# custom.vosk.lang.de
# custom.vosk.lang.ru
# jq
# (python3.withPackages (ps: with ps; [ translatepy ]))
# ];
home.packages = with pkgs; [
custom.vosk.base
jq
(python3.withPackages (ps: with ps; [ translatepy ]))
];
# xdg.configFile."script/transcript-translate.py".text = ''
# #!/bin/python
xdg.configFile."script/transcript-translate.py".text = ''
#!/bin/python
# import sys;
# from translatepy.translators.google import GoogleTranslate;
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")
# '';
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
xdg.configFile."script/transcript.sh".text = ''
#!/bin/sh
# MODELS=(
# "English:${pkgs.custom.vosklang.en-us}/usr/share/vosk-models/en-us"
# "German:${pkgs.custom.vosklang.de}/usr/share/vosk-models/de"
# "Russian:${pkgs.custom.vosklang.ru}/usr/share/vosk-models/ru"
# "Japanese:${pkgs.custom.vosklang.ja}/usr/share/vosk-models/ja"
# )
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_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}')
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:")
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
# '';
export VOSK_MODEL=$MODEL
case $TRANS in
"None")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' 2>/dev/null
;;
"None-prog")
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty, .partial // empty | select(length > 0)' 2>/dev/null
;;
*)
${pkgs.custom.vosk.cli}/bin/voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // empty | select(length > 0)' | python ~/.config/script/transcript-translate.py $TRANS
;;
esac
'';
};
}

View File

@ -0,0 +1,19 @@
{ lib, pkgs, stdenv, fetchurl, unzip }:
stdenv.mkDerivation rec {
name = "vosk-api";
version = "0.3.45";
src = fetchurl {
url =
"https://github.com/alphacep/vosk-api/releases/download/v${version}/vosk-linux-x86_64-${version}.zip";
sha256 = "sha256-u9yO2FxDl59kQxQoiXcOqVy/vFbP+1xdzXOvqHXF+7I=";
};
nativeBuildInputs = [ unzip ];
unpackCmd = "unzip $curSrc";
installPhase = ''
mkdir -p $out/lib
mv libvosk.so $out/lib/
mkdir -p $out/include
mv vosk_api.h $out/include/
'';
}

View File

@ -11,8 +11,8 @@ buildGoModule rec {
sha256 = "sha256-TeCUtHuBGVyV+YmY3MGaf1jydTWgZITUgmUZzy4wZLU=";
};
preBuild = ''
export CGO_CFLAGS="-I${pkgs.vosk}/include"
export CGO_LDFLAGS="-L${pkgs.vosk}/lib"
export CGO_CFLAGS="-I${pkgs.custom.vosk.base}/include"
export CGO_LDFLAGS="-L${pkgs.custom.vosk.base}/lib"
'';
nativeBuildInputs = [ makeWrapper ];
installPhase = ''

View File

@ -1,26 +1,6 @@
{ lib, pkgs, stdenv, fetchurl, unzip }:
let
version = "0.3.45";
base = stdenv.mkDerivation {
name = "vosk-api";
version = "${version}";
src = fetchurl {
url =
"https://github.com/alphacep/vosk-api/releases/download/v${version}/vosk-linux-x86_64-${version}.zip";
sha256 = "sha256-u9yO2FxDl59kQxQoiXcOqVy/vFbP+1xdzXOvqHXF+7I=";
};
nativeBuildInputs = [ unzip ];
unpackCmd = "unzip $curSrc";
installPhase = ''
mkdir -p $out/lib
mv libvosk.so $out/lib/
mkdir -p $out/include
mv vosk_api.h $out/include/
'';
};
in {
default = (pkgs.callPackage base { });
{ pkgs, ... }: rec {
default = (pkgs.callPackage ./base { });
base = default;
cli = (pkgs.callPackage ./cli { });
lang = (pkgs.callPackage ./lang { });
}