使用 byteArray 和 Adobe Air 生成 x 秒静音音频文件
我想使用 ByteArray
在 Adobe
Air 中生成声音。声音应该是 x 秒的沉默。我找到了用于生成字节的代码:
private function encode(data : ByteArray) : ByteArray
{
var channels : uint = 2;
var bits : uint = 16;
var rate : uint = 44100;
var bytes : ByteArray = new ByteArray();
bytes.endian = Endian.LITTLE_ENDIAN;
bytes.writeUTFBytes('RIFF');
bytes.writeInt(uint(data.length + 44));
bytes.writeUTFBytes('WAVE');
bytes.writeUTFBytes('fmt ');
bytes.writeInt(uint(16));
bytes.writeShort(uint(1));
bytes.writeShort(channels);
bytes.writeInt(rate);
bytes.writeInt(uint(rate * channels * (bits / 8)));
bytes.writeShort(uint(channels * (bits / 8)));
bytes.writeShort(bits);
bytes.writeUTFBytes('data');
bytes.writeInt(data.length);
bytes.writeBytes(data);
bytes.position = 0;
return bytes;
}
但是当我使用 Filereference 保存文件并将其导入 Flash 文件时,我收到一条错误消息,指出读取文件时出现问题。
I would like to generate a sound in Adobe
Air using ByteArray
. The sound should be a silence of x seconds. I found this code that I am using to generate the bytes:
private function encode(data : ByteArray) : ByteArray
{
var channels : uint = 2;
var bits : uint = 16;
var rate : uint = 44100;
var bytes : ByteArray = new ByteArray();
bytes.endian = Endian.LITTLE_ENDIAN;
bytes.writeUTFBytes('RIFF');
bytes.writeInt(uint(data.length + 44));
bytes.writeUTFBytes('WAVE');
bytes.writeUTFBytes('fmt ');
bytes.writeInt(uint(16));
bytes.writeShort(uint(1));
bytes.writeShort(channels);
bytes.writeInt(rate);
bytes.writeInt(uint(rate * channels * (bits / 8)));
bytes.writeShort(uint(channels * (bits / 8)));
bytes.writeShort(bits);
bytes.writeUTFBytes('data');
bytes.writeInt(data.length);
bytes.writeBytes(data);
bytes.position = 0;
return bytes;
}
But when I save the file using Filereference and import it into a flash file I get an error message saying that there were problem reading the file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这个开源库。
http://code.google.com/p/micrecorder/downloads/list
它从麦克风捕获声音并将其保存为 wav 文件。
check out this open source library for it.
http://code.google.com/p/micrecorder/downloads/list
it capture sound from mic and save it as wav file.