From 3746dccf3f145b8d87f476a4db6ae6541717cc79 Mon Sep 17 00:00:00 2001 From: Kwangsoo Yeo Date: Wed, 1 Nov 2023 13:04:16 -0700 Subject: [PATCH] v2.0 ios (#37) --- binding/ios/Koala-iOS.podspec | 4 +- binding/ios/Koala.swift | 67 ++++++++++++++----- .../KoalaAppTest/ViewController.swift | 8 +-- .../KoalaAppTestUITests.swift | 22 ++++-- binding/ios/KoalaAppTest/Podfile | 6 +- binding/ios/KoalaAppTest/Podfile.lock | 21 +++--- binding/ios/KoalaErrors.swift | 13 +++- demo/ios/KoalaDemo/Podfile | 2 +- demo/ios/KoalaDemo/Podfile.lock | 18 +++-- .../PvKoala.framework/Headers/picovoice.h | 2 + .../PvKoala.framework/Headers/picovoice.h | 2 + 11 files changed, 116 insertions(+), 49 deletions(-) diff --git a/binding/ios/Koala-iOS.podspec b/binding/ios/Koala-iOS.podspec index b07a122..6f0ec6b 100644 --- a/binding/ios/Koala-iOS.podspec +++ b/binding/ios/Koala-iOS.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'Koala-iOS' s.module_name = 'Koala' - s.version = '1.0.0' + s.version = '2.0.0' s.license = {:type => 'Apache 2.0'} s.summary = 'iOS SDK for Picovoice\'s Koala Noise Suppression Engine' s.description = @@ -18,7 +18,7 @@ Pod::Spec.new do |s| DESC s.homepage = 'https://github.com/Picovoice/koala/tree/main/binding/ios' s.author = { 'Picovoice' => 'hello@picovoice.ai' } - s.source = { :git => "https://github.com/Picovoice/koala.git", :tag => "Koala-iOS-v1.0.0" } + s.source = { :git => "https://github.com/Picovoice/koala.git", :tag => "Koala-iOS-v2.0.0" } s.ios.deployment_target = '11.0' s.swift_version = '5.0' s.vendored_frameworks = 'lib/ios/PvKoala.xcframework' diff --git a/binding/ios/Koala.swift b/binding/ios/Koala.swift index 0f9a03e..27cad5e 100644 --- a/binding/ios/Koala.swift +++ b/binding/ios/Koala.swift @@ -44,6 +44,12 @@ public class Koala { /// streams of audio data, this delay specifies the time shift between the input and output stream. public var delaySample: UInt32 = 0 + private static var sdk = "ios" + + public static func setSdk(sdk: String) { + self.sdk = sdk + } + /// Constructor. /// /// - Parameters: @@ -70,18 +76,22 @@ public class Koala { modelPathArg = try getResourcePath(modelPathArg!) } + pv_set_sdk(Koala.sdk) + var status = pv_koala_init( accessKey, modelPathArg, &self.handle) if status != PV_STATUS_SUCCESS { - throw pvStatusToKoalaError(status, "Koala init failed") + let messageStack = try getMessageStack() + throw pvStatusToKoalaError(status, "Koala init failed", messageStack) } var cDelaySample: Int32 = 0 status = pv_koala_delay_sample(self.handle, &cDelaySample) if status != PV_STATUS_SUCCESS { - throw pvStatusToKoalaError(status, "Failed to get Koala delay sample") + let messageStack = try getMessageStack() + throw pvStatusToKoalaError(status, "Failed to get Koala delay sample", messageStack) } self.delaySample = UInt32(cDelaySample) } @@ -141,7 +151,8 @@ public class Koala { var enhancedPcm = [Int16](repeating: 0, count: Int(Koala.frameLength)) let status = pv_koala_process(self.handle, pcm, &enhancedPcm[0]) if status != PV_STATUS_SUCCESS { - throw pvStatusToKoalaError(status, "Koala process failed") + let messageStack = try getMessageStack() + throw pvStatusToKoalaError(status, "Koala process failed", messageStack) } return enhancedPcm @@ -158,7 +169,8 @@ public class Koala { let status = pv_koala_reset(self.handle) if status != PV_STATUS_SUCCESS { - throw pvStatusToKoalaError(status, "Koala process failed") + let messageStack = try getMessageStack() + throw pvStatusToKoalaError(status, "Koala process failed", messageStack) } } @@ -181,33 +193,54 @@ public class Koala { """) } - private func pvStatusToKoalaError(_ status: pv_status_t, _ message: String) -> KoalaError { + private func pvStatusToKoalaError( + _ status: pv_status_t, + _ message: String, + _ messageStack: [String] = []) -> KoalaError { switch status { case PV_STATUS_OUT_OF_MEMORY: - return KoalaMemoryError(message) + return KoalaMemoryError(message, messageStack) case PV_STATUS_IO_ERROR: - return KoalaIOError(message) + return KoalaIOError(message, messageStack) case PV_STATUS_INVALID_ARGUMENT: - return KoalaInvalidArgumentError(message) + return KoalaInvalidArgumentError(message, messageStack) case PV_STATUS_STOP_ITERATION: - return KoalaStopIterationError(message) + return KoalaStopIterationError(message, messageStack) case PV_STATUS_KEY_ERROR: - return KoalaKeyError(message) + return KoalaKeyError(message, messageStack) case PV_STATUS_INVALID_STATE: - return KoalaInvalidStateError(message) + return KoalaInvalidStateError(message, messageStack) case PV_STATUS_RUNTIME_ERROR: - return KoalaRuntimeError(message) + return KoalaRuntimeError(message, messageStack) case PV_STATUS_ACTIVATION_ERROR: - return KoalaActivationError(message) + return KoalaActivationError(message, messageStack) case PV_STATUS_ACTIVATION_LIMIT_REACHED: - return KoalaActivationLimitError(message) + return KoalaActivationLimitError(message, messageStack) case PV_STATUS_ACTIVATION_THROTTLED: - return KoalaActivationThrottledError(message) + return KoalaActivationThrottledError(message, messageStack) case PV_STATUS_ACTIVATION_REFUSED: - return KoalaActivationRefusedError(message) + return KoalaActivationRefusedError(message, messageStack) default: let pvStatusString = String(cString: pv_status_to_string(status)) - return KoalaError("\(pvStatusString): \(message)") + return KoalaError("\(pvStatusString): \(message)", messageStack) + } + } + + private func getMessageStack() throws -> [String] { + var messageStackRef: UnsafeMutablePointer?>? + var messageStackDepth: Int32 = 0 + let status = pv_get_error_stack(&messageStackRef, &messageStackDepth) + if status != PV_STATUS_SUCCESS { + throw pvStatusToKoalaError(status, "Unable to get Koala error state") + } + + var messageStack: [String] = [] + for i in 0.. 1.0.0' + pod 'Koala-iOS', :podspec => 'https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec' end target 'KoalaAppTestUITests' do - pod 'Koala-iOS', '~> 1.0.0' + pod 'Koala-iOS', :podspec => 'https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec' end target 'PerformanceTest' do - pod 'Koala-iOS', '~> 1.0.0' + pod 'Koala-iOS', :podspec => 'https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec' end diff --git a/binding/ios/KoalaAppTest/Podfile.lock b/binding/ios/KoalaAppTest/Podfile.lock index d899a00..debc9fb 100644 --- a/binding/ios/KoalaAppTest/Podfile.lock +++ b/binding/ios/KoalaAppTest/Podfile.lock @@ -1,16 +1,21 @@ PODS: - - Koala-iOS (1.0.0) + - Koala-iOS (2.0.0) DEPENDENCIES: - - Koala-iOS (~> 1.0.0) + - Koala-iOS (from `https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec`) -SPEC REPOS: - trunk: - - Koala-iOS +EXTERNAL SOURCES: + Koala-iOS: + :podspec: https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec + +CHECKOUT OPTIONS: + Koala-iOS: + :commit: 82b588b19cb7225222853f7709f9e5de20415b47 + :git: https://github.com/Picovoice/koala.git SPEC CHECKSUMS: - Koala-iOS: 98ccd64b2531c57a0380dae47ea4105c4c5ae641 + Koala-iOS: 865994d8e18b03854f2b933ec9645915ba95f189 -PODFILE CHECKSUM: 1973a21901d505bae8a4a3f3777bd9df4b434bda +PODFILE CHECKSUM: aa02120478c1d3dd9e8085db3379479143edbc02 -COCOAPODS: 1.11.2 +COCOAPODS: 1.11.3 diff --git a/binding/ios/KoalaErrors.swift b/binding/ios/KoalaErrors.swift index 1aba76b..e71b9b8 100644 --- a/binding/ios/KoalaErrors.swift +++ b/binding/ios/KoalaErrors.swift @@ -9,13 +9,22 @@ public class KoalaError: LocalizedError { private let message: String + private let messageStack: [String] - public init (_ message: String) { + public init (_ message: String, _ messageStack: [String] = []) { self.message = message + self.messageStack = messageStack } public var errorDescription: String? { - return message + var messageString = message + if messageStack.count > 0 { + messageString += ":" + for i in 0.. 1.0.0' + pod 'Koala-iOS', :podspec => 'https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec' pod 'ios-voice-processor', '~> 1.1.0' end diff --git a/demo/ios/KoalaDemo/Podfile.lock b/demo/ios/KoalaDemo/Podfile.lock index d58ac25..d168322 100644 --- a/demo/ios/KoalaDemo/Podfile.lock +++ b/demo/ios/KoalaDemo/Podfile.lock @@ -1,20 +1,28 @@ PODS: - ios-voice-processor (1.1.0) - - Koala-iOS (1.0.0) + - Koala-iOS (2.0.0) DEPENDENCIES: - ios-voice-processor (~> 1.1.0) - - Koala-iOS (~> 1.0.0) + - Koala-iOS (from `https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec`) SPEC REPOS: trunk: - ios-voice-processor - - Koala-iOS + +EXTERNAL SOURCES: + Koala-iOS: + :podspec: https://raw.githubusercontent.com/Picovoice/koala/v2.0-ios/binding/ios/Koala-iOS.podspec + +CHECKOUT OPTIONS: + Koala-iOS: + :commit: 9ea3024bbf5a91ad3ec558d23c64c936bcebf623 + :git: https://github.com/Picovoice/koala.git SPEC CHECKSUMS: ios-voice-processor: 8e32d7f980a06d392d128ef1cd19cf6ddcaca3c1 - Koala-iOS: 98ccd64b2531c57a0380dae47ea4105c4c5ae641 + Koala-iOS: 865994d8e18b03854f2b933ec9645915ba95f189 -PODFILE CHECKSUM: 0e642f89b04c02a356a72938e8737b9f102378c0 +PODFILE CHECKSUM: 0f89a64b9647d42bf16b4915aa88de8d933489b8 COCOAPODS: 1.11.3 diff --git a/lib/ios/PvKoala.xcframework/ios-arm64/PvKoala.framework/Headers/picovoice.h b/lib/ios/PvKoala.xcframework/ios-arm64/PvKoala.framework/Headers/picovoice.h index 886558d..3f13d70 100644 --- a/lib/ios/PvKoala.xcframework/ios-arm64/PvKoala.framework/Headers/picovoice.h +++ b/lib/ios/PvKoala.xcframework/ios-arm64/PvKoala.framework/Headers/picovoice.h @@ -77,6 +77,8 @@ PV_API pv_status_t pv_get_error_stack( */ PV_API void pv_free_error_stack(char **message_stack); +PV_API void pv_set_sdk(const char *sdk); + #ifdef __cplusplus } diff --git a/lib/ios/PvKoala.xcframework/ios-arm64_x86_64-simulator/PvKoala.framework/Headers/picovoice.h b/lib/ios/PvKoala.xcframework/ios-arm64_x86_64-simulator/PvKoala.framework/Headers/picovoice.h index 886558d..3f13d70 100644 --- a/lib/ios/PvKoala.xcframework/ios-arm64_x86_64-simulator/PvKoala.framework/Headers/picovoice.h +++ b/lib/ios/PvKoala.xcframework/ios-arm64_x86_64-simulator/PvKoala.framework/Headers/picovoice.h @@ -77,6 +77,8 @@ PV_API pv_status_t pv_get_error_stack( */ PV_API void pv_free_error_stack(char **message_stack); +PV_API void pv_set_sdk(const char *sdk); + #ifdef __cplusplus }