0

In Flash as3.0 recorded voice is stored in a BytesArray variable. Now need to store the recorded sound as .mp3 or .wav file in aspx script. Any can help me? How to convert byte array to audio format and save in server any concept please share.

1 Answer 1

2

refer a following my code. this code is skills about after recording your voice to be converted to wav or mp3 to save. converted output mp3 and wav file is is guaranteed about socket communication with the C and Java. I tested in Windows-xp(32bit) Windows7(64bit), MacOSX, Android.

Framework used here is the link.

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your immediate response. However I managed to encode the ByteArray(for mp3), I want to save it from the ASP application (Not from PHP)instead of saving it from the flash application. Do you have any idea to save it using ASP because I am absolutely new to ASP.
Just to let you know, this is the most concise and easy to implement way to save mic data to MP3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.