Porcupine - iOS API
API Reference for the iOS Porcupine SDK (Cocoapod)
Porcupine
public class Porcupine { }
Class for the Porcupine Wake Word engine. Porcupine can be initialized either using the
High-level PorcupineManager() Class or directly using the class constructor.
Resources should be cleaned when you are done using the delete()
function.
Porcupine.init()
init
methods for Porcupine Wake Word engine with a mixture of arguments.
public init(accessKey: String, keywordPaths: [String], modelPath:String? = nil, sensitivities: [Float32]? = nil)
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywordPaths
[String] : Absolute paths to keyword model files (.ppn
).modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivities
[Float32]? : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
Throws
PorcupineError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String, keywordPath: String, modelPath:String? = nil, sensitivity: Float32 = 0.5)
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywordPath
String : Absolute path to a keyword model file (.ppn
).modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivity
Float32? : Sensitivity for detecting keyword, which should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
Throws
PorcupineError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String, keywords:[Porcupine.BuiltInKeyword], modelPath:String? = nil, sensitivities: [Float32]? = nil)
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywords
[Porcupine.BuiltInKeyword] : An array of built-in keywords from the Porcupine.BuiltInKeyword enum.modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivities
[Float32]? : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
Throws
PorcupineError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String, keyword: Porcupine.BuiltInKeyword, modelPath:String? = nil, sensitivity: Float32 = 0.5)
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keyword
Porcupine.BuiltInKeyword : A built-in keyword from the Porcupine.BuiltInKeyword enum.modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivity
Float32? : Sensitivity for detecting keyword, which should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.
Throws
PorcupineError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
Porcupine.delete()
Releases resources acquired by the Porcupine engine.
public func delete()
Porcupine.process()
Process a frame of audio with the Porcupine Wake Word engine.
public func process(pcm:[Int16]) throws -> Int32
Parameters
pcm
[Int16] : An array of 16-bit pcm samples.
Returns
- Int32 : Index of keyword detected or -1 if no keyword was detected.
Throws
PorcupineError
: If there is an error while processing the audio frame.
Porcupine.frameLength
Porcupine.frameLength: UInt32
The number of audio samples per frame.
Porcupine.sampleRate
Porcupine.sampleRate: UInt32
Audio sample rate accepted by Porcupine.
Porcupine.version
Porcupine.version: String
Current Porcupine version.
Porcupine.BuiltInKeyword
public enum BuiltInKeyword: String, CaseIterable {case alexa = "Alexa"case americano = "Americano"case blueberry = "Blueberry"case bumblebee = "Bumblebee"case computer = "Computer"case grapefruit = "Grapefruit"case grasshopper = "Grasshopper"case heyGoogle = "Hey Google"case heySiri = "Hey Siri"case jarvis = "Jarvis"case okGoogle = "Ok Google"case picovoice = "Picovoice"case porcupine = "Porcupine"case terminator = "Terminator"}
Enum of available built-in keywords for Porcupine Wake Word engine.
PorcupineManager
A High-level iOS binding for Porcupine
that handles recording audio from microphone, processes it in
real-time using Porcupine, and notifies the client when any of the given keywords are detected.
public class PorcupineManager { }
PorcupineManager.init()
public convenience init(accessKey: String,keywordPaths: [String],modelPath:String? = nil,sensitivities: [Float32]? = nil,onDetection: ((Int32) -> Void)?,errorCallback: ((Error) -> Void)? = nil) throws
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywordPaths
[String] : Absolute paths to keyword model files (.ppn
).modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivities
[Float32]? : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.onDetection
((Int32) -> Void)? : A callback that is invoked upon detection of the keyword.errorCallback
((Error) -> Void)? = nil) : A callback that is invoked if an error occurs while processing frames. If missing, error will be printed to console.
Throws
PorcupineManagerError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String,keywordPath: String,modelPath:String? = nil,sensitivity: Float32 = 0.5,onDetection: ((Int32) -> Void)?,errorCallback: ((Error) -> Void)? = nil) throws
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywordPath
String : Absolute path to a keyword model file (.ppn
).modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivity
Float32? : Sensitivity for detecting keyword, which should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.onDetection
((Int32) -> Void)? : A callback that is invoked upon detection of the keyword.errorCallback
((Error) -> Void)? = nil) : A callback that is invoked if an error occurs while processing frames. If missing, error will be printed to console.
Throws
PorcupineManagerError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String,keywords:[Porcupine.BuiltInKeyword],modelPath:String? = nil,sensitivities: [Float32]? = nil,onDetection: ((Int32) -> Void)?,errorCallback: ((Error) -> Void)? = nil) throws
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keywords
[Porcupine.BuiltInKeyword] : An array of built-in keywords from the Porcupine.BuiltInKeyword enum.modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivities
[Float32]? : Sensitivities for detecting keywords. Each value should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.onDetection
((Int32) -> Void)? : A callback that is invoked upon detection of the keyword.errorCallback
((Error) -> Void)? = nil) : A callback that is invoked if an error occurs while processing frames. If missing, error will be printed to console.
Throws
PorcupineManagerError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
public convenience init(accessKey: String,keyword: Porcupine.BuiltInKeyword,modelPath: String? = nil,sensitivity: Float32 = 0.5,onDetection: ((Int32) -> Void)?,errorCallback: ((Error) -> Void)? = nil) throws
Parameters
accessKey
String : The AccessKey obtained from Picovoice Console.keyword
Porcupine.BuiltInKeyword : A built-in keyword from the Porcupine.BuiltInKeyword enum.modelPath
String? : Absolute path to file containing model parameters (.pv
).sensitivity
Float32? : Sensitivity for detecting keyword, which should be a number within [0, 1]. A higher sensitivity results in fewer misses at the cost of increasing the false alarm rate.onDetection
((Int32) -> Void)? : A callback that is invoked upon detection of the keyword.errorCallback
((Error) -> Void)? = nil) : A callback that is invoked if an error occurs while processing frames. If missing, error will be printed to console.
Throws
PorcupineManagerError
: If an error occurs while creating an instance of Porcupine Wake Word engine.
PorcupineManager.delete()
public func delete()
Stops recording and releases Porcupine resources.
PorcupineManager.start()
public func start() throws
Starts recording audio from the microphone and monitors it for the utterances of the given set of keywords.
Throws
PorcupineError
: If microphone permission is not granted or Porcupine has been disposed.
PorcupineManager.stop()
public func stop()
Stop listening for wake words.
PorcupineManagerError
public enum PorcupineManagerError: Error { }
Enums for PorcupineManager error values:
case recordingDenied
case objectDisposed
PorcupineError
public class PorcupineError : LocalizedError { }
Error thrown if an error occurs within Porcupine Wake Word engine.
public class PorcupineMemoryError : PorcupineError {}public class PorcupineIOError : PorcupineError {}public class PorcupineInvalidArgumentError : PorcupineError {}public class PorcupineStopIterationError : PorcupineError {}public class PorcupineKeyError : PorcupineError {}public class PorcupineInvalidStateError : PorcupineError {}public class PorcupineRuntimeError : PorcupineError {}public class PorcupineActivationError : PorcupineError {}public class PorcupineActivationLimitError : PorcupineError {}public class PorcupineActivationThrottledError : PorcupineError {}public class PorcupineActivationRefusedError : PorcupineError {}