我正在将Adobe AIR与ActionScript3配合使用,以播放从iOS设备上的麦克风录制的声音。
我使用FileStream.writeFloat方法将麦克风样本(单声道)存储在文件中。
稍后我创建一个Sound对象并注册到SampleEvent,在SampleEvent中,我读取了之前与麦克风采样一起存储的文件,并将它们写入两次(因为输出是立体声)。
问题是,当我在AIR模拟器中运行它时,它可以很好地工作并可以重播声音,而当我在iOS设备(iPad)上播放时,声音的运行速度是后者的两倍。
private function onSampleData(event : SampleDataEvent):void
{
// the following lines of code are modifying the sound object and creates a "pitch" effect
var sample:Number;
var outputLength:int = 0;
while (outputLength < 2048) {
// until we have filled up enough output buffer
if (_micSamplesStream.bytesAvailable < 4)
{
break;
}
// read out the left and right channels at this position
sample = _micSamplesStream.readFloat();
// write the samples to our output buffer
event.data.writeFloat(sample);
event.data.writeFloat(sample);
outputLength++;
}
}
最佳答案
我已经将应用程序构建为临时包,并使用TestFlight将其安装在iPad上,现在一切似乎都可以正常工作。
我猜在调试期间,Adobe AIR未能足够快地填充声音缓冲区并导致失真。
关于ios - 在iOS上使用ActionScript3播放声音会导致不良效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23325044/