Skip to content

Use SPM in iOS examples - #3822

Merged
csukuangfj merged 4 commits into
k2-fsa:masterfrom
csukuangfj:ios-spm
Jul 29, 2026
Merged

csukuangfj merged 4 commits into
k2-fsa:masterfrom
csukuangfj:ios-spm

Conversation

@csukuangfj

@csukuangfj csukuangfj commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • API Updates

    • Expanded the Swift public surface area across recognition (online/offline), streaming controls, text-to-speech, language ID, keyword spotting, punctuation, denoising, diarization, and source separation.
    • Exported additional metadata helpers and buffer/config utilities.
    • Updated offline TTS configuration to include rule FSTs.
  • Build & Quality

    • Added an iOS Simulator GitHub Actions workflow covering five SwiftUI app variants.
    • Migrated iOS projects to Swift Package–based integration for the SherpaOnnx module (replacing bundled xcframework usage).
  • Chores

    • Adjusted the macOS build script to remove the installed C module map after artifact generation.

@csukuangfj
csukuangfj requested a review from Copilot July 29, 2026 04:35
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d34340ae-b387-46d1-84c7-acf04f7f7764

📥 Commits

Reviewing files that changed from the base of the PR and between 1c56297 and a8db27c.

📒 Files selected for processing (1)
  • build-swift-macos.sh

📝 Walkthrough

Walkthrough

The PR exports the Swift API surface, migrates five iOS SwiftUI projects from embedded XCFrameworks to the sherpa-onnx Swift package, adds explicit module imports, updates one TTS configuration, removes the installed module map after macOS builds, and introduces iOS simulator CI coverage.

Changes

iOS Swift Package migration

Layer / File(s) Summary
Public Swift API surface
swift-api-examples/SherpaOnnx.swift, build-swift-macos.sh
Model factories, recognition, TTS, VAD, denoiser, metadata, and source-separation APIs are made public; the installed module map is removed after building.
Xcode package integration
ios-swiftui/*/*.xcodeproj/project.pbxproj, ios-swiftui/.gitignore
Five projects replace local XCFramework and bridging-header wiring with the sherpa-onnx Swift Package product; TTS resources are added.
SwiftUI module usage and TTS configuration
ios-swiftui/*/**/*.swift
Application files explicitly import SherpaOnnx, and the Kokoro multilingual TTS configuration now passes ruleFsts.
iOS simulator CI
.github/workflows/ios.yaml
Adds five macOS jobs that build the SwiftUI schemes for iOS Simulator with Swift Package plugin validation skipped.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions
  participant Xcode
  participant SwiftPackageManager
  participant SwiftUIApps
  GitHubActions->>Xcode: build five iOS Simulator schemes
  Xcode->>SwiftPackageManager: resolve sherpa-onnx product
  SwiftPackageManager->>SwiftUIApps: provide SherpaOnnx module
  SwiftUIApps->>SwiftUIApps: compile imported API usage
Loading

Possibly related PRs

Suggested reviewers: slipstr34m

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: switching the iOS examples to SPM-based dependencies.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
swift-api-examples/SherpaOnnx.swift (1)

2208-2218: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Keep C string buffers alive for the whole config construction.

withUnsafeBufferPointer only guarantees the returned baseAddress for the closure execution, but line 2225 passes those cstrings to SherpaOnnxCreateOfflineSourceSeparation after all buffer closures have returned. Build the pointers in scoped C-string closures and call body(...) before each buffer/storage is deallocated or overwritten.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@swift-api-examples/SherpaOnnx.swift` around lines 2208 - 2218, Update
withCConfig so every C-string pointer remains valid while the configuration is
consumed: replace the helper’s escaped baseAddress storage with nested
withUnsafeBufferPointer scopes for each optional string, and invoke body (and
the underlying SherpaOnnxCreateOfflineSourceSeparation call) inside those
scopes. Ensure all related buffers and config storage remain alive through the
call, including when optional values are nil.
🧹 Nitpick comments (1)
swift-api-examples/SherpaOnnx.swift (1)

212-212: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid freezing the Recongition typo into the public API.

Both exported result classes are misspelled. Add correctly spelled public names before consumers adopt this API, retaining deprecated aliases if compatibility is required.

Also applies to: 677-677

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@swift-api-examples/SherpaOnnx.swift` at line 212, Correct the public class
names for both exported recognition result types, including the declaration near
SherpaOnnxOnlineRecongitionResult and the corresponding class near the second
affected location. Preserve compatibility by retaining the misspelled names only
as deprecated aliases that reference the correctly spelled public classes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ios.yaml:
- Around line 27-29: Disable checkout credential persistence by adding
persist-credentials: false to every actions/checkout@v4 step in
.github/workflows/ios.yaml at lines 27-29, 44-46, 61-63, 78-80, and 95-97, while
preserving the existing fetch-depth settings.
- Around line 33-39: Enable pipefail before each piped xcodebuild command so
simulator build failures propagate correctly: update .github/workflows/ios.yaml
lines 33-39, 51-56, 68-73, 85-90, and 102-107, covering the SherpaOnnx,
SherpaOnnx2Pass, SherpaOnnxLangID, SherpaOnnxSubtitle, and SherpaOnnxTts build
steps.

In `@ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj`:
- Around line 231-233: Add the missing XCRemoteSwiftPackageReference object for
C9SP000000000003, defining the sherpa-onnx repository URL and its required
version or branch, and place it in the project’s PBX object sections so the
existing packageReferences entry and product dependency resolve correctly.

In `@ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass.xcodeproj/project.pbxproj`:
- Around line 130-132: Add a matching XCRemoteSwiftPackageReference object for
package UUID C9SP000000000003 and the sherpa-onnx package in
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass.xcodeproj/project.pbxproj (lines
130-132),
ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID.xcodeproj/project.pbxproj (lines
233-235), and
ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle.xcodeproj/project.pbxproj
(lines 160-162). Define each package object with the repository URL and
requirement matching the project’s intended sherpa-onnx dependency so the
existing XCSwiftPackageProductDependency references resolve.

In `@ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj`:
- Around line 24-26: Update the Xcode project’s Resources build phase to bundle
the three new TTS assets: espeak-ng-data, en_US-amy-low.onnx, and tokens.txt.
Add corresponding PBXBuildFile entries and include all three build-file
references in C917B4DF2B0EEF3B005245AC /* Resources */, while retaining their
existing PBXFileReference entries.

In `@swift-api-examples/SherpaOnnx.swift`:
- Around line 16-18: Remove the public `toCPointer` API and eliminate its use
for storing string pointers in the public config factories. Use owned string
storage for any pointers retained in C structs, or restrict pointer conversion
to internal immediate C calls where the backing string remains alive; ensure SPM
clients cannot receive pointers backed by a temporary `NSString`.
- Around line 2195-2207: Add public initializers to the nested Spleeter and Uvr
structs and to SourceSeparationConfig, exposing parameters for their
configurable properties with existing defaults preserved. Update
SourceSeparator.init?(config:) to be public so external package clients can
construct and use the source-separation API.

---

Outside diff comments:
In `@swift-api-examples/SherpaOnnx.swift`:
- Around line 2208-2218: Update withCConfig so every C-string pointer remains
valid while the configuration is consumed: replace the helper’s escaped
baseAddress storage with nested withUnsafeBufferPointer scopes for each optional
string, and invoke body (and the underlying
SherpaOnnxCreateOfflineSourceSeparation call) inside those scopes. Ensure all
related buffers and config storage remain alive through the call, including when
optional values are nil.

---

Nitpick comments:
In `@swift-api-examples/SherpaOnnx.swift`:
- Line 212: Correct the public class names for both exported recognition result
types, including the declaration near SherpaOnnxOnlineRecongitionResult and the
corresponding class near the second affected location. Preserve compatibility by
retaining the misspelled names only as deprecated aliases that reference the
correctly spelled public classes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f7383f8-b814-4e9d-86aa-0f2f8d8ef32e

📥 Commits

Reviewing files that changed from the base of the PR and between 2744aa2 and eb49f75.

