Android: Need to record mic input

后端 未结 2 493
余生分开走
余生分开走 2020-11-28 03:06

Is there a way to record mic input in android while it is being process for playback/preview in real time? I tried to use AudioRecord and AudioTrack to do this

2条回答
  •  温柔的废话
    2020-11-28 03:27

    Following permission in manifest is required to work properly:

    
    

    Also, 2d buffer array is not necessary. The logic of the code is valid even with just one buffer, like this:

    short[] buffer = new short[160];
    while (!stopped) {
        //Log.i("Map", "Writing new data to buffer");
        int n = recorder.read(buffer, 0, buffer.length);
        track.write(buffer, 0, n);
    }
    

提交回复
热议问题