advance on website script
This commit is contained in:
parent
590fcfd6ff
commit
8d31bff32a
31
conversion_simple_en.py
Normal file
31
conversion_simple_en.py
Normal 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())
|
BIN
input/ydl/uniqueid.mp3
Normal file
BIN
input/ydl/uniqueid.mp3
Normal file
Binary file not shown.
12
input/ydl/uniqueid/0_output_.json
Normal file
12
input/ydl/uniqueid/0_output_.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"text" : ""
|
||||
}
|
||||
{
|
||||
"text" : ""
|
||||
}
|
||||
{
|
||||
"text" : ""
|
||||
}
|
||||
{
|
||||
"text" : ""
|
||||
}
|
4
input/ydl/uniqueid/1_converted_.txt
Normal file
4
input/ydl/uniqueid/1_converted_.txt
Normal file
@ -0,0 +1,4 @@
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
4
input/ydl/uniqueid/2_without_nulls_.txt
Normal file
4
input/ydl/uniqueid/2_without_nulls_.txt
Normal file
@ -0,0 +1,4 @@
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
4
input/ydl/uniqueid/3_without_nulls_.txt
Normal file
4
input/ydl/uniqueid/3_without_nulls_.txt
Normal file
@ -0,0 +1,4 @@
|
||||
""
|
||||
""
|
||||
""
|
||||
""
|
4
input/ydl/uniqueid/4_phrases_.txt
Normal file
4
input/ydl/uniqueid/4_phrases_.txt
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
|
||||
|
BIN
input/ydl/uniqueid/uniqueid.wav
Normal file
BIN
input/ydl/uniqueid/uniqueid.wav
Normal file
Binary file not shown.
BIN
input/ydl/uniqueid_facho.mp3
Normal file
BIN
input/ydl/uniqueid_facho.mp3
Normal file
Binary file not shown.
44
input/ydl/uniqueid_facho/0_output_.json
Normal file
44
input/ydl/uniqueid_facho/0_output_.json
Normal 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"
|
||||
}
|
1
input/ydl/uniqueid_facho/1_converted_.txt
Normal file
1
input/ydl/uniqueid_facho/1_converted_.txt
Normal file
@ -0,0 +1 @@
|
||||
"les fascistes de merde un fasciste de merde"
|
1
input/ydl/uniqueid_facho/2_without_nulls_.txt
Normal file
1
input/ydl/uniqueid_facho/2_without_nulls_.txt
Normal file
@ -0,0 +1 @@
|
||||
"les fascistes de merde un fasciste de merde"
|
1
input/ydl/uniqueid_facho/3_without_nulls_.txt
Normal file
1
input/ydl/uniqueid_facho/3_without_nulls_.txt
Normal file
@ -0,0 +1 @@
|
||||
"les fascistes de merde un fasciste de merde"
|
1
input/ydl/uniqueid_facho/4_phrases_.txt
Normal file
1
input/ydl/uniqueid_facho/4_phrases_.txt
Normal file
@ -0,0 +1 @@
|
||||
les fascistes de merde un fasciste de merde
|
BIN
input/ydl/uniqueid_facho/uniqueid_facho.wav
Normal file
BIN
input/ydl/uniqueid_facho/uniqueid_facho.wav
Normal file
Binary file not shown.
@ -1,55 +1,73 @@
|
||||
<?php
|
||||
include( '_head.php' );
|
||||
/**
|
||||
* récupération d'une vidéo par youtube dl et conversion
|
||||
*/
|
||||
?>
|
||||
<div class="container">
|
||||
|
||||
<?php
|
||||
/**
|
||||
* récupération d'une vidéo par youtube dl et conversion
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @param $cmd
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function command_exist( $cmd ) {
|
||||
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
|
||||
/**
|
||||
* @param $cmd
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function command_exist( $cmd ) {
|
||||
$return = shell_exec( sprintf( "which %s", escapeshellarg( $cmd ) ) );
|
||||
|
||||
return ! empty( $return );
|
||||
}
|
||||
return ! empty( $return );
|
||||
}
|
||||
|
||||
if ( isset( $_POST[ 'url' ] ) ) {
|
||||
// sanitize input
|
||||
if ( isset( $_POST[ 'url' ] ) ) {
|
||||
// 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')) {
|
||||
// print '[Erreur] pas de commande youtube-dl installée sur ce serveur';
|
||||
// } else {
|
||||
|
||||
$uniqid = time();
|
||||
$uniqid = time();
|
||||
|
||||
# exemple url https://peertube.cipherbliss.com/videos/watch/e6a37508-042e-4d83-8598-5d36b764bb3d
|
||||
shell_exec( 'bash youtube-dl.sh ' . $uniqid . ' ' . $url );
|
||||
# exemple url https://peertube.cipherbliss.com/videos/watch/e6a37508-042e-4d83-8598-5d36b764bb3d
|
||||
$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);
|
||||
// récup du nom de fichier
|
||||
echo "récupération de la vidéo OK " . $url . ". <br>";
|
||||
// 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 "<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' );
|
||||
var_dump( $dir );
|
||||
$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
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
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user