mirror of
https://github.com/ggerganov/ggwave.git
synced 2026-03-18 09:06:07 +08:00
ggwave-to-file : http service now produces mp3 files
The .wav files could not play on most Apple software
This commit is contained in:
@@ -8,10 +8,15 @@ if (isset($_GET['p'])) { $cmd .= " -p".intval($_GET['p']); }
|
|||||||
|
|
||||||
$descriptorspec = array(
|
$descriptorspec = array(
|
||||||
0 => array("pipe", "r"),
|
0 => array("pipe", "r"),
|
||||||
1 => array("pipe", "w"),
|
//1 => array("pipe", "w"),
|
||||||
2 => array("pipe", "w"),
|
2 => array("pipe", "w"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$path_wav = tempnam("/tmp", "ggwave");
|
||||||
|
$path_mp3 = $path_wav.".mp3";
|
||||||
|
|
||||||
|
$cmd .= " > $path_wav";
|
||||||
|
|
||||||
$process = proc_open($cmd, $descriptorspec, $pipes);
|
$process = proc_open($cmd, $descriptorspec, $pipes);
|
||||||
|
|
||||||
if (is_resource($process)) {
|
if (is_resource($process)) {
|
||||||
@@ -20,24 +25,36 @@ if (is_resource($process)) {
|
|||||||
fwrite($pipes[0], $message);
|
fwrite($pipes[0], $message);
|
||||||
fclose($pipes[0]);
|
fclose($pipes[0]);
|
||||||
|
|
||||||
$result = stream_get_contents($pipes[1]);
|
//$result = stream_get_contents($pipes[1]);
|
||||||
fclose($pipes[1]);
|
//fclose($pipes[1]);
|
||||||
|
|
||||||
$log = stream_get_contents($pipes[2]);
|
$log = stream_get_contents($pipes[2]);
|
||||||
fclose($pipes[2]);
|
fclose($pipes[2]);
|
||||||
|
|
||||||
$return_value = proc_close($process);
|
$return_value = proc_close($process);
|
||||||
|
|
||||||
if (strlen($result) == 0) {
|
exec("ffmpeg -i ".$path_wav." ".$path_mp3);
|
||||||
|
|
||||||
|
$result = file_get_contents($path_mp3);
|
||||||
|
$size = filesize($path_mp3);
|
||||||
|
|
||||||
|
if ($size == 0) {
|
||||||
header('Content-type: text/plain');
|
header('Content-type: text/plain');
|
||||||
echo $log;
|
echo $log;
|
||||||
} else {
|
} else {
|
||||||
header('Content-Disposition: attachment; filename="output.wav"');
|
//header("Content-Type: audio/wav");
|
||||||
|
header("Content-Type: ". mime_content_type($path_mp3));
|
||||||
|
header("Content-Length: $size");
|
||||||
|
header("Accept-Ranges: bytes");
|
||||||
|
header('Content-Disposition: inline; filename="output.wav"');
|
||||||
header("Content-Transfer-Encoding: binary");
|
header("Content-Transfer-Encoding: binary");
|
||||||
header("Content-Type: audio/wav");
|
header("Content-Range: bytes 0-".$size."/".$size);
|
||||||
|
|
||||||
echo $result;
|
echo $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlink($path_mp3);
|
||||||
|
unlink($path_wav);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user