add python API and examples for TTS (#364)
This commit is contained in:
@@ -14,6 +14,9 @@ pybind11_add_module(_sherpa_onnx
|
||||
offline-stream.cc
|
||||
offline-tdnn-model-config.cc
|
||||
offline-transducer-model-config.cc
|
||||
offline-tts-model-config.cc
|
||||
offline-tts-vits-model-config.cc
|
||||
offline-tts.cc
|
||||
offline-whisper-model-config.cc
|
||||
offline-zipformer-ctc-model-config.cc
|
||||
online-lm-config.cc
|
||||
|
||||
32
sherpa-onnx/python/csrc/offline-tts-model-config.cc
Normal file
32
sherpa-onnx/python/csrc/offline-tts-model-config.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-model-config.cc
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-model-config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-vits-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsModelConfig(py::module *m) {
|
||||
PybindOfflineTtsVitsModelConfig(m);
|
||||
|
||||
using PyClass = OfflineTtsModelConfig;
|
||||
|
||||
py::class_<PyClass>(*m, "OfflineTtsModelConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const OfflineTtsVitsModelConfig &, int32_t, bool,
|
||||
const std::string &>(),
|
||||
py::arg("vits"), py::arg("num_threads") = 1,
|
||||
py::arg("debug") = false, py::arg("provider") = "cpu")
|
||||
.def_readwrite("vits", &PyClass::vits)
|
||||
.def_readwrite("num_threads", &PyClass::num_threads)
|
||||
.def_readwrite("debug", &PyClass::debug)
|
||||
.def_readwrite("provider", &PyClass::provider)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-tts-model-config.h
Normal file
16
sherpa-onnx/python/csrc/offline-tts-model-config.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-model-config.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_MODEL_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_MODEL_CONFIG_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsModelConfig(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_MODEL_CONFIG_H_
|
||||
27
sherpa-onnx/python/csrc/offline-tts-vits-model-config.cc
Normal file
27
sherpa-onnx/python/csrc/offline-tts-vits-model-config.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-vits-model-config.cc
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-vits-model-config.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts-vits-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsVitsModelConfig(py::module *m) {
|
||||
using PyClass = OfflineTtsVitsModelConfig;
|
||||
|
||||
py::class_<PyClass>(*m, "OfflineTtsVitsModelConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const std::string &, const std::string &,
|
||||
const std::string &>(),
|
||||
py::arg("model"), py::arg("lexicon"), py::arg("tokens"))
|
||||
.def_readwrite("model", &PyClass::model)
|
||||
.def_readwrite("lexicon", &PyClass::lexicon)
|
||||
.def_readwrite("tokens", &PyClass::tokens)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-tts-vits-model-config.h
Normal file
16
sherpa-onnx/python/csrc/offline-tts-vits-model-config.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts-vits-model-config.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_VITS_MODEL_CONFIG_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_VITS_MODEL_CONFIG_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTtsVitsModelConfig(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_VITS_MODEL_CONFIG_H_
|
||||
46
sherpa-onnx/python/csrc/offline-tts.cc
Normal file
46
sherpa-onnx/python/csrc/offline-tts.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts.cc
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
#include "sherpa-onnx/python/csrc/offline-tts.h"
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts-model-config.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
static void PybindGeneratedAudio(py::module *m) {
|
||||
using PyClass = GeneratedAudio;
|
||||
py::class_<PyClass>(*m, "GeneratedAudio")
|
||||
.def(py::init<>())
|
||||
.def_readwrite("samples", &PyClass::samples)
|
||||
.def_readwrite("sample_rate", &PyClass::sample_rate)
|
||||
.def("__str__", [](PyClass &self) {
|
||||
std::ostringstream os;
|
||||
os << "GeneratedAudio(sample_rate=" << self.sample_rate << ", ";
|
||||
os << "num_samples=" << self.samples.size() << ")";
|
||||
return os.str();
|
||||
});
|
||||
}
|
||||
|
||||
static void PybindOfflineTtsConfig(py::module *m) {
|
||||
PybindOfflineTtsModelConfig(m);
|
||||
|
||||
using PyClass = OfflineTtsConfig;
|
||||
py::class_<PyClass>(*m, "OfflineTtsConfig")
|
||||
.def(py::init<>())
|
||||
.def(py::init<const OfflineTtsModelConfig &>(), py::arg("model"))
|
||||
.def_readwrite("model", &PyClass::model)
|
||||
.def("__str__", &PyClass::ToString);
|
||||
}
|
||||
|
||||
void PybindOfflineTts(py::module *m) {
|
||||
PybindOfflineTtsConfig(m);
|
||||
PybindGeneratedAudio(m);
|
||||
|
||||
using PyClass = OfflineTts;
|
||||
py::class_<PyClass>(*m, "OfflineTts")
|
||||
.def(py::init<const OfflineTtsConfig &>(), py::arg("config"))
|
||||
.def("generate", &PyClass::Generate);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
16
sherpa-onnx/python/csrc/offline-tts.h
Normal file
16
sherpa-onnx/python/csrc/offline-tts.h
Normal file
@@ -0,0 +1,16 @@
|
||||
// sherpa-onnx/python/csrc/offline-tts.h
|
||||
//
|
||||
// Copyright (c) 2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_H_
|
||||
#define SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_H_
|
||||
|
||||
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
void PybindOfflineTts(py::module *m);
|
||||
|
||||
}
|
||||
|
||||
#endif // SHERPA_ONNX_PYTHON_CSRC_OFFLINE_TTS_H_
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "sherpa-onnx/python/csrc/offline-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-recognizer.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-stream.h"
|
||||
#include "sherpa-onnx/python/csrc/offline-tts.h"
|
||||
#include "sherpa-onnx/python/csrc/online-lm-config.h"
|
||||
#include "sherpa-onnx/python/csrc/online-model-config.h"
|
||||
#include "sherpa-onnx/python/csrc/online-recognizer.h"
|
||||
@@ -45,6 +46,8 @@ PYBIND11_MODULE(_sherpa_onnx, m) {
|
||||
PybindVadModel(&m);
|
||||
PybindCircularBuffer(&m);
|
||||
PybindVoiceActivityDetector(&m);
|
||||
|
||||
PybindOfflineTts(&m);
|
||||
}
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
Reference in New Issue
Block a user