2

My question is partially answered by this: Which audio format can be recorded and played back by iPhone and Android?

However, I'd like to ask further, if possible.

The simplified use-case is this: a client app (which will be either iPhone or Android) will record audio via the built-in mic. This audio will then be sent to a server. From the same client app, the user can see a list of recorded audio files and streamed back for playback.

I'm trying to see what would be the best audio format for the recording and streamed playback.

I have two questions:

1) From the link I gave above, it seems that both iPhone and Android support AAC for recording. However, I'm confused about the variants of AAC. Android seems to support AAC ADTS, whereas the iPhone something different (MPEG-4). Are these the same?

2) I was hoping to be able to record in the same format on both iPhone/Android so that they can be streamed as-is to the client devices. However, if transcoding on the server is a better option, what would be the preferred format for that?

Thank you in advance!

Community
  • 1
  • 1
kurisukun
  • 3,149
  • 5
  • 37
  • 69

1 Answers1

3

In the end, on iOS, I ended up using

NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:

                                [NSNumber numberWithInt:kAudioFormatMPEG4AAC], AVFormatIDKey,                                    
                                [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
                                [NSNumber numberWithInt:16], AVEncoderBitRateKey,
                                [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                                [NSNumber numberWithFloat:16000.0], AVSampleRateKey,
                                nil];

and on Android:

_mediaRecorder = new MediaRecorder();
_mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
_mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
_mediaRecorder.setOutputFile(_mediaFile.getAbsolutePath());
_mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

And the resulting files were AAC files were playable on both iOS and Android. Hope that helps!

kurisukun
  • 3,149
  • 5
  • 37
  • 69
  • Thanks a lot. I am trying the android code. I have 2 android devices. From one device, it works well. From the other device, it only records 0 byte files. Any idea if this is some version specific issue? – ambit Nov 22 '13 at 10:35
  • Perhaps it's a permissions issue with regards to where you're writing the audio file to? – kurisukun Nov 22 '13 at 13:01
  • I was earlier using the same code. But just the setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); line instead of AAC_ADTS. The recording worked well but I changed it to get over the compatibility issues with iphone. So, it might not be a storage related issue. Anyway, let me know if you think of anything. – ambit Nov 22 '13 at 13:27
  • I have also posted a question for the same http://stackoverflow.com/questions/20146510/android-audio-recording-issue-with-mediarecorder-outputformat-aac-adts – ambit Nov 22 '13 at 13:51