Skip to content

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

License

Notifications You must be signed in to change notification settings

Picovoice/ios-voice-processor

Repository files navigation

iOS Voice Processor

GitHub release GitHub

Cocoapods

Made in Vancouver, Canada by Picovoice

Twitter URL

YouTube Channel Views

The iOS 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

Compatibility

  • iOS 13.0+

Installation

iOS Voice Processor is available via the Swift Package Manager and CocoaPods.

To import the package using SPM, open up your project's Package Dependencies in XCode and add:

https://github.com/Picovoice/ios-voice-processor.git

To import it into your iOS project using CocoaPods, add the following line to your Podfile:

pod 'ios-voice-processor'

Permissions

To enable recording with your iOS device's microphone you must add the following to your app's Info.plist file:

<key>NSMicrophoneUsageDescription</key>
<string>[Permission explanation]</string>

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 ios_voice_processor

let voiceProcessor = VoiceProcessor.instance

Add listeners for audio frames and errors:

let frameListener = VoiceProcessorFrameListener { frame in
    // use audio
}

let errorListener = VoiceProcessorErrorListener { error in
    // handle error
}

voiceProcessor.addFrameListener(frameListener);
voiceProcessor.addErrorListener(errorListener);

Start audio capture with the desired frame length and audio sample rate:

do {
    try voiceProcessor.start(frameLength: 512, sampleRate: 16000);
} catch {
    // handle start error
}

Stop audio capture:

do {
    try voiceProcessor.stop();
} catch {
}

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:

let listener1 = VoiceProcessorFrameListener({_ in })
let listener2 = VoiceProcessorFrameListener({_ in })
let listeners: [VoiceProcessorFrameListener] = [listener1, listener2];

voiceProcessor.addFrameListeners(listeners);

voiceProcessor.removeFrameListeners(listeners);
// or
voiceProcessor.clearFrameListeners();

Example

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

Releases

v1.2.0 - October 24, 2024

  • Add support for Swift Package Manager
  • Bumped minimum iOS version to 13

v1.1.0 - July 31, 2023

  • Numerous API improvements
  • Error handling improvements
  • Allow for multiple listeners instead of a single callback function
  • Upgrades to testing infrastructure and example app

v1.0.0 - August 5, 2021

  • Initial public release.

About

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

Topics

Resources

License

Stars

Watchers

Forks