Swift Wrapper
The Pryonlite Swift wrapper provides a Swift interface around the PryonLite library's C APIs.
Files required for integration
The following files need to be added to the target iOS App's workspace.
BridgingHeader.h
Imports the pryonlite C header files and provides a bridging interface needed by the Swift wrapper.
PryonWrapper.swift
Provides the Swift interface for iOS Apps to use the pryonlite library.
PryonWrapper APIs:
/// Initializer method of the PronLite wrapper class.
/// Configures and sets up the PryonLite Wake Word detector.
///
/// - Parameters:
/// - detectThreshold: wake word detection threshold in the range [1-1000],
/// 1 = lowest threshold, most detections, 1000 = highest threshold, fewer restrictive.
/// - modelFile: Wake Word model file.
/// - modelDir: Directory of the wake word model file, optional, default is nil
/// - internalConfigReserved: Reserved config pointer, optional, default is nil.
/// - useVad: Use Pryonlite's Voice Activity Detector, optional, default is 0.
/// - lowLatency: enable Low latency mode. Only valid for type 'U' models.
/// Results in ~200ms lower detection latency, at the cost of less accurate ww end indexes reported in
/// the detection callback.
///
init(detectThreshold: Int32, modelFile: NSString, modelDir:String? = nil, internalConfigReserved: UnsafeMutableRawPointer? = nil,
useVad: Int32? = 0, lowLatency: Int32? = 0)
/// Push audio samples for PryonLite's processing.
///
/// - Parameters:
/// - samples: Pointer to Int16 array of the input audio samples.
/// - sampleCount: Number of samples in the samples array. This should be equal to 160.
/// - Returns: PryonLiteError code, nominally PRYON_LITE_ERROR_OK.
/// Refer to pryon_lite_error.h for the list of error values.
///
pushSamples(samples: UnsafeMutablePointer<Int16>, sampleCount: Int32) ->PryonLiteError
/// Enable or disable one or all wakeword keywords
/// - Parameters:
/// - keyword: Pointer to C CHAR array type for keyword to enable or disable; ex. "ALEXA".
/// Pass keyword "ALL" to enable or disable all keywords.
/// - enable: (Int32): Integer 0: disable keyword, 1 enable keyword.
///
wakewordEnableKeyword(keyword: UnsafeMutablePointer<CChar>, enable: Int32) -> PryonLiteStatus
/// Destory the PryonLite Wrapper Instance.
///
/// - Returns: PryonLiteError code, nominally PRYON_LITE_ERROR_OK.
/// Refer to pryon_lite_error.h for the list of error values.
///
destroy() ->PryonLiteError
Usage
The iOS App can invoke the pryonlite library in it's various stages as follows:
-
Initialization stage to configure and initialize the pryonlite library.
var pryonWrapper: PryonWrapper let detectionThreshold = 500 let useVad = 0 let lowLatency = 0 modelFilePath = "D.en-US.alexa" modelDir = "models/common" pryonWrapper = PryonWrapper(detectThreshold: detectionThreshold, modelFile: modelFilePath, modelDir: modelDir, internalConfigReserved: nil, useVad: useVad, lowLatency: lowLatency)
-
Audio processing loop to push the audio samples to processing.
let pryonliteStatusCode = pryonWrapper.pushSamples(samples: &samplesArray, sampleCount: Int32(samplesArray.count)) if (pryonliteStatusCode.publicCode != Int32(PRYON_LITE_ERROR_OK.rawValue)) { print(""" Error pushing Samples with index \(readSampleIndex) Public Error Code: \(pryonliteStatusCode.publicCode) Internal Error Code: \(pryonliteStatusCode.internalCode) """ , to:&LogFileOutput) }
-
Teardown stage of the application to destory the pryonlite instance.
// Flush the decoder let pryonliteStatusCode = pryonWrapper.destroy() if (pryonliteStatusCode.publicCode != Int32(PRYON_LITE_ERROR_OK.rawValue)) { print(""" Error flushing decoder. Public Error Code: \(pryonliteStatusCode.publicCode) Internal Error Code: \(pryonliteStatusCode.internalCode) """ , to:&LogFileOutput) }