Skip to content

Commit 0d90b34

Browse files
authored
Support Chinese heteronyms on Android for TTS. (#742)
1 parent 6b3d2b8 commit 0d90b34

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

cmake/openfst.cmake

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
function(download_openfst)
44
include(FetchContent)
55

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

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

2020
foreach(f IN LISTS possible_file_locations)

scripts/dotnet/generate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def process_linux(s):
4040
"libpiper_phonemize.so.1",
4141
"libsherpa-onnx-c-api.so",
4242
"libsherpa-onnx-core.so",
43-
"libsherpa-onnx-fstfar.so.7",
44-
"libsherpa-onnx-fst.so.6",
43+
"libsherpa-onnx-fstfar.so.16",
44+
"libsherpa-onnx-fst.so.16",
4545
"libsherpa-onnx-kaldifst-core.so",
4646
"libucd.so",
4747
]
@@ -69,8 +69,8 @@ def process_macos(s):
6969
"libpiper_phonemize.1.dylib",
7070
"libsherpa-onnx-c-api.dylib",
7171
"libsherpa-onnx-core.dylib",
72-
"libsherpa-onnx-fstfar.7.dylib",
73-
"libsherpa-onnx-fst.6.dylib",
72+
"libsherpa-onnx-fstfar.16.dylib",
73+
"libsherpa-onnx-fst.16.dylib",
7474
"libsherpa-onnx-kaldifst-core.dylib",
7575
"libucd.dylib",
7676
]

sherpa-onnx/csrc/offline-tts-vits-impl.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
5656
}
5757
std::vector<std::string> files;
5858
SplitStringToVector(config.rule_fars, ",", false, &files);
59+
60+
tn_list_.reserve(files.size() + tn_list_.size());
61+
5962
for (const auto &f : files) {
6063
if (config.model.debug) {
6164
SHERPA_ONNX_LOGE("rule far: %s", f.c_str());
@@ -96,6 +99,34 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
9699
tn_list_.push_back(std::make_unique<kaldifst::TextNormalizer>(is));
97100
}
98101
}
102+
103+
if (!config.rule_fars.empty()) {
104+
std::vector<std::string> files;
105+
SplitStringToVector(config.rule_fars, ",", false, &files);
106+
tn_list_.reserve(files.size() + tn_list_.size());
107+
108+
for (const auto &f : files) {
109+
if (config.model.debug) {
110+
SHERPA_ONNX_LOGE("rule far: %s", f.c_str());
111+
}
112+
113+
auto buf = ReadFile(mgr, f);
114+
115+
std::unique_ptr<std::istream> s(
116+
new std::istrstream(buf.data(), buf.size()));
117+
118+
std::unique_ptr<fst::FarReader<fst::StdArc>> reader(
119+
fst::FarReader<fst::StdArc>::Open(std::move(s)));
120+
121+
for (; !reader->Done(); reader->Next()) {
122+
std::unique_ptr<fst::StdConstFst> r(
123+
fst::CastOrConvertToConstFst(reader->GetFst()->Copy()));
124+
125+
tn_list_.push_back(
126+
std::make_unique<kaldifst::TextNormalizer>(std::move(r)));
127+
} // for (; !reader->Done(); reader->Next())
128+
} // for (const auto &f : files)
129+
} // if (!config.rule_fars.empty())
99130
}
100131
#endif
101132

sherpa-onnx/python/csrc/offline-stream.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

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

7+
#include <vector>
8+
79
#include "sherpa-onnx/csrc/offline-stream.h"
810

911
namespace sherpa_onnx {

sherpa-onnx/python/csrc/online-stream.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

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

7+
#include <vector>
8+
79
#include "sherpa-onnx/csrc/online-stream.h"
810

911
namespace sherpa_onnx {

0 commit comments

Comments
 (0)