Fangjun Kuang
Committed by GitHub

Add SwiftUI demo project (#118)

* Commit after creating the project

* Add sherpa-onnx related files

* copy and modify files from sherpa-ncnn

* add app icon
  1 +// !$*UTF8*$!
  2 +{
  3 + archiveVersion = 1;
  4 + classes = {
  5 + };
  6 + objectVersion = 56;
  7 + objects = {
  8 +
  9 +/* Begin PBXBuildFile section */
  10 + C924F32E29DDAC0B00A440A5 /* SherpaOnnxApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */; };
  11 + C924F33029DDAC0B00A440A5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F32F29DDAC0B00A440A5 /* ContentView.swift */; };
  12 + C924F33229DDAC0D00A440A5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C924F33129DDAC0D00A440A5 /* Assets.xcassets */; };
  13 + C924F33529DDAC0D00A440A5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */; };
  14 + C924F33F29DDAC0D00A440A5 /* SherpaOnnxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */; };
  15 + C924F34929DDAC0D00A440A5 /* SherpaOnnxUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */; };
  16 + C924F34B29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */; };
  17 + C924F35929DDACED00A440A5 /* SherpaOnnx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F35829DDACED00A440A5 /* SherpaOnnx.swift */; };
  18 + C924F35C29DDAE4000A440A5 /* sherpa-onnx.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */; };
  19 + C924F35E29DDAE8200A440A5 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F35D29DDAE8200A440A5 /* Model.swift */; };
  20 + C924F36029DDB05D00A440A5 /* onnxruntime.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */; };
  21 + C924F36229DDB15D00A440A5 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F36129DDB15D00A440A5 /* Extension.swift */; };
  22 + C924F36429DDB1D500A440A5 /* SherpaOnnxViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */; };
  23 +/* End PBXBuildFile section */
  24 +
  25 +/* Begin PBXContainerItemProxy section */
  26 + C924F33B29DDAC0D00A440A5 /* PBXContainerItemProxy */ = {
  27 + isa = PBXContainerItemProxy;
  28 + containerPortal = C924F32229DDAC0B00A440A5 /* Project object */;
  29 + proxyType = 1;
  30 + remoteGlobalIDString = C924F32929DDAC0B00A440A5;
  31 + remoteInfo = SherpaOnnx;
  32 + };
  33 + C924F34529DDAC0D00A440A5 /* PBXContainerItemProxy */ = {
  34 + isa = PBXContainerItemProxy;
  35 + containerPortal = C924F32229DDAC0B00A440A5 /* Project object */;
  36 + proxyType = 1;
  37 + remoteGlobalIDString = C924F32929DDAC0B00A440A5;
  38 + remoteInfo = SherpaOnnx;
  39 + };
  40 +/* End PBXContainerItemProxy section */
  41 +
  42 +/* Begin PBXFileReference section */
  43 + C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SherpaOnnx.app; sourceTree = BUILT_PRODUCTS_DIR; };
  44 + C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxApp.swift; sourceTree = "<group>"; };
  45 + C924F32F29DDAC0B00A440A5 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
  46 + C924F33129DDAC0D00A440A5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
  47 + C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
  48 + C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SherpaOnnxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
  49 + C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxTests.swift; sourceTree = "<group>"; };
  50 + C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SherpaOnnxUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
  51 + C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxUITests.swift; sourceTree = "<group>"; };
  52 + C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SherpaOnnxUITestsLaunchTests.swift; sourceTree = "<group>"; };
  53 + 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 = "<group>"; };
  54 + C924F35829DDACED00A440A5 /* SherpaOnnx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SherpaOnnx.swift; path = "../../../swift-api-examples/SherpaOnnx.swift"; sourceTree = "<group>"; };
  55 + C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = "sherpa-onnx.xcframework"; path = "../../build-ios/sherpa-onnx.xcframework"; sourceTree = "<group>"; };
  56 + C924F35D29DDAE8200A440A5 /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = "<group>"; };
  57 + C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = onnxruntime.xcframework; path = "../../build-ios/ios-onnxruntime/onnxruntime.xcframework"; sourceTree = "<group>"; };
  58 + C924F36129DDB15D00A440A5 /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
  59 + C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SherpaOnnxViewModel.swift; sourceTree = "<group>"; };
  60 +/* End PBXFileReference section */
  61 +
  62 +/* Begin PBXFrameworksBuildPhase section */
  63 + C924F32729DDAC0B00A440A5 /* Frameworks */ = {
  64 + isa = PBXFrameworksBuildPhase;
  65 + buildActionMask = 2147483647;
  66 + files = (
  67 + C924F36029DDB05D00A440A5 /* onnxruntime.xcframework in Frameworks */,
  68 + C924F35C29DDAE4000A440A5 /* sherpa-onnx.xcframework in Frameworks */,
  69 + );
  70 + runOnlyForDeploymentPostprocessing = 0;
  71 + };
  72 + C924F33729DDAC0D00A440A5 /* Frameworks */ = {
  73 + isa = PBXFrameworksBuildPhase;
  74 + buildActionMask = 2147483647;
  75 + files = (
  76 + );
  77 + runOnlyForDeploymentPostprocessing = 0;
  78 + };
  79 + C924F34129DDAC0D00A440A5 /* Frameworks */ = {
  80 + isa = PBXFrameworksBuildPhase;
  81 + buildActionMask = 2147483647;
  82 + files = (
  83 + );
  84 + runOnlyForDeploymentPostprocessing = 0;
  85 + };
  86 +/* End PBXFrameworksBuildPhase section */
  87 +
  88 +/* Begin PBXGroup section */
  89 + C924F32129DDAC0B00A440A5 = {
  90 + isa = PBXGroup;
  91 + children = (
  92 + C924F32C29DDAC0B00A440A5 /* SherpaOnnx */,
  93 + C924F33D29DDAC0D00A440A5 /* SherpaOnnxTests */,
  94 + C924F34729DDAC0D00A440A5 /* SherpaOnnxUITests */,
  95 + C924F32B29DDAC0B00A440A5 /* Products */,
  96 + C924F35A29DDAE3F00A440A5 /* Frameworks */,
  97 + );
  98 + sourceTree = "<group>";
  99 + };
  100 + C924F32B29DDAC0B00A440A5 /* Products */ = {
  101 + isa = PBXGroup;
  102 + children = (
  103 + C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */,
  104 + C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */,
  105 + C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */,
  106 + );
  107 + name = Products;
  108 + sourceTree = "<group>";
  109 + };
  110 + C924F32C29DDAC0B00A440A5 /* SherpaOnnx */ = {
  111 + isa = PBXGroup;
  112 + children = (
  113 + C924F36329DDB1D500A440A5 /* SherpaOnnxViewModel.swift */,
  114 + C924F36129DDB15D00A440A5 /* Extension.swift */,
  115 + C924F35D29DDAE8200A440A5 /* Model.swift */,
  116 + C924F35729DDACED00A440A5 /* SherpaOnnx-Bridging-Header.h */,
  117 + C924F35829DDACED00A440A5 /* SherpaOnnx.swift */,
  118 + C924F32D29DDAC0B00A440A5 /* SherpaOnnxApp.swift */,
  119 + C924F32F29DDAC0B00A440A5 /* ContentView.swift */,
  120 + C924F33129DDAC0D00A440A5 /* Assets.xcassets */,
  121 + C924F33329DDAC0D00A440A5 /* Preview Content */,
  122 + );
  123 + path = SherpaOnnx;
  124 + sourceTree = "<group>";
  125 + };
  126 + C924F33329DDAC0D00A440A5 /* Preview Content */ = {
  127 + isa = PBXGroup;
  128 + children = (
  129 + C924F33429DDAC0D00A440A5 /* Preview Assets.xcassets */,
  130 + );
  131 + path = "Preview Content";
  132 + sourceTree = "<group>";
  133 + };
  134 + C924F33D29DDAC0D00A440A5 /* SherpaOnnxTests */ = {
  135 + isa = PBXGroup;
  136 + children = (
  137 + C924F33E29DDAC0D00A440A5 /* SherpaOnnxTests.swift */,
  138 + );
  139 + path = SherpaOnnxTests;
  140 + sourceTree = "<group>";
  141 + };
  142 + C924F34729DDAC0D00A440A5 /* SherpaOnnxUITests */ = {
  143 + isa = PBXGroup;
  144 + children = (
  145 + C924F34829DDAC0D00A440A5 /* SherpaOnnxUITests.swift */,
  146 + C924F34A29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift */,
  147 + );
  148 + path = SherpaOnnxUITests;
  149 + sourceTree = "<group>";
  150 + };
  151 + C924F35A29DDAE3F00A440A5 /* Frameworks */ = {
  152 + isa = PBXGroup;
  153 + children = (
  154 + C924F35F29DDB05D00A440A5 /* onnxruntime.xcframework */,
  155 + C924F35B29DDAE4000A440A5 /* sherpa-onnx.xcframework */,
  156 + );
  157 + name = Frameworks;
  158 + sourceTree = "<group>";
  159 + };
  160 +/* End PBXGroup section */
  161 +
  162 +/* Begin PBXNativeTarget section */
  163 + C924F32929DDAC0B00A440A5 /* SherpaOnnx */ = {
  164 + isa = PBXNativeTarget;
  165 + buildConfigurationList = C924F34E29DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnx" */;
  166 + buildPhases = (
  167 + C924F32629DDAC0B00A440A5 /* Sources */,
  168 + C924F32729DDAC0B00A440A5 /* Frameworks */,
  169 + C924F32829DDAC0B00A440A5 /* Resources */,
  170 + );
  171 + buildRules = (
  172 + );
  173 + dependencies = (
  174 + );
  175 + name = SherpaOnnx;
  176 + productName = SherpaOnnx;
  177 + productReference = C924F32A29DDAC0B00A440A5 /* SherpaOnnx.app */;
  178 + productType = "com.apple.product-type.application";
  179 + };
  180 + C924F33929DDAC0D00A440A5 /* SherpaOnnxTests */ = {
  181 + isa = PBXNativeTarget;
  182 + buildConfigurationList = C924F35129DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxTests" */;
  183 + buildPhases = (
  184 + C924F33629DDAC0D00A440A5 /* Sources */,
  185 + C924F33729DDAC0D00A440A5 /* Frameworks */,
  186 + C924F33829DDAC0D00A440A5 /* Resources */,
  187 + );
  188 + buildRules = (
  189 + );
  190 + dependencies = (
  191 + C924F33C29DDAC0D00A440A5 /* PBXTargetDependency */,
  192 + );
  193 + name = SherpaOnnxTests;
  194 + productName = SherpaOnnxTests;
  195 + productReference = C924F33A29DDAC0D00A440A5 /* SherpaOnnxTests.xctest */;
  196 + productType = "com.apple.product-type.bundle.unit-test";
  197 + };
  198 + C924F34329DDAC0D00A440A5 /* SherpaOnnxUITests */ = {
  199 + isa = PBXNativeTarget;
  200 + buildConfigurationList = C924F35429DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxUITests" */;
  201 + buildPhases = (
  202 + C924F34029DDAC0D00A440A5 /* Sources */,
  203 + C924F34129DDAC0D00A440A5 /* Frameworks */,
  204 + C924F34229DDAC0D00A440A5 /* Resources */,
  205 + );
  206 + buildRules = (
  207 + );
  208 + dependencies = (
  209 + C924F34629DDAC0D00A440A5 /* PBXTargetDependency */,
  210 + );
  211 + name = SherpaOnnxUITests;
  212 + productName = SherpaOnnxUITests;
  213 + productReference = C924F34429DDAC0D00A440A5 /* SherpaOnnxUITests.xctest */;
  214 + productType = "com.apple.product-type.bundle.ui-testing";
  215 + };
  216 +/* End PBXNativeTarget section */
  217 +
  218 +/* Begin PBXProject section */
  219 + C924F32229DDAC0B00A440A5 /* Project object */ = {
  220 + isa = PBXProject;
  221 + attributes = {
  222 + BuildIndependentTargetsInParallel = 1;
  223 + LastSwiftUpdateCheck = 1420;
  224 + LastUpgradeCheck = 1420;
  225 + TargetAttributes = {
  226 + C924F32929DDAC0B00A440A5 = {
  227 + CreatedOnToolsVersion = 14.2;
  228 + };
  229 + C924F33929DDAC0D00A440A5 = {
  230 + CreatedOnToolsVersion = 14.2;
  231 + TestTargetID = C924F32929DDAC0B00A440A5;
  232 + };
  233 + C924F34329DDAC0D00A440A5 = {
  234 + CreatedOnToolsVersion = 14.2;
  235 + TestTargetID = C924F32929DDAC0B00A440A5;
  236 + };
  237 + };
  238 + };
  239 + buildConfigurationList = C924F32529DDAC0B00A440A5 /* Build configuration list for PBXProject "SherpaOnnx" */;
  240 + compatibilityVersion = "Xcode 14.0";
  241 + developmentRegion = en;
  242 + hasScannedForEncodings = 0;
  243 + knownRegions = (
  244 + en,
  245 + Base,
  246 + );
  247 + mainGroup = C924F32129DDAC0B00A440A5;
  248 + productRefGroup = C924F32B29DDAC0B00A440A5 /* Products */;
  249 + projectDirPath = "";
  250 + projectRoot = "";
  251 + targets = (
  252 + C924F32929DDAC0B00A440A5 /* SherpaOnnx */,
  253 + C924F33929DDAC0D00A440A5 /* SherpaOnnxTests */,
  254 + C924F34329DDAC0D00A440A5 /* SherpaOnnxUITests */,
  255 + );
  256 + };
  257 +/* End PBXProject section */
  258 +
  259 +/* Begin PBXResourcesBuildPhase section */
  260 + C924F32829DDAC0B00A440A5 /* Resources */ = {
  261 + isa = PBXResourcesBuildPhase;
  262 + buildActionMask = 2147483647;
  263 + files = (
  264 + C924F33529DDAC0D00A440A5 /* Preview Assets.xcassets in Resources */,
  265 + C924F33229DDAC0D00A440A5 /* Assets.xcassets in Resources */,
  266 + );
  267 + runOnlyForDeploymentPostprocessing = 0;
  268 + };
  269 + C924F33829DDAC0D00A440A5 /* Resources */ = {
  270 + isa = PBXResourcesBuildPhase;
  271 + buildActionMask = 2147483647;
  272 + files = (
  273 + );
  274 + runOnlyForDeploymentPostprocessing = 0;
  275 + };
  276 + C924F34229DDAC0D00A440A5 /* Resources */ = {
  277 + isa = PBXResourcesBuildPhase;
  278 + buildActionMask = 2147483647;
  279 + files = (
  280 + );
  281 + runOnlyForDeploymentPostprocessing = 0;
  282 + };
  283 +/* End PBXResourcesBuildPhase section */
  284 +
  285 +/* Begin PBXSourcesBuildPhase section */
  286 + C924F32629DDAC0B00A440A5 /* Sources */ = {
  287 + isa = PBXSourcesBuildPhase;
  288 + buildActionMask = 2147483647;
  289 + files = (
  290 + C924F36229DDB15D00A440A5 /* Extension.swift in Sources */,
  291 + C924F33029DDAC0B00A440A5 /* ContentView.swift in Sources */,
  292 + C924F35929DDACED00A440A5 /* SherpaOnnx.swift in Sources */,
  293 + C924F32E29DDAC0B00A440A5 /* SherpaOnnxApp.swift in Sources */,
  294 + C924F36429DDB1D500A440A5 /* SherpaOnnxViewModel.swift in Sources */,
  295 + C924F35E29DDAE8200A440A5 /* Model.swift in Sources */,
  296 + );
  297 + runOnlyForDeploymentPostprocessing = 0;
  298 + };
  299 + C924F33629DDAC0D00A440A5 /* Sources */ = {
  300 + isa = PBXSourcesBuildPhase;
  301 + buildActionMask = 2147483647;
  302 + files = (
  303 + C924F33F29DDAC0D00A440A5 /* SherpaOnnxTests.swift in Sources */,
  304 + );
  305 + runOnlyForDeploymentPostprocessing = 0;
  306 + };
  307 + C924F34029DDAC0D00A440A5 /* Sources */ = {
  308 + isa = PBXSourcesBuildPhase;
  309 + buildActionMask = 2147483647;
  310 + files = (
  311 + C924F34B29DDAC0D00A440A5 /* SherpaOnnxUITestsLaunchTests.swift in Sources */,
  312 + C924F34929DDAC0D00A440A5 /* SherpaOnnxUITests.swift in Sources */,
  313 + );
  314 + runOnlyForDeploymentPostprocessing = 0;
  315 + };
  316 +/* End PBXSourcesBuildPhase section */
  317 +
  318 +/* Begin PBXTargetDependency section */
  319 + C924F33C29DDAC0D00A440A5 /* PBXTargetDependency */ = {
  320 + isa = PBXTargetDependency;
  321 + target = C924F32929DDAC0B00A440A5 /* SherpaOnnx */;
  322 + targetProxy = C924F33B29DDAC0D00A440A5 /* PBXContainerItemProxy */;
  323 + };
  324 + C924F34629DDAC0D00A440A5 /* PBXTargetDependency */ = {
  325 + isa = PBXTargetDependency;
  326 + target = C924F32929DDAC0B00A440A5 /* SherpaOnnx */;
  327 + targetProxy = C924F34529DDAC0D00A440A5 /* PBXContainerItemProxy */;
  328 + };
  329 +/* End PBXTargetDependency section */
  330 +
  331 +/* Begin XCBuildConfiguration section */
  332 + C924F34C29DDAC0D00A440A5 /* Debug */ = {
  333 + isa = XCBuildConfiguration;
  334 + buildSettings = {
  335 + ALWAYS_SEARCH_USER_PATHS = NO;
  336 + CLANG_ANALYZER_NONNULL = YES;
  337 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
  338 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
  339 + CLANG_ENABLE_MODULES = YES;
  340 + CLANG_ENABLE_OBJC_ARC = YES;
  341 + CLANG_ENABLE_OBJC_WEAK = YES;
  342 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
  343 + CLANG_WARN_BOOL_CONVERSION = YES;
  344 + CLANG_WARN_COMMA = YES;
  345 + CLANG_WARN_CONSTANT_CONVERSION = YES;
  346 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
  347 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
  348 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
  349 + CLANG_WARN_EMPTY_BODY = YES;
  350 + CLANG_WARN_ENUM_CONVERSION = YES;
  351 + CLANG_WARN_INFINITE_RECURSION = YES;
  352 + CLANG_WARN_INT_CONVERSION = YES;
  353 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  354 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
  355 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
  356 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
  357 + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
  358 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
  359 + CLANG_WARN_STRICT_PROTOTYPES = YES;
  360 + CLANG_WARN_SUSPICIOUS_MOVE = YES;
  361 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
  362 + CLANG_WARN_UNREACHABLE_CODE = YES;
  363 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
  364 + COPY_PHASE_STRIP = NO;
  365 + DEBUG_INFORMATION_FORMAT = dwarf;
  366 + ENABLE_STRICT_OBJC_MSGSEND = YES;
  367 + ENABLE_TESTABILITY = YES;
  368 + GCC_C_LANGUAGE_STANDARD = gnu11;
  369 + GCC_DYNAMIC_NO_PIC = NO;
  370 + GCC_NO_COMMON_BLOCKS = YES;
  371 + GCC_OPTIMIZATION_LEVEL = 0;
  372 + GCC_PREPROCESSOR_DEFINITIONS = (
  373 + "DEBUG=1",
  374 + "$(inherited)",
  375 + );
  376 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
  377 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
  378 + GCC_WARN_UNDECLARED_SELECTOR = YES;
  379 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
  380 + GCC_WARN_UNUSED_FUNCTION = YES;
  381 + GCC_WARN_UNUSED_VARIABLE = YES;
  382 + IPHONEOS_DEPLOYMENT_TARGET = 16.2;
  383 + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
  384 + MTL_FAST_MATH = YES;
  385 + ONLY_ACTIVE_ARCH = YES;
  386 + SDKROOT = iphoneos;
  387 + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
  388 + SWIFT_OPTIMIZATION_LEVEL = "-Onone";
  389 + };
  390 + name = Debug;
  391 + };
  392 + C924F34D29DDAC0D00A440A5 /* Release */ = {
  393 + isa = XCBuildConfiguration;
  394 + buildSettings = {
  395 + ALWAYS_SEARCH_USER_PATHS = NO;
  396 + CLANG_ANALYZER_NONNULL = YES;
  397 + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
  398 + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
  399 + CLANG_ENABLE_MODULES = YES;
  400 + CLANG_ENABLE_OBJC_ARC = YES;
  401 + CLANG_ENABLE_OBJC_WEAK = YES;
  402 + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
  403 + CLANG_WARN_BOOL_CONVERSION = YES;
  404 + CLANG_WARN_COMMA = YES;
  405 + CLANG_WARN_CONSTANT_CONVERSION = YES;
  406 + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
  407 + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
  408 + CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
  409 + CLANG_WARN_EMPTY_BODY = YES;
  410 + CLANG_WARN_ENUM_CONVERSION = YES;
  411 + CLANG_WARN_INFINITE_RECURSION = YES;
  412 + CLANG_WARN_INT_CONVERSION = YES;
  413 + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
  414 + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
  415 + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
  416 + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
  417 + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
  418 + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
  419 + CLANG_WARN_STRICT_PROTOTYPES = YES;
  420 + CLANG_WARN_SUSPICIOUS_MOVE = YES;
  421 + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
  422 + CLANG_WARN_UNREACHABLE_CODE = YES;
  423 + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
  424 + COPY_PHASE_STRIP = NO;
  425 + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
  426 + ENABLE_NS_ASSERTIONS = NO;
  427 + ENABLE_STRICT_OBJC_MSGSEND = YES;
  428 + GCC_C_LANGUAGE_STANDARD = gnu11;
  429 + GCC_NO_COMMON_BLOCKS = YES;
  430 + GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
  431 + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
  432 + GCC_WARN_UNDECLARED_SELECTOR = YES;
  433 + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
  434 + GCC_WARN_UNUSED_FUNCTION = YES;
  435 + GCC_WARN_UNUSED_VARIABLE = YES;
  436 + IPHONEOS_DEPLOYMENT_TARGET = 16.2;
  437 + MTL_ENABLE_DEBUG_INFO = NO;
  438 + MTL_FAST_MATH = YES;
  439 + SDKROOT = iphoneos;
  440 + SWIFT_COMPILATION_MODE = wholemodule;
  441 + SWIFT_OPTIMIZATION_LEVEL = "-O";
  442 + VALIDATE_PRODUCT = YES;
  443 + };
  444 + name = Release;
  445 + };
  446 + C924F34F29DDAC0D00A440A5 /* Debug */ = {
  447 + isa = XCBuildConfiguration;
  448 + buildSettings = {
  449 + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
  450 + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
  451 + CODE_SIGN_STYLE = Automatic;
  452 + CURRENT_PROJECT_VERSION = 1;
  453 + DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnx/Preview Content\"";
  454 + ENABLE_PREVIEWS = YES;
  455 + GENERATE_INFOPLIST_FILE = YES;
  456 + HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios/sherpa-onnx.xcframework/Headers/";
  457 + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
  458 + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
  459 + INFOPLIST_KEY_UILaunchScreen_Generation = YES;
  460 + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
  461 + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
  462 + LD_RUNPATH_SEARCH_PATHS = (
  463 + "$(inherited)",
  464 + "@executable_path/Frameworks",
  465 + );
  466 + MARKETING_VERSION = 1.0;
  467 + OTHER_LDFLAGS = "-lc++";
  468 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnx";
  469 + PRODUCT_NAME = "$(TARGET_NAME)";
  470 + SWIFT_EMIT_LOC_STRINGS = YES;
  471 + SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h";
  472 + SWIFT_VERSION = 5.0;
  473 + TARGETED_DEVICE_FAMILY = "1,2";
  474 + };
  475 + name = Debug;
  476 + };
  477 + C924F35029DDAC0D00A440A5 /* Release */ = {
  478 + isa = XCBuildConfiguration;
  479 + buildSettings = {
  480 + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
  481 + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
  482 + CODE_SIGN_STYLE = Automatic;
  483 + CURRENT_PROJECT_VERSION = 1;
  484 + DEVELOPMENT_ASSET_PATHS = "\"SherpaOnnx/Preview Content\"";
  485 + ENABLE_PREVIEWS = YES;
  486 + GENERATE_INFOPLIST_FILE = YES;
  487 + HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../build-ios/sherpa-onnx.xcframework/Headers/";
  488 + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
  489 + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
  490 + INFOPLIST_KEY_UILaunchScreen_Generation = YES;
  491 + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
  492 + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
  493 + LD_RUNPATH_SEARCH_PATHS = (
  494 + "$(inherited)",
  495 + "@executable_path/Frameworks",
  496 + );
  497 + MARKETING_VERSION = 1.0;
  498 + OTHER_LDFLAGS = "-lc++";
  499 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnx";
  500 + PRODUCT_NAME = "$(TARGET_NAME)";
  501 + SWIFT_EMIT_LOC_STRINGS = YES;
  502 + SWIFT_OBJC_BRIDGING_HEADER = "${PROJECT_DIR}/../../swift-api-examples/SherpaOnnx-Bridging-Header.h";
  503 + SWIFT_VERSION = 5.0;
  504 + TARGETED_DEVICE_FAMILY = "1,2";
  505 + };
  506 + name = Release;
  507 + };
  508 + C924F35229DDAC0D00A440A5 /* Debug */ = {
  509 + isa = XCBuildConfiguration;
  510 + buildSettings = {
  511 + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
  512 + BUNDLE_LOADER = "$(TEST_HOST)";
  513 + CODE_SIGN_STYLE = Automatic;
  514 + CURRENT_PROJECT_VERSION = 1;
  515 + GENERATE_INFOPLIST_FILE = YES;
  516 + IPHONEOS_DEPLOYMENT_TARGET = 16.2;
  517 + MARKETING_VERSION = 1.0;
  518 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTests";
  519 + PRODUCT_NAME = "$(TARGET_NAME)";
  520 + SWIFT_EMIT_LOC_STRINGS = NO;
  521 + SWIFT_VERSION = 5.0;
  522 + TARGETED_DEVICE_FAMILY = "1,2";
  523 + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SherpaOnnx.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/SherpaOnnx";
  524 + };
  525 + name = Debug;
  526 + };
  527 + C924F35329DDAC0D00A440A5 /* Release */ = {
  528 + isa = XCBuildConfiguration;
  529 + buildSettings = {
  530 + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
  531 + BUNDLE_LOADER = "$(TEST_HOST)";
  532 + CODE_SIGN_STYLE = Automatic;
  533 + CURRENT_PROJECT_VERSION = 1;
  534 + GENERATE_INFOPLIST_FILE = YES;
  535 + IPHONEOS_DEPLOYMENT_TARGET = 16.2;
  536 + MARKETING_VERSION = 1.0;
  537 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxTests";
  538 + PRODUCT_NAME = "$(TARGET_NAME)";
  539 + SWIFT_EMIT_LOC_STRINGS = NO;
  540 + SWIFT_VERSION = 5.0;
  541 + TARGETED_DEVICE_FAMILY = "1,2";
  542 + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SherpaOnnx.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/SherpaOnnx";
  543 + };
  544 + name = Release;
  545 + };
  546 + C924F35529DDAC0D00A440A5 /* Debug */ = {
  547 + isa = XCBuildConfiguration;
  548 + buildSettings = {
  549 + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
  550 + CODE_SIGN_STYLE = Automatic;
  551 + CURRENT_PROJECT_VERSION = 1;
  552 + GENERATE_INFOPLIST_FILE = YES;
  553 + MARKETING_VERSION = 1.0;
  554 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxUITests";
  555 + PRODUCT_NAME = "$(TARGET_NAME)";
  556 + SWIFT_EMIT_LOC_STRINGS = NO;
  557 + SWIFT_VERSION = 5.0;
  558 + TARGETED_DEVICE_FAMILY = "1,2";
  559 + TEST_TARGET_NAME = SherpaOnnx;
  560 + };
  561 + name = Debug;
  562 + };
  563 + C924F35629DDAC0D00A440A5 /* Release */ = {
  564 + isa = XCBuildConfiguration;
  565 + buildSettings = {
  566 + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
  567 + CODE_SIGN_STYLE = Automatic;
  568 + CURRENT_PROJECT_VERSION = 1;
  569 + GENERATE_INFOPLIST_FILE = YES;
  570 + MARKETING_VERSION = 1.0;
  571 + PRODUCT_BUNDLE_IDENTIFIER = "com.k2-fsa.org.SherpaOnnxUITests";
  572 + PRODUCT_NAME = "$(TARGET_NAME)";
  573 + SWIFT_EMIT_LOC_STRINGS = NO;
  574 + SWIFT_VERSION = 5.0;
  575 + TARGETED_DEVICE_FAMILY = "1,2";
  576 + TEST_TARGET_NAME = SherpaOnnx;
  577 + };
  578 + name = Release;
  579 + };
  580 +/* End XCBuildConfiguration section */
  581 +
  582 +/* Begin XCConfigurationList section */
  583 + C924F32529DDAC0B00A440A5 /* Build configuration list for PBXProject "SherpaOnnx" */ = {
  584 + isa = XCConfigurationList;
  585 + buildConfigurations = (
  586 + C924F34C29DDAC0D00A440A5 /* Debug */,
  587 + C924F34D29DDAC0D00A440A5 /* Release */,
  588 + );
  589 + defaultConfigurationIsVisible = 0;
  590 + defaultConfigurationName = Release;
  591 + };
  592 + C924F34E29DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnx" */ = {
  593 + isa = XCConfigurationList;
  594 + buildConfigurations = (
  595 + C924F34F29DDAC0D00A440A5 /* Debug */,
  596 + C924F35029DDAC0D00A440A5 /* Release */,
  597 + );
  598 + defaultConfigurationIsVisible = 0;
  599 + defaultConfigurationName = Release;
  600 + };
  601 + C924F35129DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxTests" */ = {
  602 + isa = XCConfigurationList;
  603 + buildConfigurations = (
  604 + C924F35229DDAC0D00A440A5 /* Debug */,
  605 + C924F35329DDAC0D00A440A5 /* Release */,
  606 + );
  607 + defaultConfigurationIsVisible = 0;
  608 + defaultConfigurationName = Release;
  609 + };
  610 + C924F35429DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnxUITests" */ = {
  611 + isa = XCConfigurationList;
  612 + buildConfigurations = (
  613 + C924F35529DDAC0D00A440A5 /* Debug */,
  614 + C924F35629DDAC0D00A440A5 /* Release */,
  615 + );
  616 + defaultConfigurationIsVisible = 0;
  617 + defaultConfigurationName = Release;
  618 + };
  619 +/* End XCConfigurationList section */
  620 + };
  621 + rootObject = C924F32229DDAC0B00A440A5 /* Project object */;
  622 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<Workspace
  3 + version = "1.0">
  4 + <FileRef
  5 + location = "self:">
  6 + </FileRef>
  7 +</Workspace>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>IDEDidComputeMac32BitWarning</key>
  6 + <true/>
  7 +</dict>
  8 +</plist>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3 +<plist version="1.0">
  4 +<dict>
  5 + <key>SchemeUserState</key>
  6 + <dict>
  7 + <key>SherpaOnnx.xcscheme_^#shared#^_</key>
  8 + <dict>
  9 + <key>orderHint</key>
  10 + <integer>0</integer>
  11 + </dict>
  12 + </dict>
  13 +</dict>
  14 +</plist>
  1 +{
  2 + "colors" : [
  3 + {
  4 + "idiom" : "universal"
  5 + }
  6 + ],
  7 + "info" : {
  8 + "author" : "xcode",
  9 + "version" : 1
  10 + }
  11 +}
  1 +{
  2 + "images" : [
  3 + {
  4 + "filename" : "k2-1024x1024.png",
  5 + "idiom" : "universal",
  6 + "platform" : "ios",
  7 + "size" : "1024x1024"
  8 + }
  9 + ],
  10 + "info" : {
  11 + "author" : "xcode",
  12 + "version" : 1
  13 + }
  14 +}
  1 +{
  2 + "info" : {
  3 + "author" : "xcode",
  4 + "version" : 1
  5 + }
  6 +}
  1 +//
  2 +// ContentView.swift
  3 +// SherpaOnnx
  4 +//
  5 +// Created by fangjun on 2023/4/5.
  6 +//
  7 +
  8 +import SwiftUI
  9 +
  10 +struct ContentView: View {
  11 + @StateObject var sherpaOnnxVM = SherpaOnnxViewModel()
  12 +
  13 + var body: some View {
  14 + VStack {
  15 + Text("ASR with Next-gen Kaldi")
  16 + .font(.title)
  17 + if sherpaOnnxVM.status == .stop {
  18 + Text("See https://github.com/k2-fsa/sherpa-onnx")
  19 + Text("Press the Start button to run!")
  20 + }
  21 + ScrollView(.vertical, showsIndicators: true) {
  22 + HStack {
  23 + Text(sherpaOnnxVM.subtitles)
  24 + Spacer()
  25 + }
  26 + }
  27 + Spacer()
  28 + Button {
  29 + toggleRecorder()
  30 + } label: {
  31 + Text(sherpaOnnxVM.status == .stop ? "Start" : "Stop")
  32 + }
  33 + }
  34 + .padding()
  35 + }
  36 +
  37 + private func toggleRecorder() {
  38 + sherpaOnnxVM.toggleRecorder()
  39 + }
  40 +}
  41 +
  42 +struct ContentView_Previews: PreviewProvider {
  43 + static var previews: some View {
  44 + ContentView()
  45 + }
  46 +}
  1 +//
  2 +// Extension.swift
  3 +// SherpaOnnx
  4 +//
  5 +// Created by knight on 2023/4/5.
  6 +//
  7 +
  8 +import AVFoundation
  9 +
  10 +extension AudioBuffer {
  11 + func array() -> [Float] {
  12 + return Array(UnsafeBufferPointer(self))
  13 + }
  14 +}
  15 +
  16 +extension AVAudioPCMBuffer {
  17 + func array() -> [Float] {
  18 + return self.audioBufferList.pointee.mBuffers.array()
  19 + }
  20 +}
  1 +import Foundation
  2 +
  3 +func getResource(_ forResource: String, _ ofType: String) -> String {
  4 + let path = Bundle.main.path(forResource: forResource, ofType: ofType)
  5 + precondition(
  6 + path != nil,
  7 + "\(forResource).\(ofType) does not exist!\n" + "Remember to change \n"
  8 + + " Build Phases -> Copy Bundle Resources\n" + "to add it!"
  9 + )
  10 + return path!
  11 +}
  12 +/// Please refer to
  13 +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
  14 +/// to download pre-trained models
  15 +
  16 +/// sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20 (Bilingual, Chinese + English)
  17 +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/zipformer-transducer-models.html
  18 +func getBilingualStreamZhEnZipformer20230220() -> SherpaOnnxOnlineTransducerModelConfig {
  19 + let encoder = getResource("encoder-epoch-99-avg-1", "onnx")
  20 + let decoder = getResource("decoder-epoch-99-avg-1", "onnx")
  21 + let joiner = getResource("joiner-epoch-99-avg-1", "onnx")
  22 + let tokens = getResource("tokens", "txt")
  23 +
  24 + return sherpaOnnxOnlineTransducerModelConfig(
  25 + encoder: encoder,
  26 + decoder: decoder,
  27 + joiner: joiner,
  28 + tokens: tokens,
  29 + numThreads: 2
  30 + )
  31 +}
  32 +
  33 +/// Please refer to
  34 +/// https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
  35 +/// to add more models if you need
  1 +{
  2 + "info" : {
  3 + "author" : "xcode",
  4 + "version" : 1
  5 + }
  6 +}
  1 +//
  2 +// SherpaOnnxApp.swift
  3 +// SherpaOnnx
  4 +//
  5 +// Created by fangjun on 2023/4/5.
  6 +//
  7 +
  8 +import SwiftUI
  9 +
  10 +@main
  11 +struct SherpaOnnxApp: App {
  12 + var body: some Scene {
  13 + WindowGroup {
  14 + ContentView()
  15 + }
  16 + }
  17 +}
  1 +//
  2 +// SherpaOnnxViewModel.swift
  3 +// SherpaOnnx
  4 +//
  5 +// Created by knight on 2023/4/5.
  6 +//
  7 +
  8 +import Foundation
  9 +import AVFoundation
  10 +
  11 +enum Status {
  12 + case stop
  13 + case recording
  14 +}
  15 +
  16 +class SherpaOnnxViewModel: ObservableObject {
  17 + @Published var status: Status = .stop
  18 + @Published var subtitles: String = ""
  19 +
  20 + var sentences: [String] = []
  21 +
  22 + var audioEngine: AVAudioEngine? = nil
  23 + var recognizer: SherpaOnnxRecognizer! = nil
  24 +
  25 + var lastSentence: String = ""
  26 + let maxSentence: Int = 20
  27 +
  28 + var results: String {
  29 + if sentences.isEmpty && lastSentence.isEmpty {
  30 + return ""
  31 + }
  32 + if sentences.isEmpty {
  33 + return "0: \(lastSentence.lowercased())"
  34 + }
  35 +
  36 + let start = max(sentences.count - maxSentence, 0)
  37 + if lastSentence.isEmpty {
  38 + return sentences.enumerated().map { (index, s) in "\(index): \(s.lowercased())" }[start...]
  39 + .joined(separator: "\n")
  40 + } else {
  41 + return sentences.enumerated().map { (index, s) in "\(index): \(s.lowercased())" }[start...]
  42 + .joined(separator: "\n") + "\n\(sentences.count): \(lastSentence.lowercased())"
  43 + }
  44 + }
  45 +
  46 + func updateLabel() {
  47 + DispatchQueue.main.async {
  48 + self.subtitles = self.results
  49 + }
  50 + }
  51 +
  52 + init() {
  53 + initRecognizer()
  54 + initRecorder()
  55 + }
  56 +
  57 + private func initRecognizer() {
  58 + // Please select one model that is best suitable for you.
  59 + //
  60 + // You can also modify Model.swift to add new pre-trained models from
  61 + // https://k2-fsa.github.io/sherpa/onnx/pretrained_models/index.html
  62 + let modelConfig = getBilingualStreamZhEnZipformer20230220()
  63 +
  64 + let featConfig = sherpaOnnxFeatureConfig(
  65 + sampleRate: 16000,
  66 + featureDim: 80)
  67 +
  68 + var config = sherpaOnnxOnlineRecognizerConfig(
  69 + featConfig: featConfig,
  70 + modelConfig: modelConfig,
  71 + enableEndpoint: true,
  72 + rule1MinTrailingSilence: 2.4,
  73 + rule2MinTrailingSilence: 0.8,
  74 + rule3MinUtteranceLength: 30,
  75 + decodingMethod: "greedy_search",
  76 + maxActivePaths: 4
  77 + )
  78 + recognizer = SherpaOnnxRecognizer(config: &config)
  79 + }
  80 +
  81 + private func initRecorder() {
  82 + print("init recorder")
  83 + audioEngine = AVAudioEngine()
  84 + let inputNode = self.audioEngine?.inputNode
  85 + let bus = 0
  86 + let inputFormat = inputNode?.outputFormat(forBus: bus)
  87 + let outputFormat = AVAudioFormat(
  88 + commonFormat: .pcmFormatFloat32,
  89 + sampleRate: 16000, channels: 1,
  90 + interleaved: false)!
  91 +
  92 + let converter = AVAudioConverter(from: inputFormat!, to: outputFormat)!
  93 +
  94 + inputNode!.installTap(
  95 + onBus: bus,
  96 + bufferSize: 1024,
  97 + format: inputFormat
  98 + ) {
  99 + (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
  100 + var newBufferAvailable = true
  101 +
  102 + let inputCallback: AVAudioConverterInputBlock = {
  103 + inNumPackets, outStatus in
  104 + if newBufferAvailable {
  105 + outStatus.pointee = .haveData
  106 + newBufferAvailable = false
  107 +
  108 + return buffer
  109 + } else {
  110 + outStatus.pointee = .noDataNow
  111 + return nil
  112 + }
  113 + }
  114 +
  115 + let convertedBuffer = AVAudioPCMBuffer(
  116 + pcmFormat: outputFormat,
  117 + frameCapacity:
  118 + AVAudioFrameCount(outputFormat.sampleRate)
  119 + * buffer.frameLength
  120 + / AVAudioFrameCount(buffer.format.sampleRate))!
  121 +
  122 + var error: NSError?
  123 + let _ = converter.convert(
  124 + to: convertedBuffer,
  125 + error: &error, withInputFrom: inputCallback)
  126 +
  127 + // TODO(fangjun): Handle status != haveData
  128 +
  129 + let array = convertedBuffer.array()
  130 + if !array.isEmpty {
  131 + self.recognizer.acceptWaveform(samples: array)
  132 + while (self.recognizer.isReady()){
  133 + self.recognizer.decode()
  134 + }
  135 + let isEndpoint = self.recognizer.isEndpoint()
  136 + let text = self.recognizer.getResult().text
  137 +
  138 + if !text.isEmpty && self.lastSentence != text {
  139 + self.lastSentence = text
  140 + self.updateLabel()
  141 + print(text)
  142 + }
  143 +
  144 + if isEndpoint{
  145 + if !text.isEmpty {
  146 + let tmp = self.lastSentence
  147 + self.lastSentence = ""
  148 + self.sentences.append(tmp)
  149 + }
  150 + self.recognizer.reset()
  151 + }
  152 + }
  153 + }
  154 + }
  155 +
  156 + public func toggleRecorder() {
  157 + if status == .stop {
  158 + startRecorder()
  159 + status = .recording
  160 + } else {
  161 + stopRecorder()
  162 + status = .stop
  163 + }
  164 + }
  165 +
  166 + private func startRecorder() {
  167 + lastSentence = ""
  168 + sentences = []
  169 +
  170 + do {
  171 + try self.audioEngine?.start()
  172 + } catch let error as NSError {
  173 + print("Got an error starting audioEngine: \(error.domain), \(error)")
  174 + }
  175 + print("started")
  176 + }
  177 +
  178 + private func stopRecorder() {
  179 + audioEngine?.stop()
  180 + print("stopped")
  181 + }
  182 +}
  1 +//
  2 +// SherpaOnnxTests.swift
  3 +// SherpaOnnxTests
  4 +//
  5 +// Created by fangjun on 2023/4/5.
  6 +//
  7 +
  8 +import XCTest
  9 +@testable import SherpaOnnx
  10 +
  11 +final class SherpaOnnxTests: XCTestCase {
  12 +
  13 + override func setUpWithError() throws {
  14 + // Put setup code here. This method is called before the invocation of each test method in the class.
  15 + }
  16 +
  17 + override func tearDownWithError() throws {
  18 + // Put teardown code here. This method is called after the invocation of each test method in the class.
  19 + }
  20 +
  21 + func testExample() throws {
  22 + // This is an example of a functional test case.
  23 + // Use XCTAssert and related functions to verify your tests produce the correct results.
  24 + // Any test you write for XCTest can be annotated as throws and async.
  25 + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
  26 + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
  27 + }
  28 +
  29 + func testPerformanceExample() throws {
  30 + // This is an example of a performance test case.
  31 + self.measure {
  32 + // Put the code you want to measure the time of here.
  33 + }
  34 + }
  35 +
  36 +}
  1 +//
  2 +// SherpaOnnxUITests.swift
  3 +// SherpaOnnxUITests
  4 +//
  5 +// Created by fangjun on 2023/4/5.
  6 +//
  7 +
  8 +import XCTest
  9 +
  10 +final class SherpaOnnxUITests: XCTestCase {
  11 +
  12 + override func setUpWithError() throws {
  13 + // Put setup code here. This method is called before the invocation of each test method in the class.
  14 +
  15 + // In UI tests it is usually best to stop immediately when a failure occurs.
  16 + continueAfterFailure = false
  17 +
  18 + // 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.
  19 + }
  20 +
  21 + override func tearDownWithError() throws {
  22 + // Put teardown code here. This method is called after the invocation of each test method in the class.
  23 + }
  24 +
  25 + func testExample() throws {
  26 + // UI tests must launch the application that they test.
  27 + let app = XCUIApplication()
  28 + app.launch()
  29 +
  30 + // Use XCTAssert and related functions to verify your tests produce the correct results.
  31 + }
  32 +
  33 + func testLaunchPerformance() throws {
  34 + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) {
  35 + // This measures how long it takes to launch your application.
  36 + measure(metrics: [XCTApplicationLaunchMetric()]) {
  37 + XCUIApplication().launch()
  38 + }
  39 + }
  40 + }
  41 +}
  1 +//
  2 +// SherpaOnnxUITestsLaunchTests.swift
  3 +// SherpaOnnxUITests
  4 +//
  5 +// Created by fangjun on 2023/4/5.
  6 +//
  7 +
  8 +import XCTest
  9 +
  10 +final class SherpaOnnxUITestsLaunchTests: XCTestCase {
  11 +
  12 + override class var runsForEachTargetApplicationUIConfiguration: Bool {
  13 + true
  14 + }
  15 +
  16 + override func setUpWithError() throws {
  17 + continueAfterFailure = false
  18 + }
  19 +
  20 + func testLaunch() throws {
  21 + let app = XCUIApplication()
  22 + app.launch()
  23 +
  24 + // Insert steps here to perform after app launch but before taking a screenshot,
  25 + // such as logging into a test account or navigating somewhere in the app
  26 +
  27 + let attachment = XCTAttachment(screenshot: app.screenshot())
  28 + attachment.name = "Launch Screen"
  29 + attachment.lifetime = .keepAlways
  30 + add(attachment)
  31 + }
  32 +}