Friday, 30 August 2013

How to record voice using Flash and save to PHP

How to record voice using Flash and save to PHP

The following are done work

Get WAV file => OK
private function renderWav(src, convertToMp3 = false) {
WaveFile.writeBytesToWavFile(myWavFile, myWavData, 44100, 2, 16)
}
Convert to MP3 => OK
private function makeIntoMp3(wav) {
mp3Encoder = new ShineMP3Encoder(wav);
mp3Encoder.start();
}
save MP3 file to Client => OK
private function onWavClick(e:MouseEvent) {
new FileReference().save(mp3Encoder.mp3Data, "MyAudio.mp3");
}
Above, I can get a MP3 file in client side but on my problem that save to
Server side(PHP)
Save to server side => Fail
public function makeMP3File() {
var urlVariables:URLVariables = new URLVariables;
urlVariables.mp3Data = mp3Encoder.mp3Data;
var req:URLRequest = new URLRequest('upload.php');
req.data = urlVariables;
req.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(req);
}
My PHP Code
function strean2audio($audioStream, $filename)
{
$file = fopen($filename . '.mp3', "wb");
fwrite($file, $audioStream);
fclose($file);
}
I was a ActionScript rookie, don't know which part error, thanks for your
help!

No comments:

Post a Comment