Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run it in MacOS with Swift APi examples #1368

Closed
Intiserahmed opened this issue Sep 21, 2024 · 10 comments · Fixed by #1490
Closed

Unable to run it in MacOS with Swift APi examples #1368

Intiserahmed opened this issue Sep 21, 2024 · 10 comments · Fixed by #1490

Comments

@Intiserahmed
Copy link

Hi, iOS is properly working, but when i try with MacOS build script with swift api examples, kindda confuse how to use it ? Any step by step guide for macos?

@csukuangfj
Copy link
Collaborator

The following is an example:

git clone https://github.com/k2-fsa/sherpa-onnx

cd sherpa-onnx
./build-swift-macos.sh

cd swift-api-examples

# there are several ./run-xxx.sh
# For instance,

./run-decode-file.sh

./run-tts.sh

@Intiserahmed
Copy link
Author

@csukuangfj yeah i already run it, but how to use it with xcode project any example or hints please?

@csukuangfj
Copy link
Collaborator

We have provided the required header file, libraries, and swift APIs.

Could you tell us the difficulty you have? Would be great if you can post error logs.

@EnotPoloskun
Copy link

EnotPoloskun commented Oct 27, 2024

Hey @csukuangfj

I believe that what @Intiserahmed means is that there is example of how to use shepra-onnx in ios application, but there is no example of how to use it in MacOs(desktop) if it is even possible.

I am getting following error during build when I added framework from ios example to my MacOS desktop application

/.../Frameworks/sherpa-onnx.xcframework:1:1 While building for macOS, no library for this platform was found in '/../Frameworks/sherpa-onnx.xcframework'.

@csukuangfj
Copy link
Collaborator

but there is no example of how to use it in MacOs(desktop) if it is even possible.

By the way, there is nothing special with sherpa-onnx.

For macOS app development, we provide shared libraries with C API header files.
The xcframework is for iOS development only.

We do provide Swift API examples. Please see #1368 (comment)

@EnotPoloskun
Copy link

EnotPoloskun commented Oct 28, 2024

Yeah, I see, but it is still not clear what I need to add and do with my xcode project in order to use shepra-onnx.

In other words - in one of the examples you have code like this:

  var config = sherpaOnnxOfflineSpeakerDiarizationConfig(
    segmentation: sherpaOnnxOfflineSpeakerSegmentationModelConfig(
      pyannote: sherpaOnnxOfflineSpeakerSegmentationPyannoteModelConfig(model: segmentationModel)),
    embedding: sherpaOnnxSpeakerEmbeddingExtractorConfig(model: embeddingExtractorModel),
    clustering: sherpaOnnxFastClusteringConfig(numClusters: numSpeakers)
  )

  let sd = SherpaOnnxOfflineSpeakerDiarizationWrapper(config: &config)

What I need to add to xcode project in order to be able to use sherpaOnnxOfflineSpeakerDiarizationConfig and other shepra-onnx functions. Thank you in advance.

(I am pretty new in ios/macos development and never used external non swift libraries/packages in my project, so maybe I am missing something trivial)

@csukuangfj
Copy link
Collaborator

csukuangfj commented Oct 28, 2024

I am pretty new in ios/macos development and never used external non swift libraries/packages in my project,

In that case, I suggest that you first spend some time learning how to do that.

We have provided everything you need to be used in your macos project. You have to learn how to add which file to which place.

You may find
https://k2-fsa.github.io/sherpa/ncnn/ios/for-the-more-curious-swift.html
helpful, though you need to replace the xcframework with the shared library since the xcframework is for ios, not for macos.

@csukuangfj
Copy link
Collaborator

@EnotPoloskun

https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.30/sherpa-onnx-v1.10.30-macos-xcframework-static.tar.bz2

Here is the xcframework for sherpa-onnx that supports both macos x86_64 and macos arm64.

To use it in your macos xcode project, please do the following:

  1. Add the bridging header to your project
    Screenshot 2024-10-29 at 11 19 23

  2. Add SherpaOnnx.swift to your project
    Screenshot 2024-10-29 at 11 21 02

  3. Add sherpa-onnx.xcframework to your project

Screenshot 2024-10-29 at 11 22 45

  1. Add the libonnxruntime.a to your project

You can find it from https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.17.1/onnxruntime-osx-universal2-static_lib-1.17.1.zip

Screenshot 2024-10-29 at 11 32 15

  1. Add the directory containing libonnxruntime.a to the library search path

Screenshot 2024-10-29 at 11 33 56

  1. Add -lc++ as the other linker flag
    Screenshot 2024-10-29 at 11 35 48

  2. Done! Now you can use the Swift API of sherpa-onnx in your xcode project.

Please see how little code you need to write to set it up.

@Intiserahmed
Copy link
Author

@csukuangfj Thanks a lot for the specific instructions.

@EnotPoloskun
Copy link

EnotPoloskun commented Oct 29, 2024

@csukuangfj It worked like a charm first try. Really appreciate it. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants