Utilisation de l'auto-transcription dans Pod

Pour découper le fichier audio de pod et faire sa transcription, nous avons besoin de Sox, il faut donc installer les deux librairies suivantes :

Il faut également installer le module python ffmpeg-normalize

L'ensemble du modèle peuvent être stockés dans /path/to/project/django_projects/transcription. Il convient de faire un sous-dossier par langue (I.E: fr, en etc.), et un sous-dossier par type de modèle (I.E: stt, vosk, etc.)

Par exemple, pour un modèle vosk français:

/path/to/project/django_projects/transcription/fr/vosk/vosk-model-fr-0.6-linto-2.2.0/


STT (Coqui Ai)

pod@podv2:/usr/local/django_projects/transcription/model_fr/stt$ ll
-rw-r--r-- 1 pod pod        248 nov.  14 21:14 alphabet.txt
-rw-r--r-- 1 pod pod  189372825 nov.  15 09:12 model.pbmm
-rw-r--r-- 1 pod pod  1007576678 nov.  15 08:42 fr-cvfr-2-prune-kenlm.scorer
-rw-r--r-- 1 pod pod  47500492 nov.  15 08:54 model.tflite



les fichier peuvent être téléchargé sur le site du projet: https://coqui.ai/models

Dans le fichier custom/settings-local.py, il suffit d’ajouter les paramètres suivant:


Pour Pod à partir de la version 3 avec fr et en :

# Transcription
USE_TRANSCRIPTION = True

## Transcription use
# * STT
# * VOSK
TRANSCRIPTION_TYPE = "STT"

# Paramétrage des modèles
# * Pour télécharger les Modèles STT : https://coqui.ai/models
MODEL_PARAM = {
	# les modèles Stt
	'STT': {
		'fr': {
			'model': "/usr/local/django_projects/transcription/model_fr/stt/model.pbmm",
			'scorer': "/usr/local/django_projects/transcription/model_fr/stt/fr-cvfr-2-prune-kenlm.scorer",
		}
	} 
}


Pour ajouter un modèle d'un autre language, ajouter une entrée comme l'exemple ci-dessous, fait pour le language Anglais "en" :

# Paramétrage des modèles
# * Pour télécharger les Modèles STT : https://coqui.ai/models
MODEL_PARAM = {
	# les modèles Stt
	'STT': {
		'fr': {
			'model': "/usr/local/django_projects/transcription/model_fr/stt/model.pbmm",
			'scorer': "/usr/local/django_projects/transcription/model_fr/stt/fr-cvfr-2-prune-kenlm.scorer",
		},
		'en': {
			'model': "/usr/local/django_projects/transcription/model_en/stt/model.pbmm",
			'scorer': "/usr/local/django_projects/transcription/model_en/stt/kenlm.scorer",
		}
	} 
}


Pour tester l'encodage en ligne de commande :


$ python manage shell (pour lancer le shell)


$> from pod.video import transcript (dans le shell, je charge le module transcript de pod)


$>transcript.main_threaded_transcript(<video_id>) (j'appelle la fonction


main_threaded_transcript du module transcript pour transcrire la video dont l'identifiant est


<video_id>)



Vosk

Les fichiers pour les modèles peuvent être téléchargés sur cette page https://alphacephei.com/vosk/models.

Par exemple pour le modèle français:

Il faut après avoir téléchargé le modèle, il faut le décompresser. Pour cela vous pouvez utiliser la librairie unzip:


Dans le fichier custom/settings-local.py, il suffit d’ajouter les paramètres suivant:

Pour Pod avec Vosk avec fr :

# Transcription
USE_TRANSCRIPTION = True

## Transcription use
# * STT
# * VOSK
TRANSCRIPTION_TYPE = "VOSK"

# Paramétrage des modèles
# * Pour télécharger les Modèles Vosk : https://alphacephei.com/vosk/models
MODEL_PARAM = {
  # les modèles Vosk
  'VOSK':{
    'fr': {
      'model': "/path/of/project/django_projects/transcription/model_fr/vosk/vosk-model-fr-0.6-linto-2.2.0",
    }
  }
}


Pour ajouter un modèle d'un autre language, ajouter une entrée comme l'exemple ci-dessous, fait pour le language Anglais "en" :

# Paramétrage des modèles
# * Pour télécharger les Modèles Vosk : https://alphacephei.com/vosk/models
MODEL_PARAM = {
  # le modèle vosk
  'VOSK':{
    'fr': {
      'model': "/path/of/project/django_projects/transcription/model_fr/vosk/vosk-model-fr-0.6-linto-2.2.0",
    },
 	'en': {
      'model': "/path/of/project/django_projects/transcription/model_en/vosk/vosk-model-en-us-0.22",
    }
  }
}


Maintenant lors de l’upload d’une vidéo avec l’auto-transcription activée le modèle Vosk sera utilisé pour effectuer la transcription.

Activer L’enrichissement du modèle vosk dans Pod:


