Add C++ and Python API for Kokoro TTS models. (#1715)
This commit is contained in:
@@ -54,6 +54,7 @@ endif()
|
||||
|
||||
if(SHERPA_ONNX_ENABLE_TTS)
|
||||
list(APPEND srcs
|
||||
offline-tts-kokoro-model-config.cc
|
||||
offline-tts-matcha-model-config.cc
|
||||
offline-tts-model-config.cc
|
||||
offline-tts-vits-model-config.cc
|
||||
|
||||
31
sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.cc
Normal file
31
sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.cc
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts-kokoro-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsKokoroModelConfig(py::module *m) {
|
||||
using PyClass = OfflineTtsKokoroModelConfig;
|
||||
|
||||
py::class_<PyClass>(*m, "OfflineTtsKokoroModelConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const std::string &, const std::string &,
|
||||
const std::string &, const std::string &, float>(),
|
||||
py::arg("model"), py::arg("voices"), py::arg("tokens"),
|
||||
py::arg("data_dir"), py::arg("length_scale") = 1.0)
|
||||
.def_readwrite("model", &PyClass::model)
|
||||
.def_readwrite("voices", &PyClass::voices)
|
||||
.def_readwrite("tokens", &PyClass::tokens)
|
||||
.def_readwrite("data_dir", &PyClass::data_dir)
|
||||
.def_readwrite("length_scale", &PyClass::length_scale)
|
||||
.def("__str__", &PyClass::ToString)
|
||||
.def("validate", &PyClass::Validate);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.h
Normal file
16
sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.h
|
||||
//
|
||||
// Copyright (c) 2025 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_KOKORO_MODEL_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_KOKORO_MODEL_CONFIG_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsKokoroModelConfig(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_KOKORO_MODEL_CONFIG_H_
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-kokoro-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-matcha-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-vits-model-config.h"
|
||||
|
||||
@@ -15,20 +16,24 @@ namespace sherpa_onnx {
|
||||
void PybindOfflineTtsModelConfig(py::module *m) {
|
||||
PybindOfflineTtsVitsModelConfig(m);
|
||||
PybindOfflineTtsMatchaModelConfig(m);
|
||||
PybindOfflineTtsKokoroModelConfig(m);
|
||||
|
||||
using PyClass = OfflineTtsModelConfig;
|
||||
|
||||
py::class_<PyClass>(*m, "OfflineTtsModelConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const OfflineTtsVitsModelConfig &,
|
||||
const OfflineTtsMatchaModelConfig &, int32_t, bool,
|
||||
const OfflineTtsMatchaModelConfig &,
|
||||
const OfflineTtsKokoroModelConfig &, int32_t, bool,
|
||||
const std::string &>(),
|
||||
py::arg("vits") = OfflineTtsVitsModelConfig{},
|
||||
py::arg("matcha") = OfflineTtsMatchaModelConfig{},
|
||||
py::arg("kokoro") = OfflineTtsKokoroModelConfig{},
|
||||
py::arg("num_threads") = 1, py::arg("debug") = false,
|
||||
py::arg("provider") = "cpu")
|
||||
.def_readwrite("vits", &PyClass::vits)
|
||||
.def_readwrite("matcha", &PyClass::matcha)
|
||||
.def_readwrite("kokoro", &PyClass::kokoro)
|
||||
.def_readwrite("num_threads", &PyClass::num_threads)
|
||||
.def_readwrite("debug", &PyClass::debug)
|
||||
.def_readwrite("provider", &PyClass::provider)
|
||||
|
||||
Reference in New Issue
Block a user