forked from SimplesIP/pabx-app
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
#!/usr/bin/php -q |
|
<?php |
|
$arquivo = $argv[1]; |
|
|
|
if($arquivo){ |
|
$file = explode('/', $arquivo); |
|
$file = $file[count($file) - 1]; |
|
DownloadAudio($file, $arquivo, 'mp3'); |
|
} |
|
|
|
function DownloadAudioAlgar($file, $filepath, $tipo = 'wav', $protocolo = '', $dataAudio = '') { |
|
ob_clean(); |
|
$isMp3 = (strtolower($tipo) == 'mp3'); |
|
|
|
/* |
|
* Renomeia com o protocolo da chamada. |
|
*/ |
|
$file = $protocolo ? $protocolo . '_' . $dataAudio . "." . strtoupper($tipo) : $file; |
|
|
|
if ($isMp3) { |
|
$dirMp3 = '/var/www/html/aplicativo/audio/'; |
|
$pathFileWav = sprintf("%s%s", $dirMp3, $file); |
|
$patFileMp3 = str_ireplace('.WAV', '.MP3', $pathFileWav); |
|
|
|
/* |
|
* Renomeia o file para mostrar corretamente. |
|
*/ |
|
$file = str_ireplace('.WAV', '.MP3', $file); |
|
|
|
/* |
|
* Cria o arquivo wav localmente. |
|
*/ |
|
@file_put_contents($pathFileWav, @file_get_contents($filepath)); |
|
|
|
/* |
|
* Convert para mp3. |
|
*/ |
|
ConvertToMp3($pathFileWav, $patFileMp3); |
|
|
|
/* |
|
* Pega o tamanho do arquivo mp3 criado. |
|
*/ |
|
$fsize = filesize($patFileMp3); |
|
|
|
header('Content-Description: File Transfer'); |
|
header('Content-Transfer-Encoding: binary'); |
|
header('Content-Type: mpeg'); |
|
if ($fsize) |
|
header('Content-Length: ' . $fsize); |
|
header('Content-Disposition: attachment; filename="' . $file . '"'); |
|
header('Connection: close'); |
|
readfile($patFileMp3); |
|
unlink($pathFileWav); |
|
unlink($patFileMp3); |
|
exit; |
|
} |
|
} |
|
|
|
function ConvertToMp3($fileOrig, $fileDest) { |
|
$cmd = sprintf("ffmpeg -y -i %s -acodec libmp3lame %s", $fileOrig, $fileDest); |
|
exec($cmd); |
|
} |
|
|