Add C API for Kokoro TTS 1.0 (#1801)

This commit is contained in:
Fangjun Kuang
2025-02-07 14:30:40 +08:00
committed by GitHub
parent a52b819fb5
commit 7330f7519a
6 changed files with 128 additions and 0 deletions

View File

@@ -1120,6 +1120,10 @@ static sherpa_onnx::OfflineTtsConfig GetOfflineTtsConfig(
SHERPA_ONNX_OR(config->model.kokoro.data_dir, "");
tts_config.model.kokoro.length_scale =
SHERPA_ONNX_OR(config->model.kokoro.length_scale, 1.0);
tts_config.model.kokoro.dict_dir =
SHERPA_ONNX_OR(config->model.kokoro.dict_dir, "");
tts_config.model.kokoro.lexicon =
SHERPA_ONNX_OR(config->model.kokoro.lexicon, "");
tts_config.model.num_threads = SHERPA_ONNX_OR(config->model.num_threads, 1);
tts_config.model.debug = config->model.debug;

View File

@@ -926,6 +926,8 @@ SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsKokoroModelConfig {
const char *data_dir;
float length_scale; // < 1, faster in speech speed; > 1, slower in speed
const char *dict_dir;
const char *lexicon;
} SherpaOnnxOfflineTtsKokoroModelConfig;
SHERPA_ONNX_API typedef struct SherpaOnnxOfflineTtsModelConfig {

View File

@@ -4,6 +4,8 @@
#ifndef SHERPA_ONNX_CSRC_OFFLINE_TTS_KOKORO_IMPL_H_
#define SHERPA_ONNX_CSRC_OFFLINE_TTS_KOKORO_IMPL_H_
#include <iomanip>
#include <ios>
#include <memory>
#include <string>
#include <strstream>
@@ -188,6 +190,20 @@ class OfflineTtsKokoroImpl : public OfflineTtsImpl {
SHERPA_ONNX_LOGE("Raw text: %{public}s", text.c_str());
#else
SHERPA_ONNX_LOGE("Raw text: %s", text.c_str());
#endif
std::ostringstream os;
os << "In bytes (hex):\n";
const auto p = reinterpret_cast<const uint8_t *>(text.c_str());
for (int32_t i = 0; i != text.size(); ++i) {
os << std::setw(2) << std::setfill('0') << std::hex
<< static_cast<uint32_t>(p[i]) << " ";
}
os << "\n";
#if __OHOS__
SHERPA_ONNX_LOGE("%{public}s", os.str().c_str());
#else
SHERPA_ONNX_LOGE("%s", os.str().c_str());
#endif
}