Comment intégrer Deepspeech dans un projet java maven?

Loris-steve Messages postés 4 Date d'inscription lundi 12 décembre 2022 Statut Membre Dernière intervention 5 août 2023 - Modifié le 5 août 2023 à 10:39
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 5 août 2023 à 15:34

J'ai essayé pendant 2 jours d'utiliser Deepspeech dans mon projet java fx mais je n'y arrive pas.

Quelqu'un sait si cela est possible?

A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
Modifié le 5 sept. 2023 à 10:48

Bonjour,

Dans la mesure où ton besoin n'a pas été véritablement expliqué, je vais aller au plus simple.

Je considère la dernière version de DeepSpeech, la 0.9.3 qui date de 2020.
Les livrables sont ici : https://github.com/mozilla/DeepSpeech/releases/tag/v0.9.3
La documentation est ici : https://deepspeech.readthedocs.io/en/v0.9.3/index.html
En particulier : Using a Pre-trained Model > Using the command-line client

Vu la documentation, je télécharge donc ces différents fichiers :

Dans mon répertoire de travail je me retrouve donc avec ces différents fichiers :

C:\deepspeech>
│   deepspeech-0.9.3-models.pbmm
│   deepspeech-0.9.3-models.scorer
├───audio
│       2830-3980-0043.wav
│       4507-16021-0012.wav
│       8455-210777-0068.wav
└───native_client
        deepspeech.exe
        ...

On peut tester en lignes de commandes que cela fonctionne bien avec un des fichiers d'exemple téléchargé.

C:\deepspeech\native_client\deepspeech.exe --model C:\deepspeech\deepspeech-0.9.3-models.pbmm --scorer C:\deepspeech\deepspeech-0.9.3-models.scorer --audio C:\deepspeech\audio\2830-3980-0043.wav

Passons à la partie Java en utilisant la méthode Runtime.exec(String[]) pour exécuter la même ligne de commande puis récupérer le résultat affiché.

import java.io.IOException;
import java.util.Scanner;

public class DeepSpeech {
    private static final String NATIVE_CLIENT = "C:\\deepspeech\\native_client\\deepspeech.exe";
    private static final String MODEL = "C:\\deepspeech\\deepspeech-0.9.3-models.pbmm";
    private static final String SCORER = "C:\\deepspeech\\deepspeech-0.9.3-models.scorer";

    public static String executeDeepSpeech(String audio) throws IOException {
        String[] cmdArray = {NATIVE_CLIENT, "--model", MODEL, "--scorer", SCORER, "--audio", audio};
        Process process = Runtime.getRuntime().exec(cmdArray);
        StringBuilder result = new StringBuilder();
        try (Scanner sc = new Scanner(process.getInputStream())) {
            while (sc.hasNextLine()) {
                result.append(sc.nextLine()).append("\n");
            }
        }
        return result.toString();
    }

    public static void main(String[] args) throws IOException {
        System.out.println(executeDeepSpeech("C:\\deepspeech\\audio\\2830-3980-0043.wav")); // experience proves this
        System.out.println(executeDeepSpeech("C:\\deepspeech\\audio\\4507-16021-0012.wav")); // why should one halt on the way
        System.out.println(executeDeepSpeech("C:\\deepspeech\\audio\\8455-210777-0068.wav")); // your paris sufficient i said
    }
}

Chez moi, ça fonctionne en mettant entre 1 et 2 secondes par fichier.
À voir ensuite ce que tu veux en faire dans ton projet Java FX.


1