Les modèles utilisés pour l’enrichissement du modèle peuvent être stockés dans /path/to/project/django_projects/compile-model


Il faut télécharger le modèle de compilation correspondant sur ce lien https://alphacephei.com/vosk/lm#update-process.

Par exemple pour le modèle français:

Il faut après avoir téléchargé le modèle de compilation, le décompresser. Pour cela vous pouvez utiliser la librairie unzip:


Il faut seulement que la structure du dossier compile-model ressemble à cela:


(django_pod) pod@:/path/to/project/django_projects/compile-model

compile-model


|--fr
|   |--conf
|   |   |...
|   |
|   |--data
|   |   |...
|   |
|   |--db
|   |   |...
|   |
|   |--exp
|   |   |...
|   |
|   |--local
|   |   |...
|   |
|   |--mfcc
|   |   |...
|   |
|   |--steps
|   |   |...
|   |
|   |--utils
|   |   |...
|   |
|   |--cmd.sh
|   |--compile-grapg.sh
|   |--decode.sh
|   |--dict.py
|   |--path.sh
|   
|--en



Maintenant il faut installer docker sur votre machine. (voir https://docs.docker.com/engine/install/debian/ ci besoin)

Après que docker soit installer créer un fichier entrypoint.sh et DockerFile dans un même dossier.

Copier le script suivant dans le fichier entrypoint.sh;


#!/bin/bash
modelPath="$KALDI_ROOT/compile-model/$1"
cat "$KALDI_ROOT/tools/env.sh" > "$modelPath/path.sh"
cd $modelPath
/bin/bash -c "./compile-graph.sh"
/bin/bash -c "utils/build_const_arpa_lm.sh lm.gz data/lang_test data/lang_test_rescore"


Puis copier le code ci-dessous fait sur mesure afin d’enrichire un modèle dans le Fichier DockerFile, cela créera un container avec tout ce qu’il faut d’installer :

## Build the DockerFile
# docker build --tag kaldi -f DockerFile .
##
## Example of manual execution of the Docker file
# sudo docker run -v ${PWD}/compile-model:/kaldi/compile-model -it kaldi
##
FROM debian:10
RUN apt-get update && apt-get install -y ca-certificates \
 && apt-get install -y \
 python3-pip \
 git \
 && apt-get install -y zlib1g-dev automake autoconf unzip wget sox gfortran libtool subversion python2.7 nano libfst-tools \
 && apt-get clean
RUN python3 --version
ENV KALDI_ROOT="/kaldi"
RUN git clone https://github.com/kaldi-asr/kaldi.git $KALDI_ROOT
WORKDIR $KALDI_ROOT"/tools"
RUN bash $KALDI_ROOT"/tools/extras/check_dependencies.sh"
RUN touch $KALDI_ROOT"/tools/python/.use_default_python"
RUN bash $KALDI_ROOT"/tools/extras/install_mkl.sh"
RUN apt-get install gfortran sox
RUN make -j $(nproc)
RUN pip3 install phonetisaurus
RUN bash $KALDI_ROOT"/tools/extras/install_opengrm.sh"
RUN make
RUN bash $KALDI_ROOT"/tools/extras/install_irstlm.sh"
RUN apt-get install gawk
RUN bash $KALDI_ROOT"/tools/extras/install_srilm.sh" "unkown" "unkown" "unkown"
RUN cd $KALDI_ROOT"/src" && ./configure --shared
RUN cd $KALDI_ROOT"/src" && make depend -j $(nproc)
RUN cd $KALDI_ROOT"/src" && make -j $(nproc)
RUN cd $KALDI_ROOT"/src/fstbin" && make
RUN echo "export PATH="$KALDI_ROOT"/src/fstbin:\$PATH" >> $KALDI_ROOT"/tools/env.sh"
RUN cd $KALDI_ROOT"/src/lmbin" && make
RUN echo "export PATH="$KALDI_ROOT"/src/lmbin:\$PATH" >> $KALDI_ROOT"/tools/env.sh"
RUN cd $KALDI_ROOT"/src/tree" && make
RUN echo "export PATH="$KALDI_ROOT"/src/tree:\$PATH" >> $KALDI_ROOT"/tools/env.sh"
RUN cd $KALDI_ROOT"/src/bin" && make
RUN echo "export PATH="$KALDI_ROOT"/src/bin:\$PATH" >> $KALDI_ROOT"/tools/env.sh"
COPY entrypoint.sh /entrypoint.sh
WORKDIR $KALDI_ROOT
ENTRYPOINT ["/entrypoint.sh"]


Après avoir copié et créer les deux fichier Dockerfile et entrypoint.sh il suffit de lancer la commande ci-dessous en étant dans la même dossier que les fichiers précédemment mentionnés.


Pour finir il faut activer l’enrichissement du modèle vosk dans une application pod, pour cela il suffit d’ajouter dans le fichier custom/settings-local.py les paramètres suivant:


ACTIVE_ENRICH = True
MODEL_COMPILE_DIR = "/path/to/project/django_projects/compile-model"