切割的声音在ActionScript声音、ActionScript

2023-09-08 15:16:49 作者:璃沫寧夏

我知道如何在ActionScript 3录制音频但有可能削减远离最后的声音文件在什么动作?

我的使用情况是,该用户可以跳转到在声音文件中的特定点(ⅰ可以管理),并从那里开始录制(基本上覆盖该文件的其余部分)。

这是可能在ActionScript 3,如果是,如何?

感谢你。

更新:

这是在code我用,和它的作品,但旧的记录被一头栽倒。我不知道为什么。 selectedTime是在波的图形重新presentation用户所选择的时间一毫秒值; 44100是我的采样率。

  existingByte =新的ByteArray();
VAR提取物:数= Math.floor((selectedTime)* 44.1);
sound.extract(existingByte,提取);

mic.recordData(existingByte);

//在MIC类:
公共职能recordData(existingByteArray:的ByteArray = NULL):无效{
    如果(existingByteArray == NULL){
        原料=新的ByteArray();
    } 其他 {
        原料= existingByteArray;
        raw.position = raw.length;
    }
    mic.addEventListener(的SampleDataEvent.SAMPLE_DATA,DataHandler的);
}

私有函数的DataHandler(事件:的SampleDataEvent):无效{
    尝试 {
        raw.writeBytes(event.data);
    }赶上(五){
        this.sto precording();
    }
}
 
声音ActionScript的编写与控制 动画媒体

解决方案

是的。当你从音频接收字节流要附加到这些主缓冲区。如果你想要做的一记重拳,在这样的记录。你需要知道偏移量,你想冲到主缓冲区。而不是写从一开始的缓冲区,这样,你会写从偏移用户点击的缓冲区。你必须将鼠标指针涉及到一个在你的主缓冲区偏移。然后,当你收到新的音频简单地覆盖在缓冲区中的值。如果你想有一个穿出来,因此只覆盖了音频的一小部分。你需要在主缓冲区,停止写入新的数据,以及一个终点。用户可以突出的音频部分获得输入/输出点说。

您将不得不使用的ByteArray两个缓冲区。您可以提取声音使用Sound.extract的原始字节()。对原始音频其他来源可以在这里应用,以及:

  VAR主:ByteArray的; //假设这是加载一些音频

公共职能punchIn(startLocation:指数,声:声音):无效{
    sound.extract(主,sound.bytesTotal,startLocation);
}
 

通过改变长度参数,你可以做一个冲头和冲出来的功能。

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:

var master : ByteArray;  // assume this is loaded with some audio

public function punchIn( startLocation : index, sound : Sound ) : void {
    sound.extract( master, sound.bytesTotal, startLocation );
}

By varying the length parameter you could do a punch in and punch out feature.