简体   繁体   English

如何使用Flash录制语音并保存到PHP

[英]How to record voice using Flash and save to PHP

The following are done work 以下是已完成的工作

Get WAV file => OK 获取WAV文件=>确定

private function renderWav(src, convertToMp3 = false) {
    WaveFile.writeBytesToWavFile(myWavFile, myWavData, 44100, 2, 16)       
}

Convert to MP3 => OK 转换为MP3 =>确定

private function makeIntoMp3(wav) {
    mp3Encoder = new ShineMP3Encoder(wav);
    mp3Encoder.start();
}

save MP3 file to Client => OK 将MP3文件保存到客户端=>确定

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) 上面,我可以在客户端获取MP3文件,但是在我的问题上,该文件保存到服务器端(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 我的PHP代码

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! 我是一名ActionScript新手,不知道哪一部分出错, 感谢您的帮助!

I find the way to solve my problem ( For your reference ) 我找到解决问题的方法(供参考)

// FLASH make MP3 file to server //将MP3文件闪存到服务器

public function makeMP3File() {
  var sba:ByteArray = mp3Encoder.mp3Data;    **//to ByteArray**
  var req:URLRequest = new URLRequest('upload.php');
  req.contentType = 'application/octet-stream';
  req.method = URLRequestMethod.POST;
  req.data = sba;           
  var loader:URLLoader = new URLLoader(req);
}

// PHP server side // PHP服务器端

function strean2audio($name, $spec, $userId=0) {
    $audio_content = file_get_contents("php://input");  **//get RAW POST**
    $file = fopen($audio_file_name . '.mp3', "wb");
    fwrite($file, $audio_content);
    fclose($file);
}

conclusion 结论

recorder.MP3 -> ByteArray -> URLRequest -> URLLoader -> PHP -> ByteArray -> MP3 records.MP3-> ByteArray-> URLRequest-> URLLoader-> PHP-> ByteArray-> MP3

refrence link : Voice Recorder + Server Upload 刷新链接: 录音笔+服务器上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PHP,FLASH录制语音文件 - How to record voice files using PHP, FLASH 如何在浏览器中录制语音并使用php将其保存到.wav文件中? - how to record voice in browser and save it into .wav file using php? 如何从网站录制用户的声音,但没有Flash? - How to record user's voice from the website but without Flash? 如何使用PHP将音频文件从Flash应用保存到服务器? - How to save audio file from flash app to server using php? Flash和PHP库在浏览器中录制声音并保存到.wav文件? - Flash & PHP library to record sound in browser and save to .wav file? 如何保存使用Flash中的MovieClip创建的切换状态。 如何将状态保存到变量中并传递给PHP,然后保存为XML? - How to save a toggle state that is created using a MovieClip in Flash. How to save state in variable and pass to PHP, and save to XML? 如何使用 Twilio 录制语音消息并将语音消息发送到电话号码? - How to record voice message and send the voice message to phone number using Twilio? 如何使用PHP复制mysql行记录并将其以不同的ID保存在同一个表中 - How to copy a mysql row record and save it with different ID in same table using PHP 如何使用PHP复制mysql记录并使用不同的id保存? - How Can i copy a mysql record and save with different id using PHP? 如何使用Flash Form将变量发布到php? - how to post variables to php using Flash Form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM