Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active December 15, 2015 10:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xeoncross/5246960 to your computer and use it in GitHub Desktop.
Save xeoncross/5246960 to your computer and use it in GitHub Desktop.
Record audio from flash to MP3 using PHP
<?php
// https://code.google.com/p/wami-recorder/
# Save the audio to a URL-accessible directory for playback.
parse_str($_SERVER['QUERY_STRING'], $params);
$name = isset($params['name']) ? $params['name'] : 'output.wav';
$content = file_get_contents('php://input');
$fh = fopen($name, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
unlink('output.mp3'); // FFMPEG won't overwrite existing files by default
// FFMPEG ignors our BITRATE if the Hz is wrong
//$commandOutput = shell_exec('ffmpeg -i output.wav output.mp3 -acodec libmp3lame -b 32k -ab 32k -b:a 32k');
//$commandOutput = shell_exec('ffmpeg -i output.wav -acodec libmp3lame -b:a 8k -ac 1 -ar 11025 output.mp3');
//$commandOutput = shell_exec('ffmpeg -i output.wav -acodec libmp3lame -b:a 8k -ac 1 -ar 8000 output.mp3');
$commandOutput = shell_exec('ffmpeg -i output.wav -acodec libmp3lame -ab 24k -b:a 24k -ac 1 -ar 11025 output.mp3');
file_put_contents('log.txt', $commandOutput);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment