5

I'm trying to record audio using the glass gdk and am finding it quite problematic.

I'm using media recorder and have all the right permissions, but I keep getting media recorder 100 errors. My code looks something like this:

mMediaRecorder = new MediaRecorder();
mMediaRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {
            public void onError(MediaRecorder mediarecorder1, int k, int i1) {
                Log.e(TAG, String.format("Media Recorder error: k=%d, i1=%d", k, i1));
            }
});
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setOutputFile(mAudioFile.getAbsolutePath());

mMediaRecorder.prepare();
mMediaRecorder.start();

This has to be something to do with the Google Glass as I have run the exact same code on an android phone and it recorded audio correctly. I can find very few resources about using media recorder to only record audio on glass, most posts I have seen are people recording video and audio, whilst I am not interested in video.

Any help working out how I can recorder audio on Google Glass would be greatly appreciated!

WillEllis
  • 489
  • 4
  • 14

1 Answers1

2
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

I just tested this in an immersive activity targeting the latest GDK on an XE22 Glass. What I saw with your original code was a bunch of native logcat messages suggesting codec issues. This combination of codec and container does work and I was able to retrieve the audio file and play it back on my notebook.

Jeffrey Mixon
  • 12,846
  • 4
  • 32
  • 55
  • I had noticed I could get it to record in AAC, however I am trying to record in AMR. Whats strange is here: https://code.google.com/p/google-glass-api/issues/detail?id=317 one of the developers posts that AMR is the default encoder. What I'm trying to work out is why that doesnt work. – WillEllis Nov 04 '14 at 12:03
  • It may be that now they only support AAC on glass, in which case your answer is correct. I'd be very interested to know though if anyone has worked out how to record in AMR – WillEllis Nov 04 '14 at 12:06
  • I understand, although your question was "how to record audio" on the Glass, not necessarily only in AMR format. Although AMR should work on Glass per the spec, it rarely holds up even on other Android devices. See [this post](http://stackoverflow.com/questions/12362918/android-reliable-audio-recording-all-devices) as an example. Lack of AMR encoding on Glass is either a bug or an undocumented limitation, imo. – Jeffrey Mixon Nov 04 '14 at 15:57