I know how to record audio in actionscript 3. But is it possible to cut away something from the final sound file in actionscript?
My use case is, that the user can jump to a specific point in the sound file (i can manage that) and start recording from there (essentially overwriting the rest of the file).
Is this possible in actionscript 3. If yes, how?
Thank you.
UPDATE:
This is the code I’ve used, and it works, but the old recording gets pitched down. I don’t know why. “selectedTime” is a millisecond value of a time the user selected in a graphical representation of the wave; 44100 is my sample rate.
existingByte = new ByteArray();
var extract:Number = Math.floor ((selectedTime)*44.1);
sound.extract(existingByte, extract);
mic.recordData(existingByte);
// in the mic class:
public function recordData(existingByteArray:ByteArray=null):void {
if(existingByteArray == null) {
raw = new ByteArray();
} else {
raw = existingByteArray;
raw.position = raw.length;
}
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, dataHandler);
}
private function dataHandler(event:SampleDataEvent):void {
try {
raw.writeBytes(event.data);
} catch(e) {
this.stopRecording();
}
}
Yes. As you are receiving bytes in from the audio stream you are appending those into the master buffer. If you want to do a punch-in like recording. You’ll need to know the offset into the master buffer where you want to punch into. So instead of writing to the buffer from the start, you’d write to the buffer from the offset the user clicked. You’ll have to relate the mouse pointer to an offset in your master buffer. Then as you receive new audio simply overwrite the values in that buffer. If you want a punch-out so it only overwrites a small section of the audio. You’ll need a end point in the master buffer where to stop writing new data as well. The user could highlight a section of the audio to get in/out points say.
You’ll have to use ByteArrays for the two buffers. You can extract the raw bytes from Sound using Sound.extract(). Other sources of raw audio can be applied here as well:
By varying the length parameter you could do a punch in and punch out feature.