diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj new file mode 100644 index 00000000..bc9dc93f --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj @@ -0,0 +1,622 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + C924F32E29DDAC0B00A440A5 /* SherpaOnnxApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */; }; + C924F33029DDAC0B00A440A5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F32F29DDAC0B00A440A5 /* ContentView.swift */; }; + C924F33229DDAC0D00A440A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C924F33129DDAC0D00A440A5 /* Assets.xcassets */; }; + C924F33529DDAC0D00A440A5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */; }; + C924F33F29DDAC0D00A440A5 /* SherpaOnnxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */; }; + C924F34929DDAC0D00A440A5 /* SherpaOnnxUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */; }; + C924F34B29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */; }; + C924F35929DDACED00A440A5 /* SherpaOnnx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F35829DDACED00A440A5 /* SherpaOnnx.swift */; }; + C924F35C29DDAE4000A440A5 /* sherpa-onnx.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */; }; + C924F35E29DDAE8200A440A5 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F35D29DDAE8200A440A5 /* Model.swift */; }; + C924F36029DDB05D00A440A5 /* onnxruntime.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */; }; + C924F36229DDB15D00A440A5 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F36129DDB15D00A440A5 /* Extension.swift */; }; + C924F36429DDB1D500A440A5 /* SherpaOnnxViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + C924F33B29DDAC0D00A440A5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C924F32229DDAC0B00A440A5 /* Project object */; + proxyType = 1; + remoteGlobalIDString = C924F32929DDAC0B00A440A5; + remoteInfo = SherpaOnnx; + }; + C924F34529DDAC0D00A440A5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = C924F32229DDAC0B00A440A5 /* Project object */; + proxyType = 1; + remoteGlobalIDString = C924F32929DDAC0B00A440A5; + remoteInfo = SherpaOnnx; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SherpaOnnx.app; sourceTree = BUILT_PRODUCTS_DIR; }; + C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxApp.swift; sourceTree = ""; }; + C924F32F29DDAC0B00A440A5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + C924F33129DDAC0D00A440A5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SherpaOnnxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxTests.swift; sourceTree = ""; }; + C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SherpaOnnxUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxUITests.swift; sourceTree = ""; }; + C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxUITestsLaunchTests.swift; sourceTree = ""; }; + C924F35729DDACED00A440A5 /* SherpaOnnx-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "SherpaOnnx-Bridging-Header.h"; path = "../../../swift-api-examples/SherpaOnnx-Bridging-Header.h"; sourceTree = ""; }; + C924F35829DDACED00A440A5 /* SherpaOnnx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SherpaOnnx.swift; path = "../../../swift-api-examples/SherpaOnnx.swift"; sourceTree = ""; }; + C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = "sherpa-onnx.xcframework"; path = "../../build-ios/sherpa-onnx.xcframework"; sourceTree = ""; }; + C924F35D29DDAE8200A440A5 /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; + C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = onnxruntime.xcframework; path = "../../build-ios/ios-onnxruntime/onnxruntime.xcframework"; sourceTree = ""; }; + C924F36129DDB15D00A440A5 /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; }; + C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SherpaOnnxViewModel.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C924F32729DDAC0B00A440A5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C924F36029DDB05D00A440A5 /* onnxruntime.xcframework in Frameworks */, + C924F35C29DDAE4000A440A5 /* sherpa-onnx.xcframework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F33729DDAC0D00A440A5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F34129DDAC0D00A440A5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C924F32129DDAC0B00A440A5 = { + isa = PBXGroup; + children = ( + C924F32C29DDAC0B00A440A5 /* SherpaOnnx */, + C924F33D29DDAC0D00A440A5 /* SherpaOnnxTests */, + C924F34729DDAC0D00A440A5 /* SherpaOnnxUITests */, + C924F32B29DDAC0B00A440A5 /* Products */, + C924F35A29DDAE3F00A440A5 /* Frameworks */, + ); + sourceTree = ""; + }; + C924F32B29DDAC0B00A440A5 /* Products */ = { + isa = PBXGroup; + children = ( + C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */, + C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */, + C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + C924F32C29DDAC0B00A440A5 /* SherpaOnnx */ = { + isa = PBXGroup; + children = ( + C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */, + C924F36129DDB15D00A440A5 /* Extension.swift */, + C924F35D29DDAE8200A440A5 /* Model.swift */, + C924F35729DDACED00A440A5 /* SherpaOnnx-Bridging-Header.h */, + C924F35829DDACED00A440A5 /* SherpaOnnx.swift */, + C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */, + C924F32F29DDAC0B00A440A5 /* ContentView.swift */, + C924F33129DDAC0D00A440A5 /* Assets.xcassets */, + C924F33329DDAC0D00A440A5 /* Preview Content */, + ); + path = SherpaOnnx; + sourceTree = ""; + }; + C924F33329DDAC0D00A440A5 /* Preview Content */ = { + isa = PBXGroup; + children = ( + C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + C924F33D29DDAC0D00A440A5 /* SherpaOnnxTests */ = { + isa = PBXGroup; + children = ( + C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */, + ); + path = SherpaOnnxTests; + sourceTree = ""; + }; + C924F34729DDAC0D00A440A5 /* SherpaOnnxUITests */ = { + isa = PBXGroup; + children = ( + C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */, + C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */, + ); + path = SherpaOnnxUITests; + sourceTree = ""; + }; + C924F35A29DDAE3F00A440A5 /* Frameworks */ = { + isa = PBXGroup; + children = ( + C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */, + C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C924F32929DDAC0B00A440A5 /* SherpaOnnx */ = { + isa = PBXNativeTarget; + buildConfigurationList = C924F34E29DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnx" */; + buildPhases = ( + C924F32629DDAC0B00A440A5 /* Sources */, + C924F32729DDAC0B00A440A5 /* Frameworks */, + C924F32829DDAC0B00A440A5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SherpaOnnx; + productName = SherpaOnnx; + productReference = C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */; + productType = "com.apple.product-type.application"; + }; + C924F33929DDAC0D00A440A5 /* SherpaOnnxTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = C924F35129DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxTests" */; + buildPhases = ( + C924F33629DDAC0D00A440A5 /* Sources */, + C924F33729DDAC0D00A440A5 /* Frameworks */, + C924F33829DDAC0D00A440A5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C924F33C29DDAC0D00A440A5 /* PBXTargetDependency */, + ); + name = SherpaOnnxTests; + productName = SherpaOnnxTests; + productReference = C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + C924F34329DDAC0D00A440A5 /* SherpaOnnxUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = C924F35429DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxUITests" */; + buildPhases = ( + C924F34029DDAC0D00A440A5 /* Sources */, + C924F34129DDAC0D00A440A5 /* Frameworks */, + C924F34229DDAC0D00A440A5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + C924F34629DDAC0D00A440A5 /* PBXTargetDependency */, + ); + name = SherpaOnnxUITests; + productName = SherpaOnnxUITests; + productReference = C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C924F32229DDAC0B00A440A5 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1420; + LastUpgradeCheck = 1420; + TargetAttributes = { + C924F32929DDAC0B00A440A5 = { + CreatedOnToolsVersion = 14.2; + }; + C924F33929DDAC0D00A440A5 = { + CreatedOnToolsVersion = 14.2; + TestTargetID = C924F32929DDAC0B00A440A5; + }; + C924F34329DDAC0D00A440A5 = { + CreatedOnToolsVersion = 14.2; + TestTargetID = C924F32929DDAC0B00A440A5; + }; + }; + }; + buildConfigurationList = C924F32529DDAC0B00A440A5 /* Build configuration list for PBXProject "SherpaOnnx" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = C924F32129DDAC0B00A440A5; + productRefGroup = C924F32B29DDAC0B00A440A5 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C924F32929DDAC0B00A440A5 /* SherpaOnnx */, + C924F33929DDAC0D00A440A5 /* SherpaOnnxTests */, + C924F34329DDAC0D00A440A5 /* SherpaOnnxUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + C924F32829DDAC0B00A440A5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C924F33529DDAC0D00A440A5 /* Preview Assets.xcassets in Resources */, + C924F33229DDAC0D00A440A5 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F33829DDAC0D00A440A5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F34229DDAC0D00A440A5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + C924F32629DDAC0B00A440A5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C924F36229DDB15D00A440A5 /* Extension.swift in Sources */, + C924F33029DDAC0B00A440A5 /* ContentView.swift in Sources */, + C924F35929DDACED00A440A5 /* SherpaOnnx.swift in Sources */, + C924F32E29DDAC0B00A440A5 /* SherpaOnnxApp.swift in Sources */, + C924F36429DDB1D500A440A5 /* SherpaOnnxViewModel.swift in Sources */, + C924F35E29DDAE8200A440A5 /* Model.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F33629DDAC0D00A440A5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C924F33F29DDAC0D00A440A5 /* SherpaOnnxTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + C924F34029DDAC0D00A440A5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C924F34B29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift in Sources */, + C924F34929DDAC0D00A440A5 /* SherpaOnnxUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + C924F33C29DDAC0D00A440A5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C924F32929DDAC0B00A440A5 /* SherpaOnnx */; + targetProxy = C924F33B29DDAC0D00A440A5 /* PBXContainerItemProxy */; + }; + C924F34629DDAC0D00A440A5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = C924F32929DDAC0B00A440A5 /* SherpaOnnx */; + targetProxy = C924F34529DDAC0D00A440A5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + C924F34C29DDAC0D00A440A5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + C924F34D29DDAC0D00A440A5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + C924F34F29DDAC0D00A440A5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnx/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios/sherpa-onnx.xcframework/Headers/"; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = "-lc++"; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnx"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + C924F35029DDAC0D00A440A5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnx/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios/sherpa-onnx.xcframework/Headers/"; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = "-lc++"; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnx"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + C924F35229DDAC0D00A440A5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SherpaOnnx.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/SherpaOnnx"; + }; + name = Debug; + }; + C924F35329DDAC0D00A440A5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 16.2; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SherpaOnnx.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/SherpaOnnx"; + }; + name = Release; + }; + C924F35529DDAC0D00A440A5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxUITests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = SherpaOnnx; + }; + name = Debug; + }; + C924F35629DDAC0D00A440A5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxUITests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = SherpaOnnx; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C924F32529DDAC0B00A440A5 /* Build configuration list for PBXProject "SherpaOnnx" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C924F34C29DDAC0D00A440A5 /* Debug */, + C924F34D29DDAC0D00A440A5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C924F34E29DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnx" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C924F34F29DDAC0D00A440A5 /* Debug */, + C924F35029DDAC0D00A440A5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C924F35129DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C924F35229DDAC0D00A440A5 /* Debug */, + C924F35329DDAC0D00A440A5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C924F35429DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C924F35529DDAC0D00A440A5 /* Debug */, + C924F35629DDAC0D00A440A5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C924F32229DDAC0B00A440A5 /* Project object */; +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcuserdata/fangjun.xcuserdatad/UserInterfaceState.xcuserstate b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcuserdata/fangjun.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..0d703c0b Binary files /dev/null and b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.xcworkspace/xcuserdata/fangjun.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/xcuserdata/fangjun.xcuserdatad/xcschemes/xcschememanagement.plist b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/xcuserdata/fangjun.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..4f6d363e --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/xcuserdata/fangjun.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + SherpaOnnx.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AccentColor.colorset/Contents.json b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..94b3d5c0 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images" : [ + { + "filename" : "k2-1024x1024.png", + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/k2-1024x1024.png b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/k2-1024x1024.png new file mode 100644 index 00000000..6e8f833e Binary files /dev/null and b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/AppIcon.appiconset/k2-1024x1024.png differ diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/Contents.json b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/ContentView.swift b/ios-swiftui/SherpaOnnx/SherpaOnnx/ContentView.swift new file mode 100644 index 00000000..1986f30f --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/ContentView.swift @@ -0,0 +1,46 @@ +// +// ContentView.swift +// SherpaOnnx +// +// Created by fangjun on 2023/4/5. +// + +import SwiftUI + +struct ContentView: View { + @StateObject var sherpaOnnxVM = SherpaOnnxViewModel() + + var body: some View { + VStack { + Text("ASR with Next-gen Kaldi") + .font(.title) + if sherpaOnnxVM.status == .stop { + Text("See https://github.com/k2-fsa/sherpa-onnx") + Text("Press the Start button to run!") + } + ScrollView(.vertical, showsIndicators: true) { + HStack { + Text(sherpaOnnxVM.subtitles) + Spacer() + } + } + Spacer() + Button { + toggleRecorder() + } label: { + Text(sherpaOnnxVM.status == .stop ? "Start" : "Stop") + } + } + .padding() + } + + private func toggleRecorder() { + sherpaOnnxVM.toggleRecorder() + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView() + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Extension.swift b/ios-swiftui/SherpaOnnx/SherpaOnnx/Extension.swift new file mode 100644 index 00000000..bb0edad3 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Extension.swift @@ -0,0 +1,20 @@ +// +// Extension.swift +// SherpaOnnx +// +// Created by knight on 2023/4/5. +// + +import AVFoundation + +extension AudioBuffer { + func array() -> [Float] { + return Array(UnsafeBufferPointer(self)) + } +} + +extension AVAudioPCMBuffer { + func array() -> [Float] { + return self.audioBufferList.pointee.mBuffers.array() + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Model.swift b/ios-swiftui/SherpaOnnx/SherpaOnnx/Model.swift new file mode 100644 index 00000000..6c5b5999 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Model.swift @@ -0,0 +1,35 @@ +import Foundation + +func getResource(_ forResource: String, _ ofType: String) -> String { + let path = Bundle.main.path(forResource: forResource, ofType: ofType) + precondition( + path != nil, + "\(forResource).\(ofType) does not exist!\n" + "Remember to change \n" + + " Build Phases -> Copy Bundle Resources\n" + "to add it!" + ) + return path! +} +/// Please refer to +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html +/// to download pre-trained models + +/// sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 (Bilingual, Chinese + English) +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/zipformer-transducer-models.html +func getBilingualStreamZhEnZipformer20230220() -> SherpaOnnxOnlineTransducerModelConfig { + let encoder = getResource("encoder-epoch-99-avg-1", "onnx") + let decoder = getResource("decoder-epoch-99-avg-1", "onnx") + let joiner = getResource("joiner-epoch-99-avg-1", "onnx") + let tokens = getResource("tokens", "txt") + + return sherpaOnnxOnlineTransducerModelConfig( + encoder: encoder, + decoder: decoder, + joiner: joiner, + tokens: tokens, + numThreads: 2 + ) +} + +/// Please refer to +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html +/// to add more models if you need diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/Preview Content/Preview Assets.xcassets/Contents.json b/ios-swiftui/SherpaOnnx/SherpaOnnx/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxApp.swift b/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxApp.swift new file mode 100644 index 00000000..fb091c1b --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxApp.swift @@ -0,0 +1,17 @@ +// +// SherpaOnnxApp.swift +// SherpaOnnx +// +// Created by fangjun on 2023/4/5. +// + +import SwiftUI + +@main +struct SherpaOnnxApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxViewModel.swift b/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxViewModel.swift new file mode 100644 index 00000000..e2b9c5bf --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxViewModel.swift @@ -0,0 +1,182 @@ +// +// SherpaOnnxViewModel.swift +// SherpaOnnx +// +// Created by knight on 2023/4/5. +// + +import Foundation +import AVFoundation + +enum Status { + case stop + case recording +} + +class SherpaOnnxViewModel: ObservableObject { + @Published var status: Status = .stop + @Published var subtitles: String = "" + + var sentences: [String] = [] + + var audioEngine: AVAudioEngine? = nil + var recognizer: SherpaOnnxRecognizer! = nil + + var lastSentence: String = "" + let maxSentence: Int = 20 + + var results: String { + if sentences.isEmpty && lastSentence.isEmpty { + return "" + } + if sentences.isEmpty { + return "0: \(lastSentence.lowercased())" + } + + let start = max(sentences.count - maxSentence, 0) + if lastSentence.isEmpty { + return sentences.enumerated().map { (index, s) in "\(index): \(s.lowercased())" }[start...] + .joined(separator: "\n") + } else { + return sentences.enumerated().map { (index, s) in "\(index): \(s.lowercased())" }[start...] + .joined(separator: "\n") + "\n\(sentences.count): \(lastSentence.lowercased())" + } + } + + func updateLabel() { + DispatchQueue.main.async { + self.subtitles = self.results + } + } + + init() { + initRecognizer() + initRecorder() + } + + private func initRecognizer() { + // Please select one model that is best suitable for you. + // + // You can also modify Model.swift to add new pre-trained models from + // https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html + let modelConfig = getBilingualStreamZhEnZipformer20230220() + + let featConfig = sherpaOnnxFeatureConfig( + sampleRate: 16000, + featureDim: 80) + + var config = sherpaOnnxOnlineRecognizerConfig( + featConfig: featConfig, + modelConfig: modelConfig, + enableEndpoint: true, + rule1MinTrailingSilence: 2.4, + rule2MinTrailingSilence: 0.8, + rule3MinUtteranceLength: 30, + decodingMethod: "greedy_search", + maxActivePaths: 4 + ) + recognizer = SherpaOnnxRecognizer(config: &config) + } + + private func initRecorder() { + print("init recorder") + audioEngine = AVAudioEngine() + let inputNode = self.audioEngine?.inputNode + let bus = 0 + let inputFormat = inputNode?.outputFormat(forBus: bus) + let outputFormat = AVAudioFormat( + commonFormat: .pcmFormatFloat32, + sampleRate: 16000, channels: 1, + interleaved: false)! + + let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)! + + inputNode!.installTap( + onBus: bus, + bufferSize: 1024, + format: inputFormat + ) { + (buffer: AVAudioPCMBuffer, when: AVAudioTime) in + var newBufferAvailable = true + + let inputCallback: AVAudioConverterInputBlock = { + inNumPackets, outStatus in + if newBufferAvailable { + outStatus.pointee = .haveData + newBufferAvailable = false + + return buffer + } else { + outStatus.pointee = .noDataNow + return nil + } + } + + let convertedBuffer = AVAudioPCMBuffer( + pcmFormat: outputFormat, + frameCapacity: + AVAudioFrameCount(outputFormat.sampleRate) + * buffer.frameLength + / AVAudioFrameCount(buffer.format.sampleRate))! + + var error: NSError? + let _ = converter.convert( + to: convertedBuffer, + error: &error, withInputFrom: inputCallback) + + // TODO(fangjun): Handle status != haveData + + let array = convertedBuffer.array() + if !array.isEmpty { + self.recognizer.acceptWaveform(samples: array) + while (self.recognizer.isReady()){ + self.recognizer.decode() + } + let isEndpoint = self.recognizer.isEndpoint() + let text = self.recognizer.getResult().text + + if !text.isEmpty && self.lastSentence != text { + self.lastSentence = text + self.updateLabel() + print(text) + } + + if isEndpoint{ + if !text.isEmpty { + let tmp = self.lastSentence + self.lastSentence = "" + self.sentences.append(tmp) + } + self.recognizer.reset() + } + } + } + } + + public func toggleRecorder() { + if status == .stop { + startRecorder() + status = .recording + } else { + stopRecorder() + status = .stop + } + } + + private func startRecorder() { + lastSentence = "" + sentences = [] + + do { + try self.audioEngine?.start() + } catch let error as NSError { + print("Got an error starting audioEngine: \(error.domain), \(error)") + } + print("started") + } + + private func stopRecorder() { + audioEngine?.stop() + print("stopped") + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnx/k2-1024x1024.png b/ios-swiftui/SherpaOnnx/SherpaOnnx/k2-1024x1024.png new file mode 100644 index 00000000..6e8f833e Binary files /dev/null and b/ios-swiftui/SherpaOnnx/SherpaOnnx/k2-1024x1024.png differ diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnxTests/SherpaOnnxTests.swift b/ios-swiftui/SherpaOnnx/SherpaOnnxTests/SherpaOnnxTests.swift new file mode 100644 index 00000000..a3287a3e --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnxTests/SherpaOnnxTests.swift @@ -0,0 +1,36 @@ +// +// SherpaOnnxTests.swift +// SherpaOnnxTests +// +// Created by fangjun on 2023/4/5. +// + +import XCTest +@testable import SherpaOnnx + +final class SherpaOnnxTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITests.swift b/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITests.swift new file mode 100644 index 00000000..60ad0b6e --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITests.swift @@ -0,0 +1,41 @@ +// +// SherpaOnnxUITests.swift +// SherpaOnnxUITests +// +// Created by fangjun on 2023/4/5. +// + +import XCTest + +final class SherpaOnnxUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITestsLaunchTests.swift b/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITestsLaunchTests.swift new file mode 100644 index 00000000..359e4530 --- /dev/null +++ b/ios-swiftui/SherpaOnnx/SherpaOnnxUITests/SherpaOnnxUITestsLaunchTests.swift @@ -0,0 +1,32 @@ +// +// SherpaOnnxUITestsLaunchTests.swift +// SherpaOnnxUITests +// +// Created by fangjun on 2023/4/5. +// + +import XCTest + +final class SherpaOnnxUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +}