From fe8e35360d1cd1b77e6a4838e7090ba24755d919 Mon Sep 17 00:00:00 2001 From: boffart <> Date: Wed, 14 Aug 2024 14:48:30 +0300 Subject: [PATCH] =?UTF-8?q?#766=20=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=BC=D0=B5=D0=B4=D0=B8=D0=B0=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lib/System/ConvertAudioFileAction.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/PBXCoreREST/Lib/System/ConvertAudioFileAction.php b/src/PBXCoreREST/Lib/System/ConvertAudioFileAction.php index 0aa008b79..e1e052ade 100644 --- a/src/PBXCoreREST/Lib/System/ConvertAudioFileAction.php +++ b/src/PBXCoreREST/Lib/System/ConvertAudioFileAction.php @@ -39,6 +39,7 @@ public static function main(string $filename): PBXApiResult { $res = new PBXApiResult(); $res->processor = __METHOD__; + $res->success = true; if (!file_exists($filename)) { $res->success = false; $res->messages[] = "File '$filename' not found."; @@ -60,16 +61,23 @@ public static function main(string $filename): PBXApiResult // Convert file to wav format $tmp_filename = escapeshellcmd($tmp_filename); - $n_filename = escapeshellcmd($n_filename); $soxPath = Util::which('sox'); - - // Предварительная конвертация в wav. - Processes::mwExec("$soxPath -v 0.99 -G '$n_filename' -c 1 -r 8000 -b 16 '$n_filename'", $out); + $soxIPath = Util::which('soxi'); + $busyBoxPath = Util::which('busybox'); + // Pre-conversion to wav step 1. + if(Processes::mwExec("$soxIPath $tmp_filename | $busyBoxPath grep MPEG") === 0){ + Processes::mwExec("$soxPath $tmp_filename $tmp_filename.wav", $out); + unlink($tmp_filename); + $tmp_filename = "$tmp_filename.wav"; + } + $n_filename = escapeshellcmd($n_filename); + // Pre-conversion to wav step 2. + Processes::mwExec("$soxPath -v 0.99 -G '$tmp_filename' -c 1 -r 8000 -b 16 '$n_filename'", $out); $result_str = implode('', $out); // Convert wav file to mp3 format $lamePath = Util::which('lame'); - Processes::mwExec("$lamePath -b 32 --silent '$n_filename' '$n_filename_mp3'", $out); + Processes::mwExec("$lamePath -b 16 --silent '$n_filename' '$n_filename_mp3'", $out); $result_mp3 = implode('', $out); // Convert the file to various codecs using Asterisk @@ -79,7 +87,7 @@ public static function main(string $filename): PBXApiResult foreach ($codecs as $codec){ $result = shell_exec("$asteriskPath -rx 'file convert $tmp_filename $trimmedFileName.$codec'"); if(strpos($result, 'Converted') !== 0){ - shell_exec("$rmPath -rf /root/test.$codec"); + shell_exec("$rmPath -rf $trimmedFileName.$codec"); } }