Compare commits

...

2 Commits

Author SHA1 Message Date
ed4d03342d simple convert in en script 2021-03-23 12:54:53 +01:00
8d31bff32a advance on website script 2021-03-23 12:54:17 +01:00
7 changed files with 103 additions and 37 deletions

30
conversion_simple_en.py Normal file
View 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())

View File

@ -6,8 +6,6 @@ import os
import wave
SetLogLevel(0)
print(" ------- conversion simple de", sys.argv[1])
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.")
exit (1)

View File

View File

@ -6,6 +6,14 @@ if [ $1 ]; then
file=$1
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,
avec Vosk installé par pip3, et un modèle de textes en français."
echo " "
@ -40,8 +48,7 @@ else
exit 1
fi
echo " "
FILE_NAME=$(basename $file .wav)
OUT_DIR=$( echo "output/$FILE_NAME")
mkdir output/$FILE_NAME
echo " convertir en sous titre ? $ENABLE_SRT"
if ($ENABLE_SRT) ; then

View File

@ -1,27 +1,31 @@
<?php
include( '_head.php' );
/**
?>
<div class="container">
<?php
/**
* récupération d'une vidéo par youtube dl et conversion
*/
/**
/**
* @param $cmd
*
* @return bool
*/
function command_exist( $cmd ) {
function command_exist( $cmd ) {
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
return ! empty( $return );
}
}
if ( isset( $_POST[ 'url' ] ) ) {
if ( isset( $_POST[ 'url' ] ) ) {
// sanitize input
$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')) {
// print '[Erreur] pas de commande youtube-dl installée sur ce serveur';
@ -30,26 +34,40 @@ if ( isset( $_POST[ 'url' ] ) ) {
$uniqid = time();
# 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);
// shell_exec('youtube-dl --extract-audio --audio-format flac --audio-quality 0 --output "../input/ydl/%(title)s_audio.%(ext)s" '.$url);
// exec( $old . '/youtube-dl.sh ' . $uniqid . ' ' . $url, $output, $result );
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
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>";
$dir = scandir( '../input/ydl' );
$dir = scandir( '../input/ydl/' . $uniqid );
var_dump( $dir );
// }
} else {
echo "pas d'url envoyée. Vérifiez le formulaire. <a href='index.php'>Retour</a>";
}
} else {
echo " <br> pas d'url envoyée. Vérifiez le formulaire. <a href='index.php'>Retour</a>";
}
?>
</div>
<?php
include( '_foot.php' );

3
website/test.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
echo " coucou" > test_works.txt

16
website/youtube-dl.sh Normal file → Executable file
View File

@ -1,9 +1,19 @@
#!/bin/bash
mkdir -p ../input/ydl
UNIQID=$1
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
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