我从麦克风传来一些声音。我需要为其添加声音过滤器,然后将其播放给与该麦克风说话的人。
怎么做这样的事情?
最佳答案
据我所知,这可以通过空气完成:
http://www.adobe.com/devnet/air/flex/articles/using_mic_api.html
这是满足您要求的示例代码:
import flash.media.Sound;
import flash.utils.ByteArray;
protected var soundRecording:ByteArray;
protected var soundOutput:Sound;
protected function playbackData():void
{
soundRecording.position = 0;
soundOutput = new Sound();
soundOutput.addEventListener(SampleDataEvent.SAMPLE_DATA, playSound);
soundOutput.play();
}
private function playSound(soundOutput:SampleDataEvent):void
{
if (!soundRecording.bytesAvailable > 0)
return;
for (var i:int = 0; i < 8192; i++)
{
var sample:Number = 0;
// apply your filter here
if (soundRecording.bytesAvailable > 0)
sample = soundRecording.readFloat();
soundOutput.data.writeFloat(sample);
soundOutput.data.writeFloat(sample);
}
}