Usages of

android.media.audiofx.NoiseSuppressor.getEnabled()
public VoiceActivityRecognizer(AudioRecord audioRecord) { this.audioRecord = audioRecord; this.audioBufferSize = (int) Math.pow(2,Math.round(Math.log(audioRecord.getSampleRate()/50)/Math.log(2))); if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(audioRecord.getAudioSessionId()); if(noiseSuppressor != null && !noiseSuppressor.getEnabled()) { noiseSuppressor.setEnabled(true); } } }
private NoiseCheckTask(NoiseTracker noiseTracker) { audioRecorder = new AudioRecord(MediaRecorder.AudioSource.CAMCORDER, SAMPLING, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize); if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(audioRecorder.getAudioSessionId()); if (noiseSuppressor == null) FirebaseCrash.report(new Throwable("noise suppressor is null when it should be available.")); else if (!noiseSuppressor.getEnabled()) noiseSuppressor.setEnabled(true); } this.noiseTracker = noiseTracker; }
@SuppressLint("NewApi") public void enableNoiseSuppressor() { if (!NoiseSuppressor.isAvailable()) { Log.e("AudioProcessor", "NoiseSuppressor is not supported in this device!"); } else { NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(mAudioRecorder.getAudioSessionId()); if (!noiseSuppressor.getEnabled()) { noiseSuppressor.setEnabled(true); Log.i(LOG_TAG, "NoiseSuppressor is enabled!"); } else { Log.i(LOG_TAG, "NoiseSupporessor is already enabled!"); } } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static void aec(AudioRecord ar) { if (AcousticEchoCanceler.isAvailable()) { AcousticEchoCanceler aec = AcousticEchoCanceler.create(ar.getAudioSessionId()); if (aec != null && !aec.getEnabled()) { aec.setEnabled(true); } } if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noise = NoiseSuppressor.create(ar.getAudioSessionId()); if (noise != null && !noise.getEnabled()) { noise.setEnabled(true); } } }
/** * �������� * @param ar */ public static void aec(AudioRecord ar) { if (AcousticEchoCanceler.isAvailable()) { AcousticEchoCanceler aec = AcousticEchoCanceler.create(ar.getAudioSessionId()); if (aec != null && !aec.getEnabled()) { aec.setEnabled(true); } } if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noise = NoiseSuppressor.create(ar.getAudioSessionId()); if (noise != null && !noise.getEnabled()) { noise.setEnabled(true); } } }
public static void aec(AudioRecord ar) { if (AcousticEchoCanceler.isAvailable()) { AcousticEchoCanceler aec = AcousticEchoCanceler.create(ar.getAudioSessionId()); if (aec != null && !aec.getEnabled()) { aec.setEnabled(true); } } if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noise = NoiseSuppressor.create(ar.getAudioSessionId()); if (noise != null && !noise.getEnabled()) { noise.setEnabled(true); } } }
private NoiseSuppressor mNoiseSuppressor; // code omitted ... @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void aec() { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (AcousticEchoCanceler.isAvailable()) { CommonUtils.logd(TAG, "AcousticEchoCanceler isAvailable"); mAcousticEchoCanceler = AcousticEchoCanceler.create(mAudioRecord.getAudioSessionId()); if (mAcousticEchoCanceler != null && !mAcousticEchoCanceler.getEnabled()) { mAcousticEchoCanceler.setEnabled(true); CommonUtils.logd(TAG, "AcousticEchoCanceler enabled = "+mAcousticEchoCanceler.getEnabled()); } } if (NoiseSuppressor.isAvailable()) { CommonUtils.logd(TAG, "NoiseSuppressor isAvailable"); mNoiseSuppressor = NoiseSuppressor.create(mAudioRecord.getAudioSessionId()); if (mNoiseSuppressor != null && !mNoiseSuppressor.getEnabled()) { mNoiseSuppressor.setEnabled(true); CommonUtils.logd(TAG, "NoiseSuppressor enabled = "+mNoiseSuppressor.getEnabled()); } } } }
@Override protected Void doInBackground(String... params) { int bufferSize; short[] buffer; double sum; double amplitude; int bufferReadResult; NoiseSuppressor ns = null; AutomaticGainControl agc = null; AcousticEchoCanceler aec = null; isRecording = true; try { File file = HiUtils.createOrGetFile(callback.fileName); OutputStream os = new FileOutputStream(file); BufferedOutputStream bos = new BufferedOutputStream(os); DataOutputStream dos = new DataOutputStream(bos); bufferSize = AudioRecord.getMinBufferSize(HiSoundParams.RECORDER_SAMPLERATE, HiSoundParams.RECORDER_CHANNELS, HiSoundParams.RECORDER_AUDIO_ENCODING); buffer = new short[bufferSize]; // Create a new AudioRecord object to record the audio. AudioRecord audioRecord = new AudioRecord( MediaRecorder.AudioSource.MIC, HiSoundParams.RECORDER_SAMPLERATE, HiSoundParams.RECORDER_CHANNELS, HiSoundParams.RECORDER_AUDIO_ENCODING, bufferSize); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { int audioSessionId = audioRecord.getAudioSessionId(); if (NoiseSuppressor.isAvailable()) { ns = NoiseSuppressor.create(audioSessionId); HiUtils.log("recording process", "NoiseSuppressor is Enabled: " + ns.getEnabled()); } else { HiUtils.log("recording process", "NoiseSuppressor failed :("); } if (AutomaticGainControl.isAvailable()) { agc = AutomaticGainControl.create(audioSessionId); HiUtils.log("recording process", "AutomaticGainControl is Enabled: " + agc.getEnabled()); } else { HiUtils.log("recording process", "AutomaticGainControl failed :("); } if (AcousticEchoCanceler.isAvailable()) { aec = AcousticEchoCanceler.create(audioSessionId); HiUtils.log("recording process", "AcousticEchoCanceler is Enabled: " + aec.getEnabled()); } else { HiUtils.log("recording process", "AcousticEchoCanceler failed :("); } } audioRecord.startRecording(); while (isRecording) { sum = 0; amplitude = 0; bufferReadResult = audioRecord.read(buffer, 0, bufferSize); for (int i = 0; i < bufferReadResult; i++) { dos.writeShort(buffer[i]); sum += buffer[i] * buffer[i]; } if (bufferReadResult > 0) { amplitude = (int) Math.sqrt(sum / bufferReadResult); } if (amplitude > HiSoundParams.RECORDER_AMP_THRESHOLD) { for (int i = 0; i < bufferReadResult; i++) { audio.add(buffer[i]); } } } audioRecord.stop(); audioRecord.release(); dos.close(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (ns != null) { ns.release(); } if (agc != null) { agc.release(); } if (aec != null) { aec.release(); } } } catch (Exception ex) { HiUtils.log("recording process", ex.getMessage()); } return null; }
/** * Configures echo cancellation and noise suppression effects. */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void configureEffects() { if (!AndroidUtils.hasAPI(16)) { return; } AudioSystem audioSystem = AudioSystem.getAudioSystem(AudioSystem.LOCATOR_PROTOCOL_AUDIORECORD); // Creates echo canceler if available if (AcousticEchoCanceler.isAvailable()) { AcousticEchoCanceler echoCanceller = AcousticEchoCanceler.create(audioRecord.getAudioSessionId()); if (echoCanceller != null) { echoCanceller.setEnableStatusListener(this); echoCanceller.setEnabled(audioSystem.isEchoCancel()); logger.info("Echo cancellation: " + echoCanceller.getEnabled()); } } // Automatic gain control if (AutomaticGainControl.isAvailable()) { AutomaticGainControl agc = AutomaticGainControl.create(audioRecord.getAudioSessionId()); if (agc != null) { agc.setEnableStatusListener(this); agc.setEnabled(audioSystem.isAutomaticGainControl()); logger.info("Auto gain control: " + agc.getEnabled()); } } // Creates noise suppressor if available if (NoiseSuppressor.isAvailable()) { NoiseSuppressor noiseSuppressor = NoiseSuppressor.create(audioRecord.getAudioSessionId()); if (noiseSuppressor != null) { noiseSuppressor.setEnableStatusListener(this); noiseSuppressor.setEnabled(audioSystem.isDenoise()); logger.info("Noise suppressor: " + noiseSuppressor.getEnabled()); } } }
//Test case 1.2: test setEnabled() and getEnabled() public void test1_2NsSetEnabledGetEnabled() throws Exception { if (!hasMicrophone()) { return; } if (!NoiseSuppressor.isAvailable()) { return; } AudioRecord ar = getAudioRecord(); assertNotNull("could not create AudioRecord", ar); NoiseSuppressor ns = NoiseSuppressor.create(ar.getAudioSessionId()); assertNotNull("could not create NoiseSupressor", ns); try { ns.setEnabled(true); assertTrue("invalid state from getEnabled", ns.getEnabled()); ns.setEnabled(false); assertFalse("invalid state to getEnabled", ns.getEnabled()); // test passed } catch (IllegalStateException e) { fail("setEnabled() in wrong state"); } finally { ns.release(); ar.release(); } }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes