From 2067944151913894d7009c1021629d6dbd69d511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Sun, 22 Sep 2024 17:33:04 +0200 Subject: [PATCH] tlg-wotd: use cltk for transcription --- configs/telegram-bots/tlg-wotd.nix | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/configs/telegram-bots/tlg-wotd.nix b/configs/telegram-bots/tlg-wotd.nix index 3105800..81292cd 100644 --- a/configs/telegram-bots/tlg-wotd.nix +++ b/configs/telegram-bots/tlg-wotd.nix @@ -2,6 +2,7 @@ pkgs, lib, config, + niveumPackages, ... }: { systemd.services.telegram-bot-tlg-wotd = { @@ -12,7 +13,7 @@ path = [ pkgs.jq pkgs.curl pkgs.recode pkgs.deno pkgs.imagemagick pkgs.gawk pkgs.gnugrep pkgs.coreutils ]; environment = { NPM_CONFIG_CACHE = "/tmp"; - DENO_DIR = "/tmp"; + CLTK_DATA = "/tmp"; }; script = '' set -efux @@ -29,9 +30,17 @@ first_occurrence=$(echo "$json_data" | jq -r '.firstOccurrence') total_occurrences=$(echo "$json_data" | jq -r '.totalOccurrences') - transliteration=$(deno run ${pkgs.writeText "translit.ts" '' - import grc from "npm:greek-transliteration"; - console.log(grc.transliterate(Deno.args.join(" "))); + transliteration=$(${pkgs.writers.writePython3 "translit.py" { + libraries = [ niveumPackages.cltk ]; + } '' + import sys + from cltk.phonology.grc.transcription import Transcriber + + probert = Transcriber("Attic", "Probert") + text = " ".join(sys.argv[1:]) + ipa = probert.transcribe(text) + + print(ipa) ''} "$compact_word") @@ -87,9 +96,9 @@ -font "${pkgs.gentium}/share/fonts/truetype/GentiumBookPlus-Regular.ttf" \ -fill "$color2" \ -pointsize 60 -gravity west \ - -annotate +100+00 "/$transliteration/" \ + -annotate +100+00 "$transliteration" \ -fill "$color1" \ - -annotate +100+100 "‘$definition’" \ + -annotate +100+120 "‘$definition’" \ -fill "$color2" \ -pointsize 40 -gravity southwest \ -annotate +100+60 "t.me/TLGWotD" \