1

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.

Mattias
  • 3,907
  • 4
  • 28
  • 50
  • Are you passing a bytearray with data into your encode function? Are you able to include a default silent.mp3 file with your bundled app? If so you could then load this mp3 file and use the mp3's bytearray that has been read in, and write that to a file using filereference. In effect making a copy. Or simply use filereference.copyTo – crooksy88 Dec 15 '11 at 10:49

1 Answers1

0

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.

sanjay
  • 126
  • 1
  • I don´t want to record anything. I want to generate a silent audio file. – Mattias Dec 15 '11 at 12:14
  • there is problem with your metadata code when generate wav file.so, you can refer this code for metadata injection code. – sanjay Dec 17 '11 at 09:20