[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, ... }: { { lib, config, pkgs, ... }: {
config = lib.mkIf (config.homecfg.make.gui) { config = lib.mkIf (config.homecfg.make.gui) {
# home.packages = with pkgs; [ home.packages = with pkgs; [
# custom.vosk custom.vosk.base
# custom.vosk.cli jq
# custom.vosk.lang.en (python3.withPackages (ps: with ps; [ translatepy ]))
# 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 = '' xdg.configFile."script/transcript-translate.py".text = ''
# #!/bin/python #!/bin/python
# import sys; import sys;
# from translatepy.translators.google import GoogleTranslate; from translatepy.translators.google import GoogleTranslate;
# if len(sys.argv) != 2: if len(sys.argv) != 2:
# print("No language provided.") print("No language provided.")
# exit exit
# translator = GoogleTranslate() translator = GoogleTranslate()
# while True: while True:
# for line in sys.stdin: for line in sys.stdin:
# sys.stdout.write(translator.translate(line,sys.argv[1]).result+"\n") sys.stdout.write(translator.translate(line,sys.argv[1]).result+"\n")
# ''; '';
# xdg.configFile."script/transcript.sh".text = '' xdg.configFile."script/transcript.sh".text = ''
# #!/bin/sh #!/bin/sh
# MODELS=( MODELS=(
# "English:${pkgs.custom.vosklang.en-us}/usr/share/vosk-models/en-us" "English:${pkgs.custom.vosk.lang.en-us}/usr/share/vosk-models/en-us"
# "German:${pkgs.custom.vosklang.de}/usr/share/vosk-models/de" "German:${pkgs.custom.vosk.lang.de}/usr/share/vosk-models/de"
# "Russian:${pkgs.custom.vosklang.ru}/usr/share/vosk-models/ru" "Russian:${pkgs.custom.vosk.lang.ru}/usr/share/vosk-models/ru"
# "Japanese:${pkgs.custom.vosklang.ja}/usr/share/vosk-models/ja" "Japanese:${pkgs.custom.vosk.lang.ja}/usr/share/vosk-models/ja"
# ) )
# MODEL_OPTS="" MODEL_OPTS=""
# for pair in "''${MODELS[@]}"; do for pair in "''${MODELS[@]}"; do
# MODEL_OPTS+="$pair\n" MODEL_OPTS+="$pair\n"
# done done
# MODEL_OPT=$(echo -e "$MODEL_OPTS" | wofi --dmenu -p "Choose model:") MODEL_OPT=$(echo -e "$MODEL_OPTS" | wofi --dmenu -p "Choose model:")
# MODEL=$(echo "$MODEL_OPT" | awk -F ':' '{print $2}') MODEL=$(echo "$MODEL_OPT" | awk -F ':' '{print $2}')
# TRANSS="None\nNone-prog\nEnglish\nGerman\nRussian\nJapanese" TRANSS="None\nNone-prog\nEnglish\nGerman\nRussian\nJapanese"
# TRANS=$(echo -e "$TRANSS" | wofi --dmenu -p "Choose translation:") TRANS=$(echo -e "$TRANSS" | wofi --dmenu -p "Choose translation:")
# export VOSK_MODEL=$MODEL export VOSK_MODEL=$MODEL
# case $TRANS in case $TRANS in
# "None") "None")
# voskcli 2>/dev/null | jq --unbuffered -r '.alternatives[0].text // 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)' 2>/dev/null
# ;; ;;
# "None-prog") "None-prog")
# 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, .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 ${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 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="; sha256 = "sha256-TeCUtHuBGVyV+YmY3MGaf1jydTWgZITUgmUZzy4wZLU=";
}; };
preBuild = '' preBuild = ''
export CGO_CFLAGS="-I${pkgs.vosk}/include" export CGO_CFLAGS="-I${pkgs.custom.vosk.base}/include"
export CGO_LDFLAGS="-L${pkgs.vosk}/lib" export CGO_LDFLAGS="-L${pkgs.custom.vosk.base}/lib"
''; '';
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
installPhase = '' installPhase = ''

View File

@ -1,26 +1,6 @@
{ lib, pkgs, stdenv, fetchurl, unzip }: { pkgs, ... }: rec {
let default = (pkgs.callPackage ./base { });
version = "0.3.45"; base = default;
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 { });
cli = (pkgs.callPackage ./cli { }); cli = (pkgs.callPackage ./cli { });
lang = (pkgs.callPackage ./lang { }); lang = (pkgs.callPackage ./lang { });
} }