iosPorcupine - iOS Quick Start

Platforms

  • iOS (9.0+)

Requirements

Picovoice Account & AccessKey

Signup or Login to Picovoice Console to get your AccessKey. Make sure to keep your AccessKey secret.

Quick Start

Setup

  1. Install Xcode.

  2. Install CocoaPods

  3. Import the Porcupine iOS binding by adding the following line to Podfile:

pod 'Porcupine-iOS'
  1. Run the following from the project directory:
pod install
  1. Add the following to the app's Info.plist file to enable recording with an iOS device's microphone
<key>NSMicrophoneUsageDescription</key>
<string>[Permission explanation]</string>

Usage

Create an instance of PorcupineManager that detects the included built-in wake words porcupine and bumblebee:

import Porcupine
do {
let porcupineManager = try PorcupineManager(
accessKey: "${ACCESS_KEY}",
keywords: [Porcupine.BuiltInKeyword.porcupine, Porcupine.BuiltInKeyword.bumblebee],
onDetection: wakeWordCallback)
} catch { }

The wakeWordCallback parameter is a function that will be invoked when Porcupine has detected one of the keywords.

let wakeWordCallback: ((Int32) -> Void) = { keywordIndex in
if keywordIndex == 0 {
// porcupine detected
} else if keywordIndex == 1 {
// bumblebee detected
}
}
}

Start audio capture and wake word detection:

do {
porcupineManager.start()
} catch { }

Stop audio capture and processing with:

porcupineManager.stop()

Release resources explicitly when done with Porcupine:

porcupineManager.delete()

Custom Keywords

Create custom keywords using the Picovoice Console. Download the custom wake word file (.ppn) and include it in the app as a bundled resource (found by selecting in Build Phases > Copy Bundle Resources). Then, get its path from the app bundle:

let keywordPath = Bundle.main.path(forResource: "${CUSTOM_KEYWORD}", ofType: "ppn")

And create an instance of PorcupineManager that detects the custom keyword:

do {
let porcupineManager = try PorcupineManager(
accessKey: "${ACCESS_KEY}",
keywordPath: keywordPath,
onDetection: wakeWordCallback)
} catch { }

Non-English Languages

Use the corresponding model file (.pv) to detect non-English wake words. The model files for all supported languages are available on the Porcupine GitHub repository.

Pass in the model file using the modelPath input argument to change the detection language:

let modelPath = Bundle.main.path(forResource: "${MODEL_FILE}", ofType: "pv")
do {
let porcupineManager = try PorcupineManager(
accessKey: "${ACCESS_KEY}",
keywordPath: keywordPath,
modelPath: modelPath,
onDetection: wakeWordCallback)
} catch { }

Demo

For the Porcupine iOS SDK, we offer demo applications that demonstrate how to use the wake word engine on real-time audio streams (i.e. microphone input).

Setup

Clone the Repository:

git clone --recurse-submodules https://github.com/Picovoice/porcupine.git

Usage

  1. Install dependencies:
cd porcupine/demo/ios/ForegroundApp
pod install
  1. Replace let accessKey = "${YOUR_ACCESS_KEY_HERE}" in the file ViewController.swift with a valid AccessKey.

  2. Open the PorcupineForegroundAppDemo.xcworkspace and run the demo.

The demo detects the chosen keyword only when the application is in focus. To see an example of Porcupine in a background service, head over to our Github repository.

Resources

Packages

API

GitHub

Benchmark

Further Reading


Issue with this doc? Please let us know.