all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nicolas Graves via Guix-patches via <guix-patches@gnu.org>
To: 58140@debbugs.gnu.org
Cc: ngraves@ngraves.fr
Subject: [bug#58140] [PATCH 2/6] gnu: Add kaldi-for-vosk.
Date: Wed, 28 Sep 2022 13:57:51 +0200	[thread overview]
Message-ID: <20220928115755.6292-2-ngraves@ngraves.fr> (raw)
In-Reply-To: <20220928115755.6292-1-ngraves@ngraves.fr>

* gnu/packages/machine-learning.scm (kaldi-for-vosk): New variable.
---
 gnu/packages/machine-learning.scm | 98 +++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)

diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index 3ad907e0c9..9b2e01c102 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1596,6 +1596,104 @@ (define-public kaldi
 written in C++.")
       (license license:asl2.0))))
 
+(define kaldi-for-vosk
+  (let* ((commit "6417ac1dece94783e80dfbac0148604685d27579")
+         (revision "0")
+         (openfst openfst-for-vosk))
+    (package
+      (inherit kaldi)
+      (name "kaldi")
+      (version (git-version "0" revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/alphacep/kaldi")
+               (commit commit)))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "04xw2dpfvpla8skpk08azmgr9k97cd8hn83lj4l85q165gbzql4s"))))
+      (inputs
+       (list alsa-lib
+             ;; `(,gfortran "lib") ;; replaced by lapack
+             lapack
+             glib
+             gstreamer
+             jack-1
+             openblas
+             openfst
+             portaudio
+             python))
+      (arguments
+       (list
+        #:test-target "test"
+        #:make-flags ''("online2" "lm" "rnnlm")
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'chdir
+              (lambda _ (chdir "src") #t))
+            (replace 'configure
+              (lambda* (#:key build system inputs outputs #:allow-other-keys)
+                (when (not (or (string-prefix? "x86_64" system)
+                               (string-prefix? "i686" system)))
+                  (substitute* "makefiles/linux_openblas.mk"
+                    (("-msse -msse2") "")))
+                (substitute* "makefiles/default_rules.mk"
+                  (("/bin/bash") (which "bash")))
+                (substitute* "Makefile"
+                  (("ext_depend: check_portaudio")
+                   "ext_depend:"))
+                (substitute* '("online/Makefile"
+                               "onlinebin/Makefile"
+                               "gst-plugin/Makefile")
+                  (("../../tools/portaudio/install")
+                   (assoc-ref inputs "portaudio")))
+                (substitute* "matrix/Makefile"     ;temporary test bypass
+                  (("matrix-lib-test sparse-matrix-test") ""))
+
+                ;; This `configure' script doesn't support variables passed as
+                ;; arguments, nor does it support "prefix".
+                (let ((out (assoc-ref outputs "out")))
+                  (substitute* "configure"
+                    (("check_for_slow_expf;") "")
+                    ;; This affects the RPATH and also serves as the installation
+                    ;; directory.
+                    (("KALDILIBDIR=`pwd`/lib")
+                     (string-append "KALDILIBDIR=" out "/lib"))
+                    (("OPENBLASROOT=\\\"\\$\\(rel2abs ..\\/tools\\/OpenBLAS\\/install\\)\\\"")
+                     (string-append "OPENBLASROOT=\"" #$openblas "\""))
+                    (("-L\\$OPENBLASLIBDIR -l:libopenblas.a -l:libblas.a -l:liblapack.a -l:libf2c.a")
+                     (string-append "-L$OPENBLASLIBDIR -lopenblas "
+                                    "-L" #$lapack "/lib -lblas -llapack")))
+                  (mkdir-p out) ; must exist
+                  (setenv "CONFIG_SHELL" (which "bash"))
+                  (setenv "OPENFST_VER" #$(package-version openfst))
+                  (invoke "./configure"
+                          "--use-cuda=no"
+                          "--mathlib=OPENBLAS_CLAPACK"
+                          "--shared"
+                          (string-append "--fst-root=" #$openfst)))))
+            (add-after 'configure 'optimize-build
+                       (lambda _ (substitute* "kaldi.mk" ((" -O1") " -O3"))))
+            (replace 'install
+              (lambda* (#:key outputs #:allow-other-keys)
+                (let* ((out (assoc-ref outputs "out"))
+                       (inc (string-append out "/include"))
+                       (lib (string-append out "/lib")))
+                  (mkdir-p lib)
+                  ;; The build phase installed symlinks to the actual
+                  ;; libraries.  Install the actual targets.
+                  (for-each (lambda (file)
+                              (let ((target (readlink file)))
+                                (delete-file file)
+                                (install-file target lib)))
+                            (find-files lib "\\.so"))
+                  ;; Install headers
+                  (for-each (lambda (file)
+                              (let ((target-dir (string-append inc "/" (dirname file))))
+                                (install-file file target-dir)))
+                            (find-files "." "\\.h")))))))))))
+
 (define-public gst-kaldi-nnet2-online
   (let ((commit "cb227ef43b66a9835c14eb0ad39e08ee03c210ad")
         (revision "2"))
-- 
2.37.3





  reply	other threads:[~2022-09-28 15:15 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-28 11:34 [bug#58140] Simple offline text-to-speech incoming ! Nicolas Graves via Guix-patches via
2022-09-28 11:57 ` [bug#58140] [PATCH 1/6] gnu: Add openfst-for-vosk Nicolas Graves via Guix-patches via
2022-09-28 11:57   ` Nicolas Graves via Guix-patches via [this message]
2022-09-28 21:05     ` [bug#58140] [PATCH 2/6] gnu: Add kaldi-for-vosk Maxime Devos
2022-09-29  6:44       ` ( via Guix-patches via
2022-09-29  8:20       ` Nicolas Graves via Guix-patches via
2022-09-29  9:32         ` Maxime Devos
2022-09-28 11:57   ` [bug#58140] [PATCH 3/6] gnu: Add vosk-api Nicolas Graves via Guix-patches via
2022-09-28 11:57   ` [bug#58140] [PATCH 4/6] gnu: Add python-vosk Nicolas Graves via Guix-patches via
2022-09-28 11:57   ` [bug#58140] [PATCH 5/6] gnu: Add python-nerd-dictation Nicolas Graves via Guix-patches via
2022-09-28 11:57   ` [bug#58140] [PATCH 6/6] gnu: Add python-nerd-dictation/wayland Nicolas Graves via Guix-patches via
2022-09-28 17:58 ` [bug#58140] Simple offline text-to-speech incoming ! Denis 'GNUtoo' Carikli
2022-09-28 20:07   ` Nicolas Graves via Guix-patches via
2022-09-28 21:30 ` [bug#58140] [PATCH 6/6 v2] gnu: Add python-nerd-dictation/wayland Nicolas Graves via Guix-patches via
2022-09-28 21:39   ` Maxime Devos
2022-09-29  9:00 ` [bug#58140] [PATCH v3 1/6] gnu: Add openfst-for-vosk Nicolas Graves via Guix-patches via
2022-09-29  9:00   ` [bug#58140] [PATCH v3 2/6] gnu: Add kaldi-for-vosk Nicolas Graves via Guix-patches via
2022-09-29  9:00   ` [bug#58140] [PATCH v3 3/6] gnu: Add vosk-api Nicolas Graves via Guix-patches via
2022-09-29  9:00   ` [bug#58140] [PATCH v3 4/6] gnu: Add python-vosk Nicolas Graves via Guix-patches via
2022-09-29  9:00   ` [bug#58140] [PATCH v3 5/6] gnu: Add python-nerd-dictation Nicolas Graves via Guix-patches via
2022-09-29  9:00   ` [bug#58140] [PATCH v3 6/6] gnu: Add python-nerd-dictation/wayland Nicolas Graves via Guix-patches via
2022-09-29  9:02 ` [bug#58140] [PATCH v4 1/2] gnu: Add nerd-dictation Nicolas Graves via Guix-patches via
2022-09-29  9:02   ` [bug#58140] [PATCH v4 2/2] gnu: Add nerd-dictation/wayland Nicolas Graves via Guix-patches via
2022-10-17  8:46     ` bug#58140: Simple offline text-to-speech incoming ! Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220928115755.6292-2-ngraves@ngraves.fr \
    --to=guix-patches@gnu.org \
    --cc=58140@debbugs.gnu.org \
    --cc=ngraves@ngraves.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.