Compare commits
2 Commits
590fcfd6ff
...
ed4d03342d
Author | SHA1 | Date | |
---|---|---|---|
ed4d03342d | |||
8d31bff32a |
30
conversion_simple_en.py
Normal file
30
conversion_simple_en.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from vosk import Model, KaldiRecognizer, SetLogLevel
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import wave
|
||||||
|
|
||||||
|
SetLogLevel(0)
|
||||||
|
|
||||||
|
if not os.path.exists("models/en"):
|
||||||
|
print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'models' in the current folder.")
|
||||||
|
exit (1)
|
||||||
|
|
||||||
|
|
||||||
|
wf = wave.open(sys.argv[1], "rb")
|
||||||
|
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
|
||||||
|
print ("Audio file must be WAV format mono PCM.")
|
||||||
|
exit (1)
|
||||||
|
|
||||||
|
model = Model("models/en")
|
||||||
|
rec = KaldiRecognizer(model, wf.getframerate())
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data = wf.readframes(4000)
|
||||||
|
if len(data) == 0:
|
||||||
|
break
|
||||||
|
if rec.AcceptWaveform(data):
|
||||||
|
print(rec.Result())
|
||||||
|
|
||||||
|
print(rec.FinalResult())
|
@ -6,8 +6,6 @@ import os
|
|||||||
import wave
|
import wave
|
||||||
|
|
||||||
SetLogLevel(0)
|
SetLogLevel(0)
|
||||||
print(" ------- conversion simple de", sys.argv[1])
|
|
||||||
|
|
||||||
if not os.path.exists("models/fr"):
|
if not os.path.exists("models/fr"):
|
||||||
print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'models' in the current folder.")
|
print ("Please download the model from https://alphacephei.com/vosk/models and unpack as 'models' in the current folder.")
|
||||||
exit (1)
|
exit (1)
|
||||||
|
@ -6,6 +6,14 @@ if [ $1 ]; then
|
|||||||
file=$1
|
file=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
FILE_NAME=$(basename $file .wav)
|
||||||
|
|
||||||
|
output_dir="output"
|
||||||
|
if [ $2 ]; then
|
||||||
|
output_dir=$2
|
||||||
|
fi
|
||||||
|
OUT_DIR=$( echo "$output_dir/$FILE_NAME")
|
||||||
|
|
||||||
echo "########### $(date) : conversion de fichier audio .WAV mono piste uniquement,
|
echo "########### $(date) : conversion de fichier audio .WAV mono piste uniquement,
|
||||||
avec Vosk installé par pip3, et un modèle de textes en français."
|
avec Vosk installé par pip3, et un modèle de textes en français."
|
||||||
echo " "
|
echo " "
|
||||||
@ -40,8 +48,7 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo " "
|
echo " "
|
||||||
FILE_NAME=$(basename $file .wav)
|
|
||||||
OUT_DIR=$( echo "output/$FILE_NAME")
|
|
||||||
mkdir output/$FILE_NAME
|
mkdir output/$FILE_NAME
|
||||||
echo " convertir en sous titre ? $ENABLE_SRT"
|
echo " convertir en sous titre ? $ENABLE_SRT"
|
||||||
if ($ENABLE_SRT) ; then
|
if ($ENABLE_SRT) ; then
|
||||||
|
@ -1,27 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
include( '_head.php' );
|
include( '_head.php' );
|
||||||
/**
|
?>
|
||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
* récupération d'une vidéo par youtube dl et conversion
|
* récupération d'une vidéo par youtube dl et conversion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $cmd
|
* @param $cmd
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function command_exist( $cmd ) {
|
function command_exist( $cmd ) {
|
||||||
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
|
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
|
||||||
|
|
||||||
return ! empty( $return );
|
return ! empty( $return );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $_POST[ 'url' ] ) ) {
|
if ( isset( $_POST[ 'url' ] ) ) {
|
||||||
// sanitize input
|
// sanitize input
|
||||||
|
|
||||||
$url = $_POST[ 'url' ];
|
$url = $_POST[ 'url' ];
|
||||||
|
|
||||||
echo "récupération de la vidéo à l'url " . $url . " ... <br>";
|
echo "<br/>récupération de la vidéo à l'url " . $url . " ... <br>";
|
||||||
|
|
||||||
// if (!command_exist('youtube-dl')) {
|
// if (!command_exist('youtube-dl')) {
|
||||||
// print '[Erreur] pas de commande youtube-dl installée sur ce serveur';
|
// print '[Erreur] pas de commande youtube-dl installée sur ce serveur';
|
||||||
@ -30,26 +34,40 @@ if ( isset( $_POST[ 'url' ] ) ) {
|
|||||||
$uniqid = time();
|
$uniqid = time();
|
||||||
|
|
||||||
# exemple url https://peertube.cipherbliss.com/videos/watch/e6a37508-042e-4d83-8598-5d36b764bb3d
|
# exemple url https://peertube.cipherbliss.com/videos/watch/e6a37508-042e-4d83-8598-5d36b764bb3d
|
||||||
shell_exec( 'bash youtube-dl.sh ' . $uniqid . ' ' . $url );
|
$old = getcwd();
|
||||||
|
echo $old;
|
||||||
|
chdir( $old );
|
||||||
|
|
||||||
// shell_exec('youtube-dl --extract-audio --audio-format flac --audio-quality 0 --output "../input/ydl/$time.flac" '.$url);
|
// exec( $old . '/youtube-dl.sh ' . $uniqid . ' ' . $url, $output, $result );
|
||||||
// shell_exec('youtube-dl --extract-audio --audio-format flac --audio-quality 0 --output "../input/ydl/%(title)s_audio.%(ext)s" '.$url);
|
exec( $old . '/test.sh ' . $uniqid . ' ' . $url, $output, $result );
|
||||||
|
|
||||||
|
echo "<br/> résultat du script. <br>";
|
||||||
|
var_dump( $result );
|
||||||
|
echo "<br/> sortie du script. <br>";
|
||||||
|
var_dump( $output );
|
||||||
|
if ( $result ) {
|
||||||
|
echo( '<div class="alert is-danger"> problème de script </div>' );
|
||||||
|
include( '_foot.php' );
|
||||||
|
}
|
||||||
// récup du nom de fichier
|
// récup du nom de fichier
|
||||||
echo "récupération de la vidéo OK " . $url . ". <br>";
|
echo "<br/>récupération de la vidéo OK. <br>";
|
||||||
|
|
||||||
|
|
||||||
echo "Conversion de la vidéo" . $url . "... <br>";
|
echo "<br/>Conversion de la vidéo " . $uniqid . "... <br>";
|
||||||
|
|
||||||
echo "Vous pouvez télécharger vos fichiers.<br>";
|
echo "Vous pouvez télécharger vos fichiers.<br>";
|
||||||
|
|
||||||
$dir = scandir( '../input/ydl' );
|
$dir = scandir( '../input/ydl/' . $uniqid );
|
||||||
var_dump( $dir );
|
var_dump( $dir );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo "pas d'url envoyée. Vérifiez le formulaire. <a href='index.php'>Retour</a>";
|
echo " <br> pas d'url envoyée. Vérifiez le formulaire. <a href='index.php'>Retour</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
include( '_foot.php' );
|
include( '_foot.php' );
|
||||||
|
3
website/test.sh
Executable file
3
website/test.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo " coucou" > test_works.txt
|
16
website/youtube-dl.sh
Normal file → Executable file
16
website/youtube-dl.sh
Normal file → Executable file
@ -1,9 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
mkdir -p ../input/ydl
|
||||||
|
|
||||||
UNIQID=$1
|
UNIQID=$1
|
||||||
URL=$2
|
URL=$2
|
||||||
OUTPUT="../input/ydl/$UNIQID.flac"
|
OUTPUT="../input/ydl/$UNIQID.mp3"
|
||||||
|
|
||||||
youtube-dl --extract-audio --audio-format flac --audio-quality 0 --output $OUTPUT $URL
|
youtube-dl --extract-audio --audio-format mp3 --audio-quality 0 --output $OUTPUT $URL
|
||||||
mkdir ../input/ydl/$UNIQID
|
mkdir ../input/ydl/$UNIQID
|
||||||
ffmpeg -i "../input/ydl/$UNIQID" -ac 1 "../input/ydl/'.$UNIQID.'.wav"
|
ffmpeg -i "../input/ydl/$UNIQID.mp3" -ac 1 "../input/ydl/$UNIQID/$UNIQID.wav"
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
OUT_DIR="input/ydl/$UNIQID"
|
||||||
|
python3 ./conversion_simple_fr.py "input/ydl/$UNIQID/$UNIQID.wav" > $OUT_DIR/0_output_$FILE_NAME.json
|
||||||
|
jq .text $OUT_DIR/0_output_$FILE_NAME.json > $OUT_DIR/1_converted_$FILE_NAME.txt
|
||||||
|
sed 's/null//g' $OUT_DIR/1_converted_$FILE_NAME.txt > $OUT_DIR/2_without_nulls_$FILE_NAME.txt
|
||||||
|
sed 's/^ *//; s/ *$//; /^$/d' $OUT_DIR/2_without_nulls_$FILE_NAME.txt > $OUT_DIR/3_without_nulls_$FILE_NAME.txt
|
||||||
|
sed 's/\"//g' $OUT_DIR/3_without_nulls_$FILE_NAME.txt > $OUT_DIR/4_phrases_$FILE_NAME.txt
|
||||||
|
Loading…
Reference in New Issue
Block a user