Skip to content

Commit

Permalink
pod spec
Browse files Browse the repository at this point in the history
  • Loading branch information
laves committed Oct 18, 2023
1 parent eed5e73 commit b66e70c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 3 additions & 3 deletions sdk/ios/Picovoice-iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Pod::Spec.new do |s|
DESC
s.homepage = 'https://github.com/Picovoice/picovoice/tree/master/sdk/ios'
s.author = { 'Picovoice' => 'hello@picovoice.ai' }
s.source = { :git => "https://github.com/Picovoice/picovoice.git", :tag => "Picovoice-iOS-v2.2.2" }
s.source = { :git => "https://github.com/Picovoice/picovoice.git", :tag => "Picovoice-iOS-v3.0.0" }
s.ios.deployment_target = '11.0'
s.swift_version = '5.0'
s.source_files = 'sdk/ios/*.{swift}'
s.exclude_files = 'sdk/ios/PicovoiceAppTest/**'

s.dependency 'Porcupine-iOS', '~> 2.2.1'
s.dependency 'Rhino-iOS', '~> 2.2.2'
s.dependency 'Porcupine-iOS', '~> 3.0.0'
s.dependency 'Rhino-iOS', '~> 3.0.0'
s.dependency 'ios-voice-processor', '~> 1.1.0'
end
6 changes: 3 additions & 3 deletions sdk/ios/Picovoice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Picovoice {
public static let sampleRate = Porcupine.sampleRate
public static let porcupineVersion = Porcupine.version
public static let rhinoVersion = Rhino.version
public static let picovoiceVersion = "2.2.0"
public static let picovoiceVersion = "3.0.0"
public var contextInfo: String = ""

private var isWakeWordDetected: Bool = false
Expand Down Expand Up @@ -142,8 +142,8 @@ public class Picovoice {
}

/// Resets the internal state of Picovoice. It should be called before processing a new stream of audio
/// or when process was stopped while processing a stream of audio.
///
/// or when Picovoice was stopped while processing a stream of audio.
///
/// - Throws: PicovoiceError
public func reset() throws {
if porcupine == nil || rhino == nil {
Expand Down
30 changes: 23 additions & 7 deletions sdk/ios/PicovoiceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import Porcupine
/// from microphone, processes it in real-time using Picovoice, and notifies the
/// client upon detection of the wake word or completion of in voice command inference.
public class PicovoiceManager {
private var picovoice: Picovoice
private var picovoice: Picovoice?

private var frameListener: VoiceProcessorFrameListener?
private var errorListener: VoiceProcessorErrorListener?

public var contextInfo: String {
get {
return self.picovoice.contextInfo
return (self.picovoice != nil) ? self.picovoice!.contextInfo : ""
}
}

Expand Down Expand Up @@ -51,6 +51,8 @@ public class PicovoiceManager {
/// inference regardless. Set to `false` only if operating in an environment with overlapping speech
/// (e.g. people talking in the background).
/// - processErrorCallback: A callback that is invoked if there is an error while processing audio.
///
/// - Throws: PicovoiceError if unable to initialize
public init(
accessKey: String,
keywordPath: String,
Expand All @@ -63,7 +65,7 @@ public class PicovoiceManager {
rhinoSensitivity: Float32 = 0.5,
endpointDurationSec: Float32 = 1.0,
requireEndpoint: Bool = true,
processErrorCallback: ((Error) -> Void)? = nil) {
processErrorCallback: ((Error) -> Void)? = nil) throws {

picovoice = try Picovoice(
accessKey: self.accessKey,
Expand All @@ -80,11 +82,11 @@ public class PicovoiceManager {

self.errorListener = VoiceProcessorErrorListener({ error in
guard let callback = processErrorCallback else {
print("\(error.errorDescription)")
print("\(error.localizedDescription)")
return
}

callback(PicovoiceError(error.errorDescription))
callback(PicovoiceError(error.localizedDescription))
})

self.frameListener = VoiceProcessorFrameListener({ frame in
Expand All @@ -96,7 +98,7 @@ public class PicovoiceManager {
try picovoice.process(pcm: frame)
} catch {
guard let callback = processErrorCallback else {
print("\(error)")
print("\(error.localizedDescription)")
return
}

Expand All @@ -106,13 +108,23 @@ public class PicovoiceManager {
}

deinit {
self.picovoice.delete()
delete()
}

/// Releases native resources that were allocated to PicovoiceManager
public func delete() {
self.picovoice?.delete()
self.picovoice = nil
}

/// Starts recording audio from the microphone and Picovoice processing loop.
///
/// - Throws: PicovoiceError if unable to start recording
public func start() throws {
if picovoice == nil {
throw PicovoiceInvalidStateError("Cannot start - resources have been released.")
}

VoiceProcessor.instance.addErrorListener(errorListener!)
VoiceProcessor.instance.addFrameListener(frameListener!)

Expand All @@ -130,6 +142,10 @@ public class PicovoiceManager {
///
/// - Throws: PicovoiceError if unable to stop recording
public func stop() throws {
if picovoice == nil {
throw PicovoiceInvalidStateError("Cannot stop - resources have been released.")
}

VoiceProcessor.instance.removeErrorListener(errorListener!)
VoiceProcessor.instance.removeFrameListener(frameListener!)

Expand Down

0 comments on commit b66e70c

Please sign in to comment.