Skip to content

Commit 0904b36

Browse files
committed
字母转换
1 parent 8ab5e1c commit 0904b36

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"require": {
1616
"reactphp-x/framework-x": "^0.16.0",
17-
"reactphp-x/asyncify": "^1.0"
17+
"reactphp-x/asyncify": "^1.0",
18+
"mantas-done/subtitles": "^1.0"
1819
}
1920
}

src/Tts.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ReactphpX\Asyncify\Asyncify;
88
use React\ChildProcess\Process;
99
use React\Promise\Deferred;
10+
use Done\Subtitles\Subtitles;
1011

1112
class Tts
1213
{
@@ -388,6 +389,8 @@ function ($request) {
388389
$timeFloat = microtime(true);
389390
$f_name = $timeFloat . '.mp3';
390391
$path = $publicPath . $f_name;
392+
$srt = $publicPath . $timeFloat . '.srt';
393+
$vtt = $publicPath . $timeFloat . '.vtt';
391394

392395

393396
$deferred = new Deferred();
@@ -397,7 +400,7 @@ function ($request) {
397400
$isError = false;
398401
// $process = new Process('edge-tts --voice '.$voice.' --text '.$text.' --write-media '. $path);
399402

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);
401404
$process = new Process('exec sh -c '.$command);
402405
$process->start();
403406

@@ -417,9 +420,10 @@ function ($request) {
417420
});
418421

419422

420-
$process->on('exit', function ($exitCode, $termSignal) use (&$isError, $deferred, $timeFloat) {
423+
$process->on('exit', function ($exitCode, $termSignal) use (&$isError, $deferred, $timeFloat, $srt, $vtt) {
421424
// echo 'Process exited with code ' . $exitCode . PHP_EOL;
422425
if (!$isError) {
426+
Subtitles::convert($srt, $vtt);
423427
$deferred->resolve(json_encode([
424428
'filename' => "/voices/$timeFloat.mp3",
425429
'vtt' => "/voices/$timeFloat.vtt"

0 commit comments

Comments
 (0)