Comments (17)
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.
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.
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.
Please see our documentation
https://k2-fsa.github.io/sherpa/onnx/android/index.html
from sherpa-onnx.
Thanks, I will try that
from sherpa-onnx.
If you have troubles, please point me to the URL of libonnxruntime.so and I will build one for you.
from sherpa-onnx.
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.
Please see #603
from sherpa-onnx.
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.
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.
We have an on-going issue #433
We need to support react native eventually.
from sherpa-onnx.
First, I want to check if it works for you.
Yes, this works!
from sherpa-onnx.
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.
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.
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.
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.
I'm not sure how useful this is. I did not create a separate package or anything.
from sherpa-onnx.
Related Issues (20)
- sherpa_onnx.OnlineRecognizer( TypeError: OnlineRecognizer() takes no arguments HOT 12
- speaker-identification.py的speaker-file参数具体是指? HOT 3
- Crash After Package Name Changed HOT 7
- how to solve the channel problem and bit rate problem? HOT 2
- ANR On Android HOT 3
- 这边项目也支持语音唤醒吗? HOT 12
- Cannot instantiate Java OnlineRecognizer on Windows HOT 3
- Requred File? HOT 1
- Issue with sampling rate requirement for online_websocket_client_decode_file.py HOT 2
- whisper model recognition is unstable and error
- 在SherpaOnnxKws(Android)运行过程中发现的一个问题 HOT 4
- 热词影响onnx端点识别问题 HOT 5
- 单词写错需要修改 HOT 2
- 麻烦问下endpoint识别与vad识别有什么区别吗? HOT 5
- Use On .NET UWP HOT 6
- transcription inconsistency in different runs HOT 3
- export 3d speaker campplus sv model to onnx error
- Whisper onnxruntime exception on Android HOT 18
- 设置keywords后,例如小新小新这样的识别就很高,如果是“学习管家”这样的就基本很难识别到,老哥指导下怎么优化? HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sherpa-onnx.