advance on website script

This commit is contained in:
Tykayn 2021-03-23 12:54:17 +01:00 committed by tykayn
parent 590fcfd6ff
commit 8d31bff32a
19 changed files with 171 additions and 33 deletions

31
conversion_simple_en.py Normal file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
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)
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/fr")
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

BIN
input/ydl/uniqueid.mp3 Normal file

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"text" : ""
}
{
"text" : ""
}
{
"text" : ""
}
{
"text" : ""
}

View File

@ -0,0 +1,4 @@
""
""
""
""

View File

@ -0,0 +1,4 @@
""
""
""
""

View File

@ -0,0 +1,4 @@
""
""
""
""

View File

@ -0,0 +1,4 @@

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,44 @@
{
"result" : [{
"conf" : 0.545601,
"end" : 0.120000,
"start" : 0.000000,
"word" : "les"
}, {
"conf" : 0.658098,
"end" : 0.600019,
"start" : 0.180000,
"word" : "fascistes"
}, {
"conf" : 0.911231,
"end" : 0.719916,
"start" : 0.660000,
"word" : "de"
}, {
"conf" : 0.885049,
"end" : 1.109087,
"start" : 0.719916,
"word" : "merde"
}, {
"conf" : 0.512951,
"end" : 1.530000,
"start" : 1.380000,
"word" : "un"
}, {
"conf" : 0.840160,
"end" : 2.430000,
"start" : 1.547196,
"word" : "fasciste"
}, {
"conf" : 0.992080,
"end" : 2.609995,
"start" : 2.490000,
"word" : "de"
}, {
"conf" : 0.994251,
"end" : 3.210000,
"start" : 2.609995,
"word" : "merde"
}],
"text" : "les fascistes de merde un fasciste de merde"
}

View File

@ -0,0 +1 @@
"les fascistes de merde un fasciste de merde"

View File

@ -0,0 +1 @@
"les fascistes de merde un fasciste de merde"

View File

@ -0,0 +1 @@
"les fascistes de merde un fasciste de merde"

View File

@ -0,0 +1 @@
les fascistes de merde un fasciste de merde

Binary file not shown.

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