📒 Files selected for processing (26)
  • .github/workflows/ios.yaml
  • ios-swiftui/.gitignore
  • ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj
  • ios-swiftui/SherpaOnnx/SherpaOnnx/ContentView.swift
  • ios-swiftui/SherpaOnnx/SherpaOnnx/Extension.swift
  • ios-swiftui/SherpaOnnx/SherpaOnnx/Model.swift
  • ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxApp.swift
  • ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxViewModel.swift
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass.xcodeproj/project.pbxproj
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/ContentView.swift
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/Extension.swift
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/Model.swift
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/SherpaOnnx2PassApp.swift
  • ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/SherpaOnnxViewModel.swift
  • ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID.xcodeproj/project.pbxproj
  • ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/ContentView.swift
  • ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/SherpaOnnxLangIDApp.swift
  • ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/ViewModel.swift
  • ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle.xcodeproj/project.pbxproj
  • ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/ContentView.swift
  • ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/SherpaOnnxSubtitleApp.swift
  • ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/SubtitleViewModel.swift
  • ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj
  • ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ContentView.swift
  • ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift
  • swift-api-examples/SherpaOnnx.swift

Comment thread .github/workflows/ios.yaml
Comment thread .github/workflows/ios.yaml
Comment thread ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj
Comment on lines +24 to +26
C9E3B5CE3019B6D50057554A /* espeak-ng-data */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "espeak-ng-data"; sourceTree = "<group>"; };
C9E3B5CF3019B6D50057554A /* en_US-amy-low.onnx */ = {isa = PBXFileReference; lastKnownFileType = file; path = "en_US-amy-low.onnx"; sourceTree = "<group>"; };
C9E3B5D03019B6D50057554A /* tokens.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = tokens.txt; sourceTree = "<group>"; };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Bundle the newly added TTS assets.

These are only PBXFileReferences; none are added to the Resources build phase at lines 140-149. Bundle.main cannot load the model, tokens, or espeak-ng-data from the installed app.

Add PBXBuildFile resource entries for all three and include them in C917B4DF2B0EEF3B005245AC /* Resources */.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj` around
lines 24 - 26, Update the Xcode project’s Resources build phase to bundle the
three new TTS assets: espeak-ng-data, en_US-amy-low.onnx, and tokens.txt. Add
corresponding PBXBuildFile entries and include all three build-file references
in C917B4DF2B0EEF3B005245AC /* Resources */, while retaining their existing
PBXFileReference entries.

Comment on lines +16 to 18
public func toCPointer(_ s: String) -> UnsafePointer<Int8>! {
let cs = (s as NSString).utf8String
return UnsafePointer<Int8>(cs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | sed -n '1,120p'

echo "== target file context =="
if [ -f swift-api-examples/SherpaOnnx.swift ]; then
  wc -l swift-api-examples/SherpaOnnx.swift
  ast-grep outline swift-api-examples/SherpaOnnx.swift || true
  sed -n '1,140p' swift-api-examples/SherpaOnnx.swift
else
  fd -i 'SherpaOnnx.swift'
fi

echo "== search toCPointer and withCConfig usages =="
rg -n "toCPointer|withCConfig|withCString|SwiftManaged" swift-api-examples/SherpaOnnx.swift . --glob '*.swift' --glob '*.h' --glob '*.hpp' | sed -n '1,220p'

Repository: k2-fsa/sherpa-onnx

Length of output: 34367


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Swift config structs and call sites =="
sed -n '28,135p' swift-api-examples/SherpaOnnx.swift
sed -n '145,220p' swift-api-examples/SherpaOnnx.swift
sed -n '254,340p' swift-api-examples/SherpaOnnx.swift
sed -n '1289,1392p' swift-api-examples/SherpaOnnx.swift
sed -n '2195,2245p' swift-api-examples/SherpaOnnx.swift

echo "== Swift package manifests / SPM exposure =="
git ls-files | rg 'Package.swift$|Package.resolved$|swift|CMakeLists|SherpaOnnx' | sed -n '1,220p'

echo "== relevant header declarations =="
rg -n "SherpaOnnxOnlineModelConfig|SherpaOnnxOfflineModelConfig|SherpaOnnx.*Config|typedef struct|const char" --glob '*.h' --glob 'C-API*' --glob 'api*' . | sed -n '1,260p'

Repository: k2-fsa/sherpa-onnx

Length of output: 48287


🌐 Web query:

Swift NSString UTF8String returned pointer lifetime underlying temporary buffer

💡 Result:

The pointer returned by the NSString utf8String property (and its Objective-C equivalent, UTF8String) points to a memory buffer managed by the NSString object [1][2]. This pointer is not guaranteed to be valid for any duration longer than the lifetime of the NSString object itself [1][3]. In many cases, it may have a significantly shorter lifetime, potentially becoming invalid as soon as the current scope or the current autorelease cycle ends [1][3][4]. Because the returned value is a raw C pointer, it does not participate in Swift's Automatic Reference Counting (ARC) or any other memory management system [5][3]. The system cannot track when you are finished using the pointer, and therefore it cannot prevent the underlying NSString from being deallocated while you are still accessing the buffer [3][2]. If you need to use the string data beyond the immediate scope where the pointer was obtained, you must copy the data (for example, by using strdup or creating a new Swift String or Data object) [1][5][2]. Apple's official documentation explicitly warns: This C string is a pointer to a structure inside the string object, which may have a lifetime shorter than the string object and will certainly not have a longer lifetime. Therefore, you should copy the C string if it needs to be stored outside of the memory context in which you use this property [1][6].

Citations:


Do not expose an unowned C-string pointer from toCPointer.

toCPointer returns the raw utf8String pointer from a temporary bridged NSString; those buffers are not ARCs retained and can be invalidated once the bridged string has no owner. The public config factories then pass these pointers into C structs, so SPM clients can store them until later C calls and read freed memory. Keep the helper internal, only use owned conversion for immediate C calls, or copy/retain the backing string storage in a Swift wrapper.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@swift-api-examples/SherpaOnnx.swift` around lines 16 - 18, Remove the public
`toCPointer` API and eliminate its use for storing string pointers in the public
config factories. Use owned string storage for any pointers retained in C
structs, or restrict pointer conversion to internal immediate C calls where the
backing string remains alive; ensure SPM clients cannot receive pointers backed
by a temporary `NSString`.

