sherpa-onnx icon indicating copy to clipboard operation
sherpa-onnx copied to clipboard

Unable to run it in MacOS with Swift APi examples

Open Intiserahmed opened this issue 1 year ago • 3 comments

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?

Intiserahmed avatar Sep 21 '24 05:09 Intiserahmed

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

csukuangfj avatar Sep 21 '24 08:09 csukuangfj

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

Intiserahmed avatar Sep 21 '24 09:09 Intiserahmed

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.

csukuangfj avatar Sep 21 '24 09:09 csukuangfj

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'.

EnotPoloskun avatar Oct 27 '24 22:10 EnotPoloskun

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 https://github.com/k2-fsa/sherpa-onnx/issues/1368#issuecomment-2365064156

csukuangfj avatar Oct 28 '24 01:10 csukuangfj

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)

EnotPoloskun avatar Oct 28 '24 16:10 EnotPoloskun

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 avatar Oct 28 '24 16:10 csukuangfj

@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.

csukuangfj avatar Oct 29 '24 03:10 csukuangfj

@csukuangfj Thanks a lot for the specific instructions.

Intiserahmed avatar Oct 29 '24 04:10 Intiserahmed

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

EnotPoloskun avatar Oct 29 '24 15:10 EnotPoloskun