Java Code Examples for android.media.AudioRecord#STATE_UNINITIALIZED
The following examples show how to use
android.media.AudioRecord#STATE_UNINITIALIZED .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MicRecorder.java From ScreenCapture with MIT License | 6 votes |
private static AudioRecord createAudioRecord(int sampleRateInHz, int channelConfig, int audioFormat) { int minBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); if (minBytes <= 0) { Log.e(TAG, String.format(Locale.US, "Bad arguments: getMinBufferSize(%d, %d, %d)", sampleRateInHz, channelConfig, audioFormat)); return null; } AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRateInHz, channelConfig, audioFormat, minBytes * 2); if (record.getState() == AudioRecord.STATE_UNINITIALIZED) { Log.e(TAG, String.format(Locale.US, "Bad arguments to new AudioRecord %d, %d, %d", sampleRateInHz, channelConfig, audioFormat)); return null; } if (VERBOSE) { Log.i(TAG, "created AudioRecord " + record + ", MinBufferSize= " + minBytes); if (Build.VERSION.SDK_INT >= N) { Log.d(TAG, " size in frame " + record.getBufferSizeInFrames()); } } return record; }
Example 2
Source File: RapidRecognizer.java From RapidSphinx with MIT License | 6 votes |
public RecognizerThread(int timeout) { if (timeout != NO_TIMEOUT) { this.timeoutSamples = timeout * sampleRate / 1000; } else { this.timeoutSamples = NO_TIMEOUT; } this.remainingSamples = this.timeoutSamples; recorder = new AudioRecord(6, sampleRate, 16, 2, bufferSize * 2); if (recorder.getState() == AudioRecord.STATE_UNINITIALIZED) { recorder.release(); try { throw new IOException( "Failed to initialize recorder. Microphone might be already in use."); } catch (IOException e) { e.printStackTrace(); } } }
Example 3
Source File: SpeechRecognizer.java From pocketsphinx-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates speech recognizer. Recognizer holds the AudioRecord object, so you * need to call {@link release} in order to properly finalize it. * * @param config The configuration object * @throws IOException thrown if audio recorder can not be created for some reason. */ protected SpeechRecognizer(Config config) throws IOException { decoder = new Decoder(config); sampleRate = (int)decoder.getConfig().getFloat("-samprate"); bufferSize = Math.round(sampleRate * BUFFER_SIZE_SECONDS); recorder = new AudioRecord( AudioSource.VOICE_RECOGNITION, sampleRate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize * 2); if (recorder.getState() == AudioRecord.STATE_UNINITIALIZED) { recorder.release(); throw new IOException( "Failed to initialize recorder. Microphone might be already in use."); } }
Example 4
Source File: ExtAudioCapture.java From PLDroidRTCStreaming with Apache License 2.0 | 5 votes |
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) { if (mIsCaptureStarted) { Log.e(TAG, "Capture already started !"); return false; } int minBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); if (minBufferSize == AudioRecord.ERROR_BAD_VALUE) { Log.e(TAG, "Invalid parameter !"); return false; } mAudioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, minBufferSize * 4); if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) { Log.e(TAG, "AudioRecord initialize fail !"); return false; } mAudioRecord.startRecording(); mIsLoopExit = false; mCaptureThread = new Thread(new AudioCaptureRunnable()); mCaptureThread.start(); mIsCaptureStarted = true; Log.d(TAG, "Start audio capture success !"); return true; }
Example 5
Source File: AudioCodec.java From haven with GNU General Public License v3.0 | 5 votes |
public void stop() { if (recorder != null && recorder.getState() != AudioRecord.STATE_UNINITIALIZED) { recorder.stop(); recorder.release(); Log.i("AudioCodec", "Sampling stopped"); } Log.i("AudioCodec", "Recorder set to null"); recorder = null; }
Example 6
Source File: SaiyRecorder.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
/** * Initialise the Voice Recorder * * @return The audio record initialisation state. */ public int initialise() { int count = 0; while (count < 4) { count++; saiyAudio = new SaiyAudio(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes, enhance); if (saiyAudio.getState() == AudioRecord.STATE_INITIALIZED) { return AudioRecord.STATE_INITIALIZED; } else { if (DEBUG) { MyLog.w(CLS_NAME, "SaiyAudio reinitialisation attempt ~ " + count); } if (Looper.myLooper() != null && Looper.myLooper() != Looper.getMainLooper()) { // Give the audio object a small chance to sort itself out try { Thread.sleep(250); } catch (InterruptedException e) { if (DEBUG) { MyLog.w(CLS_NAME, "SaiyAudio InterruptedException"); e.printStackTrace(); } } } } } if (DEBUG) { MyLog.w(CLS_NAME, "SaiyAudio initialisation failed"); } return AudioRecord.STATE_UNINITIALIZED; }
Example 7
Source File: AudioCodec.java From secureit with MIT License | 5 votes |
public void stop() { if (recorder != null && recorder.getState() != AudioRecord.STATE_UNINITIALIZED) { recorder.stop(); recorder.release(); Log.i("AudioCodec", "Sampling stopped"); } Log.i("AudioCodec", "Recorder set to null"); recorder = null; }
Example 8
Source File: ExtAudioCapture.java From PLDroidMediaStreaming with Apache License 2.0 | 5 votes |
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) { if (mIsCaptureStarted) { Log.e(TAG, "Capture already started !"); return false; } int minBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); if (minBufferSize == AudioRecord.ERROR_BAD_VALUE) { Log.e(TAG, "Invalid parameter !"); return false; } mAudioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, minBufferSize * 4); if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) { Log.e(TAG, "AudioRecord initialize fail !"); return false; } mAudioRecord.startRecording(); mIsLoopExit = false; mCaptureThread = new Thread(new AudioCaptureRunnable()); mCaptureThread.start(); mIsCaptureStarted = true; Log.d(TAG, "Start audio capture success !"); return true; }
Example 9
Source File: AudioCapturer.java From Android with Apache License 2.0 | 5 votes |
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) { if (mIsCaptureStarted) { Log.e(TAG, "Capture already started !"); return false; } mMinBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz,channelConfig,audioFormat); if (mMinBufferSize == AudioRecord.ERROR_BAD_VALUE) { Log.e(TAG, "Invalid parameter !"); return false; } Log.d(TAG , "getMinBufferSize = "+mMinBufferSize+" bytes !"); mAudioRecord = new AudioRecord(audioSource,sampleRateInHz,channelConfig,audioFormat,mMinBufferSize); if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) { Log.e(TAG, "AudioRecord initialize fail !"); return false; } mAudioRecord.startRecording(); mIsLoopExit = false; mCaptureThread = new Thread(new AudioCaptureRunnable()); mCaptureThread.start(); mIsCaptureStarted = true; Log.d(TAG, "Start audio capture success !"); return true; }
Example 10
Source File: ShadowAudioRecord.java From science-journal with Apache License 2.0 | 4 votes |
public static void setInitializationFailed() { state = AudioRecord.STATE_UNINITIALIZED; }
Example 11
Source File: AudioCapture.java From EvilsLive with MIT License | 3 votes |
public boolean startCapture(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) { if (mIsCaptureStarted) { Log.e(TAG, "hujd Capture already started !"); return false; } mMinBufferSize = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat); if (mMinBufferSize == AudioRecord.ERROR_BAD_VALUE) { Log.e(TAG, "hujd Invalid parameter !"); return false; } Log.e(TAG, "hujd getMinBufferSize = " + mMinBufferSize + " bytes !"); mAudioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, mMinBufferSize); if (mAudioRecord.getState() == AudioRecord.STATE_UNINITIALIZED) { Log.e(TAG, "hujd AudioRecord initialize fail !"); return false; } mAudioRecord.startRecording(); mIsLoopExit = false; mCaptureThread = new Thread(new AudioCaptureRunnable()); mCaptureThread.start(); mIsCaptureStarted = true; Log.e(TAG, "hujd Start audio capture success !"); return true; }