GithubHelp home page GithubHelp logo

This library cannot reconcile with the react-native onnxuruntime official library: unresolved OrtGetApiBase symbol about sherpa-onnx HOT 17 OPEN

l3utterfly avatar l3utterfly commented on May 29, 2024
This library cannot reconcile with the react-native onnxuruntime official library: unresolved OrtGetApiBase symbol

from sherpa-onnx.

Comments (17)

l3utterfly avatar l3utterfly commented on May 29, 2024 1

This is the binding code:

package com.k2fsa.sherpa.onnx

import android.net.Uri
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.modules.core.DeviceEventManagerModule
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.nio.charset.StandardCharsets
import java.util.UUID


class Sherpa(reactContext: ReactApplicationContext?) : ReactContextBaseJavaModule(reactContext) {
    private var listenerCount = 0
    private lateinit var tts: OfflineTts

    override fun getName(): String {
        return "Sherpa"
    }

    // this function is called from C++
    private fun callback(samples: FloatArray) {
        //track.write(samples, 0, samples.size, AudioTrack.WRITE_BLOCKING)
    }

    @ReactMethod
    fun initTts(modelDir: String, modelName: String, modelDataDir: String) {

        var ruleFsts: String? = null
        var lexicon: String? = null

        val config = getOfflineTtsConfig(
            modelDir = modelDir!!, modelName = modelName!!, lexicon = lexicon ?: "",
            dataDir = modelDataDir ?: "",
            ruleFsts = ruleFsts ?: ""
        )!!

        if(::tts.isInitialized)
            tts.free();

        tts = OfflineTts(assetManager = null, config = config)
    }

    @ReactMethod
    fun generate(text: String, voiceId: Int, speed: Float, genDir: String, promise: Promise) {
        Thread {
            try {
                val audio = tts.generateWithCallback(
                    text = text,
                    sid = voiceId,
                    speed = speed,
                    callback = this::callback
                )

                // Create a File object for the directory
                val directory = File(genDir)
                // Check if the directory exists, if not, create it
                if (!directory.exists()) {
                    directory.mkdirs()  // This will create the directory including any necessary but nonexistent parent directories.
                }

                val filename = "$genDir/${UUID.randomUUID()}.wav"
                val ok = audio.samples.size > 0 && audio.save(filename)
                if (ok) {
                    // If saving is successful, resolve the promise
                    promise.resolve(filename)
                } else {
                    // If saving failed, reject the promise
                    promise.reject("ERROR", "Failed to generate or save audio.")
                }
            } catch (e: Exception) {
                // Handle any exceptions by rejecting the promise
                promise.reject("ERROR", "Exception occurred: ${e.message}")
            }
        }.start()
    }
}

Currently it only exposes what I need in my application, but it could be a good starting point. It's not encapsulated in its own library or anything.

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

make the official library use the libonnxruntime.so downloaded from your release page: crashes when using the official library features to run other onnx models

Do you re-build sherpa-onnx using linbonnxruntime.so from the official react native library?

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

No, I didn't do that. How can I do that? I'm new to this, please help.

I just downloaded the libs from your release page.

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

Please see our documentation

https://k2-fsa.github.io/sherpa/onnx/android/index.html

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

Thanks, I will try that

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

If you have troubles, please point me to the URL of libonnxruntime.so and I will build one for you.

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

This is the jettified onnx lib in my transform cache: https://github.com/l3utterfly/jetified-onnxruntime-android-1.17.0

If you can build one I would greatly appreciate it! Thank you!

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

@l3utterfly

Please see #603

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

Thank you so much for this! I really appreciate it.

Do you think it's helpful to update the documentation or upload these built libraries to your repo? I believe there are plenty of other users who would like to use both this library and the official onnxruntime library at once.

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

First, I want to check if it works for you.

If yes, then I think we can add documentation for it and also provide pre-built .so files for it.

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

We have an on-going issue #433

We need to support react native eventually.

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

First, I want to check if it works for you.

Yes, this works!

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

Thanks for verifying it.

Do you have a plan to contribute the React Native support for sherpa-onnx or will your implementation be open sourced?

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

Sure, I am happy to help where I can! I don't have any custom implementation though.. I just followed your documentation...

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

I'm only using the TTS portion of sherpa, so I basically followed your documentation on building for android/ios, then wrote a React Native bridge which exposes the one function that TTS needs.

from sherpa-onnx.

csukuangfj avatar csukuangfj commented on May 29, 2024

I'm only using the TTS portion of sherpa, so I basically followed your documentation on building for android/ios, then wrote a React Native bridge which exposes the one function that TTS needs.

Will your binding code be open sourced?

from sherpa-onnx.

l3utterfly avatar l3utterfly commented on May 29, 2024

I'm not sure how useful this is. I did not create a separate package or anything.

from sherpa-onnx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.