3

I'm trying to add the Noise Suppressor to an audioRecord Handler through which I'm recording the audio, the issue is that although the audio record is clear and understandable, there is still a bit of static and buzzing noise for which i'm implementing the Noise Suppressor, and still the noise is not clear and the static still exists.

Here is my code:

public static boolean isAvailable( ) {
    return NoiseSuppressor.isAvailable();
}

@Override
public void run( ) {
    //Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO);
    int bufferSize = android.media.AudioRecord.getMinBufferSize( mSampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT );
    byte[][] audioData;
    int bufferReadResult;
    
    audioRecord = new android.media.AudioRecord( MediaRecorder.AudioSource.VOICE_RECOGNITION, mSampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize );
    
    x = audioRecord.getAudioSessionId();
    // divide byte buffersize to 2 to make it short buffer
    audioData = new byte[ 1000 ][ bufferSize ];
    
    if (isAvailable()) {
        noiseSuppressor = NoiseSuppressor.create( x );
        noiseSuppressor.setEnabled( true );
    } else {
        Log.d( "Audio Recorder thread", "Noise Suppressor not available" );
    }
    
    NoiseSuppressor.create( x );
    
    audioRecord.startRecording();
    
    int i = 0;
    byte[] data;
    while (( bufferReadResult = audioRecord.read( audioData[ i ], 0, audioData[ i ].length ) ) > 0) {
        
        data = audioData[ i ];
        
        Message msg = Message.obtain( audioHandler, AudioHandler.RECORD_AUDIO, data );
        msg.arg1 = bufferReadResult;
        msg.arg2 = (int) ( System.currentTimeMillis() - startTime );
        audioHandler.sendMessage( msg );
        
        i++;
        if (i == 1000) {
            i = 0;
        }
        if (stopThread) {
            break;
        }
    }
    
    Log.d( TAG, "AudioThread Finished, release audioRecord" );
}

public void stopAudioRecording( ) {
    
    if (audioRecord != null && audioRecord.getRecordingState() == android.media.AudioRecord.RECORDSTATE_RECORDING) {
        stopThread = true;
        audioRecord.stop();
        audioRecord.release();
        noiseSuppressor.release();
        audioRecord = null;
    }
}

I can not seem to find where the code went wrong.

ibrhm117
  • 387
  • 3
  • 25

0 Answers0