3

Im using MediaRecorder on an android project, to record video and audio files. it records correctly but the sound volume on both files is very very low.

I use this to configure MediaRecorder to record audio

String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
                    File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + ConfigApp.RECORDINGS_FOLDER);
                    if (!folder.exists())
                        success = folder.mkdir();
                    if (success) {
                        mFileName = folder + timeStamp + ".m4a";
                        currentFile = mFileName;
                        chrono.setBase(SystemClock.elapsedRealtime());
                        chrono.start();
                        mRecorder = new MediaRecorder();
                        mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
                        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                        mRecorder.setOutputFile(mFileName);
                        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


                        try {
                            mRecorder.prepare();
                        } catch (IOException e) {
                            Log.e(TAG, "prepare() failed");
                        }
                        mRecorder.start();
                        handler.post(updateVisualizer);
                    }

and this when i record video

// BEGIN_INCLUDE (configure_preview)
    mCamera = CameraHelper.getDefaultCameraInstance();
    // We need to make sure that our preview and recording video size are supported by the
    // camera. Query camera to find all the sizes and choose the optimal size given the
    // dimensions of our preview surface.
    Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
    Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes,
            mSurfaceView.getWidth(), mSurfaceView.getHeight());

    // Use the same size for recording profile.
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    profile.videoFrameWidth = optimalSize.width;
    profile.videoFrameHeight = optimalSize.height;

    // likewise for the camera object itself.
    parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mCamera.setParameters(parameters);
    try {
        // Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
        // with {@link SurfaceView}
        mCamera.setPreviewDisplay(mSurfaceView.getHolder());
        mCamera.setDisplayOrientation(90);

    } catch (IOException e) {
        Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
        return false;
    }
    // END_INCLUDE (configure_preview)


    // BEGIN_INCLUDE (configure_media_recorder)
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);

    // Step 2: Set sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER );
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    mMediaRecorder.setProfile(profile);

    // Step 4: Set output file
    String path  = getVideoFile(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO).getAbsolutePath();
    currentFile = path;
    mMediaRecorder.setOutputFile(path);
    mMediaRecorder.setOrientationHint(270);

    // END_INCLUDE (configure_media_recorder)

    // Step 5: Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;

i tried other options on setAudioSource besides the AudioSource.CAMCORDER but i always get low volume

do i need to configure any extra parameters?

Thought
  • 5,326
  • 7
  • 33
  • 69

2 Answers2

1

I had the same problem while using MediaRecorder and finally figured out the correct working solution. Here are few modifications you need to do for good quality audio recordings: mRecorder.setAudioEncodingBitRate(16*44100); mRecorder.setAudioSamplingRate(44100); Many solutions on stackoverflow would suggest .setAudioEncodingBiteRate(16) but 16 is too low to be considered meaningless .

Source: @Grant answer on stackoverflow very poor quality of audio recorded on my droidx using MediaRecorder, why?

Hissaan Ali
  • 2,229
  • 4
  • 25
  • 51
0

Try to

mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

then, Your AudioSource set to MIC.

  • The original recording voice app or camcoder app is fine? – Koo SungMin May 03 '16 at 00:33
  • sorry, but i just sharing my experience. And need to say do check the hardware. i was developed voice tracking app. so i was had same difficult. And try change setAudioSource option is ok. – Koo SungMin May 03 '16 at 00:47