Made in Vancouver, Canada by Picovoice
The Android Voice Processor is an asynchronous audio capture library designed for real-time audio processing. Given some specifications, the library delivers frames of raw audio data to the user via listeners.
- Java SDK (11+)
- Android SDK (21+)
- Android 5.0+ (API 21+)
Android Voice Processor can be found on Maven Central. To include the package in your Android
project, ensure you have included mavenCentral()
in your top-level build.gradle
file and then
add the following to your app's build.gradle
:
dependencies {
// ...
implementation 'ai.picovoice:android-voice-processor:${LATEST_VERSION}'
}
To enable audio recording with your Android device's microphone, you must add the following line to
your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
See our example app or this guide for how to properly request this permission from your users.
Access the singleton instance of VoiceProcessor
:
import ai.picovoice.android.voiceprocessor.*;
VoiceProcessor voiceProcessor = VoiceProcessor.getInstance();
Add listeners for audio frames and errors:
final VoiceProcessorFrameListener frameListener = frame -> {
// use audio data
};
final VoiceProcessorErrorListener errorListener = e -> {
// handle error
};
voiceProcessor.addFrameListener(frameListener);
voiceProcessor.addErrorListener(errorListener);
Start audio capture with the desired frame length and audio sample rate:
final int frameLength = 512;
final int sampleRate = 16000;
voiceProcessor.start(frameLength, sampleRate);
Stop audio capture:
voiceProcessor.stop();
Once audio capture has started successfully, any frame listeners assigned to the VoiceProcessor
will start receiving audio frames with the given frameLength
and sampleRate
.
Any number of listeners can be added to and removed from the VoiceProcessor
instance. However,
the instance can only record audio with a single audio configuration (frameLength
and sampleRate
),
which all listeners will receive once a call to start()
has been made. To add multiple listeners:
VoiceProcessorFrameListener listener1 = frame -> { };
VoiceProcessorFrameListener listener2 = frame -> { };
VoiceProcessorFrameListener[] listeners = new VoiceProcessorFrameListener[] {
listener1, listener2
};
voiceProcessor.addFrameListeners(listeners);
voiceProcessor.removeFrameListeners(listeners);
// or
voiceProcessor.clearFrameListeners();
The Android Voice Processor app demonstrates how to ask for user permissions and capture output from
the VoiceProcessor
.
- Initial public release.