Android AudioRecord which settings to record call

前端 未结 3 1595
后悔当初
后悔当初 2020-12-31 14:13

I use AudioRecord class to record the voice during a call.

I am intererested to record only the voice of the person who owns the phone ( from the microphone). Durin

相关标签:
3条回答
  • 2020-12-31 14:27

    A bit late but you can query the audio device to find out what it can do;

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    String sampleRate =  audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
    String sampleBufferSize = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
    int bufferSize = AudioRecord.getMinBufferSize(Integer.parseInt(sampleRate), AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
    
    0 讨论(0)
  • 2020-12-31 14:29

    You should always aim to use 44100 as sample rate since it is the only sample rate that is guaranteed to work according to google.

    "the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices." Dev site

    As for stereo versus mono, use mono.

    "describes the configuration of the audio channels. See CHANNEL_IN_MONO and CHANNEL_IN_STEREO. CHANNEL_IN_MONO is guaranteed to work on all devices." Dev site

    Finally: 8bit pcm vs 16bit pcm: Use 16bit pcm,

    "Audio data format: PCM 16 bit per sample. Guaranteed to be supported by devices." Dev site

    Just remember to use a short[] buffer instead of byte buffer when using 16bit. Since 16bit is 2 bytes you will have to combine two entries in the buffer at a time:

    byte][]{sample_1_upper, sample_1_lower, sample_2_upper, sample_2_lower,...,sample_n_lower} However if you'll use a short[]buffer:
    short[]{sample1, sample2, ..., sample3}

    I've never tried to record a call, but if the OS doesn't bind the MIC source you could probably record from it. Since you're recording from the microphone you should only get the users voice.

    0 讨论(0)
  • 2020-12-31 14:35

    Can you explain what is the differences among them. Ok MIC is obvious but VOICE_CALL vs VOICE_UPLINK vs VOICE_DOWNLINK ?

    VOICE_UPLINK: The audio transmitted from your end to the other party. IOW, what you speak into the microphone (plus surrounding noise depending on whether noise suppression is used and how well it performs).

    VOICE_DOWNLINK: The audio transmitted from the other party to your end.

    VOICE_CALL: VOICE_UPLINK + VOICE_DOWNLINK.

    0 讨论(0)
提交回复
热议问题