/android-voice-processor

Asynchronous Android audio recording library designed for real-time speech audio processing

Primary LanguageJavaApache License 2.0Apache-2.0

Android Voice Processor

GitHub release GitHub

Maven Central

Made in Vancouver, Canada by Picovoice

Twitter URL

YouTube Channel Views

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.

Table of Contents

Requirements

  • Java SDK (11+)
  • Android SDK (21+)

Compatibility

  • Android 5.0+ (API 21+)

Installation

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}'
}

Permissions

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.

Usage

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.

Capturing with Multiple Listeners

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();

Example

The Android Voice Processor app demonstrates how to ask for user permissions and capture output from the VoiceProcessor.

Releases

v1.0.0 - July 18, 2023

  • Initial public release.