7
7
use ReactphpX \Asyncify \Asyncify ;
8
8
use React \ChildProcess \Process ;
9
9
use React \Promise \Deferred ;
10
+ use Done \Subtitles \Subtitles ;
10
11
11
12
class Tts
12
13
{
@@ -388,6 +389,8 @@ function ($request) {
388
389
$ timeFloat = microtime (true );
389
390
$ f_name = $ timeFloat . '.mp3 ' ;
390
391
$ path = $ publicPath . $ f_name ;
392
+ $ srt = $ publicPath . $ timeFloat . '.srt ' ;
393
+ $ vtt = $ publicPath . $ timeFloat . '.vtt ' ;
391
394
392
395
393
396
$ deferred = new Deferred ();
@@ -397,7 +400,7 @@ function ($request) {
397
400
$ isError = false ;
398
401
// $process = new Process('edge-tts --voice '.$voice.' --text '.$text.' --write-media '. $path);
399
402
400
- $ command = escapeshellarg ('edge-tts --voice ' .$ voice .' --text ' .$ text .' --write-media ' . $ path );
403
+ $ command = escapeshellarg ('edge-tts --voice ' .$ voice .' --text ' .$ text .' --write-media ' . $ path . ' --write-subtitles ' . $ srt );
401
404
$ process = new Process ('exec sh -c ' .$ command );
402
405
$ process ->start ();
403
406
@@ -417,9 +420,10 @@ function ($request) {
417
420
});
418
421
419
422
420
- $ process ->on ('exit ' , function ($ exitCode , $ termSignal ) use (&$ isError , $ deferred , $ timeFloat ) {
423
+ $ process ->on ('exit ' , function ($ exitCode , $ termSignal ) use (&$ isError , $ deferred , $ timeFloat, $ srt , $ vtt ) {
421
424
// echo 'Process exited with code ' . $exitCode . PHP_EOL;
422
425
if (!$ isError ) {
426
+ Subtitles::convert ($ srt , $ vtt );
423
427
$ deferred ->resolve (json_encode ([
424
428
'filename ' => "/voices/ $ timeFloat.mp3 " ,
425
429
'vtt ' => "/voices/ $ timeFloat.vtt "
0 commit comments