Recording Sound and Playing it Back on Android

What is the correct way for recording audio and playing it back when on an Android device? Our application (SparkleFish) records sounds and then plays them back using the Audio library. It works great for iOS.

On an Android device, I cannot figure out how to play the sound back. I’ve tried both event sounds and the audio library.

Also, based on the documentation, I can’t find a case where you can play back what was recorded on an Android device. It looks like recording can produce a .raw (i.e. pcm) file or a .3gp file. However, the audio library only plays back .mp3 and .ogg for Android according to the docs. I have no idea what the event sound playback support is. I couldn’t tell from reading the documentation.

Finally, I tried building and running the SimpleAudioRecorder sample on my Droid 2 and it does not playback recorded sound either.

Any ideas are greatly appreciated. At this point, SparkleFish for Android is blocked.

Thanks,
Paul Osburn [import]uid: 7101 topic_id: 11995 reply_id: 311995[/import]

Hello Paul,

You are correct that Corona’s audio API does not support the audio format recorded by Android, such as 3GP. However, Corona’s media.playSound() function is capable of playing these recorded files on Android. Please use media.playSound() instead on Android.

In the future, we’d like to change the recorded audio format to WAV so that our audio API can play it, but at the moment this is our only work-around. [import]uid: 32256 topic_id: 11995 reply_id: 44448[/import]

so we can’t record a sound on android and play it back? Only pre-saved files in wav format? [import]uid: 13784 topic_id: 11995 reply_id: 47358[/import]

@marble68: You can record files on Android and play it back using media.playSound and the .3gp file extension (thanks Joshua!).

What I was doing wrong was trying to use media.playEventSound. It doesn’t work with that call.

In our app, where we need to play a lot of sounds back to back, I’m hoping I can use playEventSound for the pre-recorded sounds so I can load them into memory before I start playback. Then I’m hoping to use playSound to load the next recorded sound into memory and pause it before it plays back. That way I can get it ready when I need it. We’ll see how things work. :slight_smile:
paul [import]uid: 7101 topic_id: 11995 reply_id: 47366[/import]

Recording and playback work using media.playSound. However, the volume of the recorded sound is low. I’m not sure if this is common across all Android devices or just the Droid 2 and Droid x I’ve tested on.

Unless you put your mouth right next to the mic, the recorded sound is pretty low. The mic on the iOS devices is much better and able to come up with a nice level for the recorded sound even when you’re not right next to the mic. So, either the recorded sound is really loud or really low. Ugh.

Is there a way to adjust the recording volume on the Android? I don’t think there is but I just wanted to check. I think this definitely kills the Android version of our app, unfortunately. I don’t want to release a version of our app that is sub-standard.

Thanks,
Paul [import]uid: 7101 topic_id: 11995 reply_id: 53429[/import]

Hello Paul,

As far as I’ve seen, Android does not allow developers to control the microphone volume. However, you “can” control the volume of audio playback, which I hope is where the real issue is. Try this in Corona…
– 0 = mute; 1 = loudest.
media.setSoundVolume(1)

This is documented here…
http://developer.anscamobile.com/reference/index/mediasetsoundvolume

[import]uid: 32256 topic_id: 11995 reply_id: 53438[/import]

Hi Joshua:

Thanks for the reply.

We have playback volume set to the loudest already. The main issue appears to be that the user must be very close to the mic on android phones (at least the droids we’ve tested on) for playback to be at all audible. When they’re extremely close to the mic, playback is fine. There is very little leeway in how close they can or cannot be.

The only thing I can think of right now is having them hold the phone and talk into it like they’re on a call. That makes the UI tricky and not very user friendly. In our app right now (SparkleFish), we have the user press and hold a microphone graphic on the screen while recording. This works great for iOS devices. Their mouth does not need to be that close to the mic and we get a pretty consistent volume level.

If they need to hold the phone like they’re making a call just to record a word, we’ll need to come up with a different UX interaction for recording. Additionally, the user will need flip the phone back and forth from looking at the screen and talking on it for each word they record. That just seems more trouble than it’s worth to me. I don’t really want to release an application that I feel is sub-standard and not a good experience.

I think that would be bad for us and not so great for Ansca.

paul
[import]uid: 7101 topic_id: 11995 reply_id: 53616[/import]

Hi Paul,

I’m thinking that some Android devices have better microphones than others. Perhaps the thing to do is show live feedback in your UI to indicate to the user that sound is being picked up. Have a look at the Corona SDK’s “Media\SimpleTuner” sample app on how to do this as audio is streaming in.

EDIT: I just noticed that our SimpleTuner app does not work on Android. Corona has a bug where the streamed in audio input is passed to Lua with the byte order reversed… but only on Android. Bummer. I guess this idea is out until we fix this. [import]uid: 32256 topic_id: 11995 reply_id: 53637[/import]