Talking App like talking tom, Audio Recording didn't work on all devices Talking App like talking tom, Audio Recording didn't work on all devices android android

Talking App like talking tom, Audio Recording didn't work on all devices


If you force an arbitrary sample rate on a device wich doesen't support it, you are going to have troubles.

I suggest you to check and set a valid sample-rate for the running device (instead of hardcoding it to 44.1Khz).

Take a look here for some hints about how to check available sample-rates.


Put this code to check whether the samplerate and audio format supported in your device . Check the combination and see which one is working for you

private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 };    for (int rate : mSampleRates) {                for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT,AudioFormat.ENCODING_PCM_16BIT }) {                    for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO }) {                        try {                            Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "                                    + channelConfig);                            int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);                            if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {                                Log.d(TAG, "Found rate " + rate + "Hz, bits: " + audioFormat + ", channel: "                                        + channelConfig);                      Log.d(TAG, "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: "                                    + channelConfig +" supported");                            }                        } catch (Exception e) {                            Log.e(TAG, rate + "Exception, keep trying.",e);                        }                    }                }            }


The code doesn't really check for error cases making it much harder to figure out what going wrong on those devices.Please do the following:

  1. Not related to the recording (but the playback) but it's better if you take care of the AudioFocus.. it might be lost and etc. All yop need to know is here http://developer.android.com/training/managing-audio/audio-focus.html
  2. Add calls to AudioRecord.getState() to verify the state
  3. Add calls to AudioRecord.getRecordingState () to verify the recording state
  4. In getMinBufferSize you need to check against ERROR_BAD_VALUE
  5. In the read calls you need to check against ERROR_INVALID_OPERATION and ERROR_BAD_VALUE
  6. You can use setRecordPositionUpdateListener to tell if the recording has progressed.

These steps + observing the system logcat will put you in a much better place to pinpoint the issue or provide us with the info to solve the problem