2

Audio data is saved in the same way as here:

// 1. create AudioRecord instance
// 2. audioTrack.play();

    // 3. in separate thread reading into buffer
    // int bytesRead = audioRecord.read(buffer, 0, bufferSize); 
    // 4. save buffer to file
    // fio.write(buffer, 0 , bytesRead);

// 4. audioTrack.stop();

What codec/format is used as saved file can't be opened as WAV file, but can be read and played using AudioTrack class?

Community
  • 1
  • 1
4ntoine
  • 19,816
  • 21
  • 96
  • 220

2 Answers2

1

No codec is used. It reads raw samples. If you want to save to .wav file you should first write a .wav header to file.Look at this example

sinisha
  • 1,013
  • 13
  • 30
0

No codec is used, if you are looking for some kind of codec, I advise you to try: MediaRecorder

Guilherme Gregores
  • 1,050
  • 2
  • 10
  • 27
  • Thanks for explanation. i can't use MediaRecorder as i have to save into OutputStream and MediaRecorder saved to file only. – 4ntoine Jan 29 '13 at 14:01
  • 1
    @user1103561: Not necessarily. You can pass a `FileDescriptor` to the `setOutputFile` method. That `FileDescriptor` could correspond to e.g. a socket. – Michael Jan 29 '13 at 14:17
  • Great to know. But it still does not allow to output data in a stream (any OutputStream). – 4ntoine Jan 30 '13 at 06:28