private void checkthingsforrecoder() { int audioSessionId = getAudioSessionId(); if(NoiseSuppressor.isAvailable()) { // NoiseSuppressor.create(audioSessionId); } if(AutomaticGainControl.isAvailable()) { // AutomaticGainControl.create(audioSessionId); } if(AcousticEchoCanceler.isAvailable()){ // AcousticEchoCanceler.create(audioSessionId); } }
/** * <p>Instantiates a new recorder and sets the state to INITIALIZING. * In case of errors, no exception is thrown, but the state is set to ERROR.</p> * * <p>Android docs say: 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.</p> * * @param audioSource Identifier of the audio source (e.g. microphone) * @param sampleRate Sample rate (e.g. 16000) */ public RawAudioRecorder(int audioSource, int sampleRate) { mSampleRate = sampleRate; // E.g. 1 second of 16kHz 16-bit mono audio takes 32000 bytes. mOneSec = RESOLUTION_IN_BYTES * CHANNELS * mSampleRate; mRecording = new byte[mOneSec * MAX_RECORDING_TIME_IN_SECS]; try { setBufferSizeAndFramePeriod(); mRecorder = new AudioRecord(audioSource, mSampleRate, AudioFormat.CHANNEL_IN_MONO, RESOLUTION, mBufferSize); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { boolean agcAvailable = AutomaticGainControl.isAvailable(); if(agcAvailable) { AutomaticGainControl.create(mRecorder.getAudioSessionId()); } } if (mRecorder.getState() != AudioRecord.STATE_INITIALIZED) { throw new Exception("AudioRecord initialization failed"); } mBuffer = new byte[mFramePeriod * RESOLUTION_IN_BYTES * CHANNELS]; setState(State.READY); } catch (Exception e) { release(); setState(State.ERROR); if (e.getMessage() == null) { Log.e(LOG_TAG, "Unknown error occured while initializing recording"); } else { Log.e(LOG_TAG, e.getMessage()); } } }
public void enableAutoGainControl() { if (AutomaticGainControl.isAvailable() && automaticGainControl == null) { automaticGainControl = AutomaticGainControl.create(microphoneId); automaticGainControl.setEnabled(true); Log.i(TAG, "AutoGainControl enabled"); } else { Log.e(TAG, "This device don't support AutoGainControl"); } }
public SpeechRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes, boolean noise, boolean gain, boolean echo) throws IllegalArgumentException { super(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { Log.i("Trying to enhance audio because running on SDK " + Build.VERSION.SDK_INT); int audioSessionId = getAudioSessionId(); if (noise) { if (NoiseSuppressor.create(audioSessionId) == null) { Log.i("NoiseSuppressor: failed"); } else { Log.i("NoiseSuppressor: ON"); } } else { Log.i("NoiseSuppressor: OFF"); } if (gain) { if (AutomaticGainControl.create(audioSessionId) == null) { Log.i("AutomaticGainControl: failed"); } else { Log.i("AutomaticGainControl: ON"); } } else { Log.i("AutomaticGainControl: OFF"); } if (echo) { if (AcousticEchoCanceler.create(audioSessionId) == null) { Log.i("AcousticEchoCanceler: failed"); } else { Log.i("AcousticEchoCanceler: ON"); } } else { Log.i("AcousticEchoCanceler: OFF"); } } }
/** * Attempt to set enhancers available on modern devices. * <p/> * These are hardware dependent, not build version. Although the APIs weren't available to * devices until API Level 16 */ @SuppressWarnings("NewApi") private void setEnhancers(final int sessionId) { if (!DEBUG) { NoiseSuppressor.create(sessionId); AcousticEchoCanceler.create(sessionId); AutomaticGainControl.create(sessionId); } else { if (NoiseSuppressor.create(sessionId) == null) { MyLog.i(CLS_NAME, "NoiseSuppressor null"); } else { MyLog.i(CLS_NAME, "NoiseSuppressor success"); } if (AcousticEchoCanceler.create(sessionId) == null) { MyLog.i(CLS_NAME, "AcousticEchoCanceler null"); } else { MyLog.i(CLS_NAME, "AcousticEchoCanceler success"); } if (AutomaticGainControl.create(sessionId) == null) { MyLog.i(CLS_NAME, "AutomaticGainControl null"); } else { MyLog.i(CLS_NAME, "AutomaticGainControl success"); } } }