Replace Android system TTS engine (#508)
This commit is contained in:
@@ -34,6 +34,10 @@ class OfflineTtsImpl {
|
||||
|
||||
// Return the sample rate of the generated audio
|
||||
virtual int32_t SampleRate() const = 0;
|
||||
|
||||
// Number of supported speakers.
|
||||
// If it supports only a single speaker, then it return 0 or 1.
|
||||
virtual int32_t NumSpeakers() const = 0;
|
||||
};
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
@@ -74,6 +74,10 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
|
||||
return model_->GetMetaData().sample_rate;
|
||||
}
|
||||
|
||||
int32_t NumSpeakers() const override {
|
||||
return model_->GetMetaData().num_speakers;
|
||||
}
|
||||
|
||||
GeneratedAudio Generate(
|
||||
const std::string &_text, int64_t sid = 0, float speed = 1.0,
|
||||
GeneratedAudioCallback callback = nullptr) const override {
|
||||
|
||||
@@ -73,4 +73,6 @@ GeneratedAudio OfflineTts::Generate(
|
||||
|
||||
int32_t OfflineTts::SampleRate() const { return impl_->SampleRate(); }
|
||||
|
||||
int32_t OfflineTts::NumSpeakers() const { return impl_->NumSpeakers(); }
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
@@ -86,6 +86,10 @@ class OfflineTts {
|
||||
// Return the sample rate of the generated audio
|
||||
int32_t SampleRate() const;
|
||||
|
||||
// Number of supported speakers.
|
||||
// If it supports only a single speaker, then it return 0 or 1.
|
||||
int32_t NumSpeakers() const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<OfflineTtsImpl> impl_;
|
||||
};
|
||||
|
||||
@@ -524,6 +524,8 @@ class SherpaOnnxOfflineTts {
|
||||
|
||||
int32_t SampleRate() const { return tts_.SampleRate(); }
|
||||
|
||||
int32_t NumSpeakers() const { return tts_.NumSpeakers(); }
|
||||
|
||||
private:
|
||||
OfflineTts tts_;
|
||||
};
|
||||
@@ -652,6 +654,13 @@ JNIEXPORT jint JNICALL Java_com_k2fsa_sherpa_onnx_OfflineTts_getSampleRate(
|
||||
->SampleRate();
|
||||
}
|
||||
|
||||
SHERPA_ONNX_EXTERN_C
|
||||
JNIEXPORT jint JNICALL Java_com_k2fsa_sherpa_onnx_OfflineTts_getNumSpeakers(
|
||||
JNIEnv *env, jobject /*obj*/, jlong ptr) {
|
||||
return reinterpret_cast<sherpa_onnx::SherpaOnnxOfflineTts *>(ptr)
|
||||
->NumSpeakers();
|
||||
}
|
||||
|
||||
// see
|
||||
// https://stackoverflow.com/questions/29043872/android-jni-return-multiple-variables
|
||||
static jobject NewInteger(JNIEnv *env, int32_t value) {
|
||||
|
||||
@@ -51,6 +51,7 @@ void PybindOfflineTts(py::module *m) {
|
||||
.def(py::init<const OfflineTtsConfig &>(), py::arg("config"),
|
||||
py::call_guard<py::gil_scoped_release>())
|
||||
.def_property_readonly("sample_rate", &PyClass::SampleRate)
|
||||
.def_property_readonly("num_speakers", &PyClass::NumSpeakers)
|
||||
.def(
|
||||
"generate",
|
||||
[](const PyClass &self, const std::string &text, int64_t sid,
|
||||
|
||||
Reference in New Issue
Block a user