Fix passing gb2312 encoded strings to tts on Windows (#1819)

This commit is contained in:
Fangjun Kuang
2025-02-08 09:48:58 +08:00
committed by GitHub
parent 51b42748e5
commit d38cb81014
3 changed files with 155 additions and 0 deletions

View File

@@ -96,7 +96,27 @@ OfflineTts::~OfflineTts() = default;
GeneratedAudio OfflineTts::Generate(
const std::string &text, int64_t sid /*=0*/, float speed /*= 1.0*/,
GeneratedAudioCallback callback /*= nullptr*/) const {
#if !defined(_WIN32)
return impl_->Generate(text, sid, speed, std::move(callback));
#else
if (IsUtf8(text)) {
return impl_->Generate(text, sid, speed, std::move(callback));
} else if (IsGB2312(text)) {
auto utf8_text = Gb2312ToUtf8(text);
static bool printed = false;
if (!printed) {
SHERPA_ONNX_LOGE(
"Detected GB2312 encoded string! Converting it to UTF8.");
printed = true;
}
return impl_->Generate(utf8_text, sid, speed, std::move(callback));
} else {
SHERPA_ONNX_LOGE(
"Non UTF8 encoded string is received. You would not get expected "
"results!");
return impl_->Generate(text, sid, speed, std::move(callback));
}
#endif
}
int32_t OfflineTts::SampleRate() const { return impl_->SampleRate(); }