0

在 Flash as3.0 中,录制的语音存储在一个 BytesArray 变量中。现在需要将录制的声音存储为 .mp3 或 .wav 文件在 aspx 脚本中。任何可以帮助我?如何将字节数组转换为音频格式并将任何概念保存在服务器中,请分享。

4

1 回答 1

2

请参考我的代码。此代码是关于在录制您的声音后转换为 wav 或 mp3 保存的技能。转换后的输出 mp3 和 wav 文件保证了与 C 和 Java 的套接字通信。我在 Windows-xp(32bit) Windows7(64bit)、MacOSX、Android 中进行了测试。

这里使用的框架是链接。

WAVWriter: WAVWriter

ShineMP3Encoder: ShineMP3Encoder

import com.adobe.audio.format.WAVWriter;
import fr.kikko.lab.ShineMP3Encoder;
import flash.events.SampleDataEvent;
import flash.media.Microphone;
import flash.media.Sound;
import flash.utils.ByteArray;
import flash.events.Event;

var mp3encoder:ShineMP3Encoder;
var microphone:Microphone;
var isRecording:Boolean=false;
var soundRecording:ByteArray;

function startMicRecording():void 
{
    isRecording=true;
    soundRecording = new ByteArray();
    microphone=Microphone.getMicrophone();
    microphone.rate=44;
    microphone.addEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
}

function stopMicRecording():void {

    isRecording=false;
    microphone.removeEventListener(SampleDataEvent.SAMPLE_DATA, gotMicData);
    soundRecording.position=0;

    convert2MP3();
}


function gotMicData(micData:SampleDataEvent):void 
{
    soundRecording.writeBytes(micData.data);
}

function convert2MP3():void
{
    var wavWrite:WAVWriter = new WAVWriter();
    wavWrite.numOfChannels=1;
    wavWrite.sampleBitRate=16;
    wavWrite.samplingRate=44100;

    var wav:ByteArray = new ByteArray();

    wavWrite.processSamples(wav, soundRecording, 44100,1);
    wav.position=0;

    /* 
     If the process is compressed into mp3 if you have big problems, 
     just as .wav format save. following code: 
     var file:FileReference = new FileReference();
     file.save(wav,"your_file_name.wav");
    */

    mp3encoder=new ShineMP3Encoder(wav);
    mp3encoder.addEventListener(Event.COMPLETE, onEncoded);
    mp3encoder.start();
}

function onEncoded(e:Event):void 
{
    mp3encoder.mp3Data.position=0;
    mp3encoder.saveAs("your_file_name.mp3");
}

startMicRecording();
于 2012-08-14T13:38:00.733 回答