Comment on lines +2195 to 2207
public struct SourceSeparationConfig {
public struct Spleeter {
public var vocals: String
public var accompaniment: String
}
struct Uvr { var model: String }
public struct Uvr { public var model: String }

var spleeter: Spleeter?
var uvr: Uvr?
var numThreads: Int = 1
var debug: Bool = false
var provider: String = "cpu"
public var spleeter: Spleeter?
public var uvr: Uvr?
public var numThreads: Int = 1
public var debug: Bool = false
public var provider: String = "cpu"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant Swift file and source-separation symbols.
printf 'Files matching SherpaOnnx.swift:\n'
fd -a 'SherpaOnnx.swift' . || true

printf '\nRelevant SourceSeparationConfig area:\n'
file="$(fd 'SherpaOnnx.swift' . | head -n 1)"
if [ -n "${file:-}" ]; then
  nl -ba "$file" | sed -n '2168,2242p'
fi

printf '\nSearch for SourceSeparator and SourceSeparationConfig usages/declarations:\n'
rg -n "SourceSeparationConfig|SourceSeparator|Spleeter|Uvr|init\\?\\(config: SourceSeparationConfig\\)|struct Spleeter|struct Uvr" "$file" || true

printf '\nSwift declarations around SourceSeparator init and config struct:\n'
nl -ba "$file" | sed -n '2190,2238p'

Repository: k2-fsa/sherpa-onnx

Length of output: 324


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file="$(fd 'SherpaOnnx.swift' . | head -n 1)"
printf 'file=%s\n' "$file"

printf '\nRelevant SourceSeparationConfig/Separator area:\n'
awk 'NR>=2168 && NR<=2242 { printf "%6d\t%s\n", NR, $0 }' "$file"

printf '\nSourceSeparationConfig/SourceSeparator declarations:\n'
rg -n "public struct SourceSeparationConfig|struct SourceSeparationConfig|public struct Spleeter|struct Spleeter|public struct Uvr|struct Uvr|init\\?\\(config: SourceSeparationConfig\\)|struct SourceSeparator|public struct SourceSeparator|class SourceSeparator|public class SourceSeparator" "$file" || true

Repository: k2-fsa/sherpa-onnx

Length of output: 3504


🌐 Web query:

Swift synthesized public initializer nested public struct nested public struct SourceSeparationConfig internal initializer

💡 Result:

In Swift, the compiler does not automatically synthesize a public memberwise initializer for public structs, even if they are nested within another public struct [1][2][3]. By default, the synthesized memberwise initializer for a public struct is internal, which prevents it from being called from outside the defining module [4][2][3]. To make such an initializer available publicly, you must manually implement a public initializer [1][2]. Regarding SourceSeparationConfig, as seen in various Swift API examples (e.g., in projects like sherpa-onnx), it is a common pattern to manually define public initializers for such configuration structs to ensure they can be instantiated across module boundaries [5][6]. The internal initializer error frequently encountered by developers in this context occurs precisely because the implicit, synthesized initializer lacks the necessary public access level [4][7]. Summary of rules: 1. Implicit Initializer Access: For a public struct, the synthesized memberwise initializer is internal by default [2][3]. 2. Nested Structs: Access control for nested types works similarly; even if the nested struct is declared public, its implicit initializer remains internal if not explicitly provided [2][8]. 3. Manual Implementation: To expose the memberwise initializer publicly, you must write it explicitly within the struct definition [1][2]. If you are working with a third-party library where SourceSeparationConfig is not providing a public initializer, you cannot change this behavior externally and must rely on the library author to provide a public init, or wrap the type [4][1][2].

Citations:


Make the exported source-separation types constructible externally.

Spleeter, Uvr, and SourceSeparationConfig are public, but Swift does not synthesize public memberwise initializers for public structs, so external clients cannot build these config objects. Add public initializers for Spleeter, Uvr, and SourceSeparationConfig, and make SourceSeparator.init?(config:) public so the API is usable from its package.

Also applies to: 2229-2233

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@swift-api-examples/SherpaOnnx.swift` around lines 2195 - 2207, Add public
initializers to the nested Spleeter and Uvr structs and to
SourceSeparationConfig, exposing parameters for their configurable properties
with existing defaults preserved. Update SourceSeparator.init?(config:) to be
public so external package clients can construct and use the source-separation
API.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Updates the iOS SwiftUI example apps to consume SherpaOnnx via Swift Package Manager (SPM) instead of vendored xcframeworks/local Swift glue, and adds CI to ensure the iOS projects build.

Changes:

  • Expose Swift helper APIs in swift-api-examples/SherpaOnnx.swift as public for package consumption.
  • Migrate iOS SwiftUI example targets to import SherpaOnnx and switch Xcode projects to SPM package dependencies.
  • Add a GitHub Actions workflow to build iOS example projects on macOS runners.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
swift-api-examples/SherpaOnnx.swift Makes helper functions/wrappers public so they can be imported from the SPM module.
ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift Switches to importing the SherpaOnnx module; updates TTS config usage.
ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ContentView.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxTts/SherpaOnnxTts.xcodeproj/project.pbxproj Replaces embedded xcframeworks/local Swift file with SPM dependency.
ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/SubtitleViewModel.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/SherpaOnnxSubtitleApp.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle/ContentView.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxSubtitle/SherpaOnnxSubtitle.xcodeproj/project.pbxproj Replaces embedded xcframeworks/local Swift file with SPM dependency.
ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/ViewModel.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/SherpaOnnxLangIDApp.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID/ContentView.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnxLangID/SherpaOnnxLangID.xcodeproj/project.pbxproj Replaces embedded xcframeworks/local Swift file with SPM dependency.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/SherpaOnnxViewModel.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/SherpaOnnx2PassApp.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/Model.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/Extension.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass/ContentView.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx2Pass/SherpaOnnx2Pass.xcodeproj/project.pbxproj Replaces embedded xcframeworks/local Swift file with SPM dependency.
ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxViewModel.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx/SherpaOnnx/SherpaOnnxApp.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx/SherpaOnnx/Model.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx/SherpaOnnx/Extension.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx/SherpaOnnx/ContentView.swift Switches to importing the SherpaOnnx module.
ios-swiftui/SherpaOnnx/SherpaOnnx.xcodeproj/project.pbxproj Replaces embedded xcframeworks/local Swift file with SPM dependency.
ios-swiftui/.gitignore Ignores SwiftPM-generated project workspace metadata directory.
.github/workflows/ios.yaml Adds CI workflow to build the iOS SwiftUI example projects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to 19
public func toCPointer(_ s: String) -> UnsafePointer<Int8>! {
let cs = (s as NSString).utf8String
return UnsafePointer<Int8>(cs)
}
Comment on lines +2195 to +2206
public struct SourceSeparationConfig {
public struct Spleeter {
public var vocals: String
public var accompaniment: String
}
struct Uvr { var model: String }
public struct Uvr { public var model: String }

var spleeter: Spleeter?
var uvr: Uvr?
var numThreads: Int = 1
var debug: Bool = false
var provider: String = "cpu"
public var spleeter: Spleeter?
public var uvr: Uvr?
public var numThreads: Int = 1
public var debug: Bool = false
public var provider: String = "cpu"
Comment on lines +2229 to 2232
public class SourceSeparator {
private var engine: OpaquePointer?

init?(config: SourceSeparationConfig) {
Comment thread swift-api-examples/SherpaOnnx.swift Outdated
/// print("text: \(result.text)")
///
class SherpaOnnxOnlineRecongitionResult {
public class SherpaOnnxOnlineRecongitionResult {
Comment on lines 119 to 123
buildConfigurationList = DEA6571F2ABF19740066A81D /* Build configuration list for PBXNativeTarget "SherpaOnnxSubtitle" */;
buildPhases = (
DEA6570D2ABF19730066A81D /* Sources */,
DEA6570E2ABF19730066A81D /* Frameworks */,
DEA6570F2ABF19730066A81D /* Resources */,
);
Comment on lines 150 to 154
buildConfigurationList = DEBB2D962BBAAA3600864EF5 /* Build configuration list for PBXNativeTarget "SherpaOnnxLangID" */;
buildPhases = (
DEBB2D6E2BBAAA3500864EF5 /* Sources */,
DEBB2D6F2BBAAA3500864EF5 /* Frameworks */,
DEBB2D702BBAAA3500864EF5 /* Resources */,
DEBB2DAE2BBAAC6200864EF5 /* Embed Frameworks */,
);
Comment on lines 89 to 93
buildConfigurationList = C9A258872AAEFFF200E555CA /* Build configuration list for PBXNativeTarget "SherpaOnnx2Pass" */;
buildPhases = (
C9A258752AAEFFF100E555CA /* Sources */,
C9A258762AAEFFF100E555CA /* Frameworks */,
C9A258772AAEFFF100E555CA /* Resources */,
);
Comment on lines 148 to 152
buildConfigurationList = C924F34E29DDAC0D00A440A5 /* Build configuration list for PBXNativeTarget "SherpaOnnx" */;
buildPhases = (
C924F32629DDAC0B00A440A5 /* Sources */,
C924F32729DDAC0B00A440A5 /* Frameworks */,
C924F32829DDAC0B00A440A5 /* Resources */,
);
Comment on lines +34 to +39
cd ios-swiftui/SherpaOnnx
xcodebuild -project SherpaOnnx.xcodeproj \
-scheme SherpaOnnx \
-destination 'generic/platform=iOS Simulator' \
-skipPackagePluginValidation \
build | tail -20
Comment on lines +360 to +367
C9SP000000000003 /* XCRemoteSwiftPackageReference "sherpa-onnx" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/k2-fsa/sherpa-onnx";
requirement = {
kind = branch;
branch = master;
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants