Skip to content

Commit

Permalink
Support Chinese heteronyms on Android for TTS. (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Apr 8, 2024
1 parent 6b3d2b8 commit 0d90b34
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
16 changes: 8 additions & 8 deletions cmake/openfst.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
function(download_openfst)
include(FetchContent)

set(openfst_URL "https://github.com/kkm000/openfst/archive/refs/tags/win/1.6.5.1.tar.gz")
set(openfst_URL2 "https://hub.nuaa.cf/kkm000/openfst/archive/refs/tags/win/1.6.5.1.tar.gz")
set(openfst_HASH "SHA256=02c49b559c3976a536876063369efc0e41ab374be1035918036474343877046e")
set(openfst_URL "https://github.com/csukuangfj/openfst/archive/792965fda2a3bc29f282321f527af0d6ba26fd22.zip")
set(openfst_URL2 "https://hub.nuaa.cf/csukuangfj/openfst/archive/792965fda2a3bc29f282321f527af0d6ba26fd22.zip")
set(openfst_HASH "SHA256=815d8acf555e4aaece294d6280ec209d0e9d91e0120e8406b24ff7124ecdbb26")

# If you don't have access to the Internet,
# please pre-download it
set(possible_file_locations
$ENV{HOME}/Downloads/openfst-win-1.6.5.1.tar.gz
${CMAKE_SOURCE_DIR}/openfst-win-1.6.5.1.tar.gz
${CMAKE_BINARY_DIR}/openfst-win-1.6.5.1.tar.gz
/tmp/openfst-win-1.6.5.1.tar.gz
/star-fj/fangjun/download/github/openfst-win-1.6.5.1.tar.gz
$ENV{HOME}/Downloads/openfst-792965fda2a3bc29f282321f527af0d6ba26fd22.zip
${CMAKE_SOURCE_DIR}/openfst-792965fda2a3bc29f282321f527af0d6ba26fd22.zip
${CMAKE_BINARY_DIR}/openfst-792965fda2a3bc29f282321f527af0d6ba26fd22.zip
/tmp/openfst-792965fda2a3bc29f282321f527af0d6ba26fd22.zip
/star-fj/fangjun/download/github/openfst-792965fda2a3bc29f282321f527af0d6ba26fd22.zip
)

foreach(f IN LISTS possible_file_locations)
Expand Down
8 changes: 4 additions & 4 deletions scripts/dotnet/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def process_linux(s):
"libpiper_phonemize.so.1",
"libsherpa-onnx-c-api.so",
"libsherpa-onnx-core.so",
"libsherpa-onnx-fstfar.so.7",
"libsherpa-onnx-fst.so.6",
"libsherpa-onnx-fstfar.so.16",
"libsherpa-onnx-fst.so.16",
"libsherpa-onnx-kaldifst-core.so",
"libucd.so",
]
Expand Down Expand Up @@ -69,8 +69,8 @@ def process_macos(s):
"libpiper_phonemize.1.dylib",
"libsherpa-onnx-c-api.dylib",
"libsherpa-onnx-core.dylib",
"libsherpa-onnx-fstfar.7.dylib",
"libsherpa-onnx-fst.6.dylib",
"libsherpa-onnx-fstfar.16.dylib",
"libsherpa-onnx-fst.16.dylib",
"libsherpa-onnx-kaldifst-core.dylib",
"libucd.dylib",
]
Expand Down
31 changes: 31 additions & 0 deletions sherpa-onnx/csrc/offline-tts-vits-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
}
std::vector<std::string> files;
SplitStringToVector(config.rule_fars, ",", false, &files);

tn_list_.reserve(files.size() + tn_list_.size());

for (const auto &f : files) {
if (config.model.debug) {
SHERPA_ONNX_LOGE("rule far: %s", f.c_str());
Expand Down Expand Up @@ -96,6 +99,34 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
tn_list_.push_back(std::make_unique<kaldifst::TextNormalizer>(is));
}
}

if (!config.rule_fars.empty()) {
std::vector<std::string> files;
SplitStringToVector(config.rule_fars, ",", false, &files);
tn_list_.reserve(files.size() + tn_list_.size());

for (const auto &f : files) {
if (config.model.debug) {
SHERPA_ONNX_LOGE("rule far: %s", f.c_str());
}

auto buf = ReadFile(mgr, f);

std::unique_ptr<std::istream> s(
new std::istrstream(buf.data(), buf.size()));

std::unique_ptr<fst::FarReader<fst::StdArc>> reader(
fst::FarReader<fst::StdArc>::Open(std::move(s)));

for (; !reader->Done(); reader->Next()) {
std::unique_ptr<fst::StdConstFst> r(
fst::CastOrConvertToConstFst(reader->GetFst()->Copy()));

tn_list_.push_back(
std::make_unique<kaldifst::TextNormalizer>(std::move(r)));
} // for (; !reader->Done(); reader->Next())
} // for (const auto &f : files)
} // if (!config.rule_fars.empty())
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions sherpa-onnx/python/csrc/offline-stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "sherpa-onnx/python/csrc/offline-stream.h"

#include <vector>

#include "sherpa-onnx/csrc/offline-stream.h"

namespace sherpa_onnx {
Expand Down
2 changes: 2 additions & 0 deletions sherpa-onnx/python/csrc/online-stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "sherpa-onnx/python/csrc/online-stream.h"

#include <vector>

#include "sherpa-onnx/csrc/online-stream.h"

namespace sherpa_onnx {
Expand Down

0 comments on commit 0d90b34

Please sign in to comment.