Fangjun Kuang
Committed by GitHub

Support Chinese heteronyms on Android for TTS. (#742)

@@ -3,18 +3,18 @@ @@ -3,18 +3,18 @@
3 function(download_openfst) 3 function(download_openfst)
4 include(FetchContent) 4 include(FetchContent)
5 5
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")
9 9
10 # If you don't have access to the Internet, 10 # If you don't have access to the Internet,
11 # please pre-download it 11 # please pre-download it
12 set(possible_file_locations 12 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
18 ) 18 )
19 19
20 foreach(f IN LISTS possible_file_locations) 20 foreach(f IN LISTS possible_file_locations)
@@ -40,8 +40,8 @@ def process_linux(s): @@ -40,8 +40,8 @@ def process_linux(s):
40 "libpiper_phonemize.so.1", 40 "libpiper_phonemize.so.1",
41 "libsherpa-onnx-c-api.so", 41 "libsherpa-onnx-c-api.so",
42 "libsherpa-onnx-core.so", 42 "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",
45 "libsherpa-onnx-kaldifst-core.so", 45 "libsherpa-onnx-kaldifst-core.so",
46 "libucd.so", 46 "libucd.so",
47 ] 47 ]
@@ -69,8 +69,8 @@ def process_macos(s): @@ -69,8 +69,8 @@ def process_macos(s):
69 "libpiper_phonemize.1.dylib", 69 "libpiper_phonemize.1.dylib",
70 "libsherpa-onnx-c-api.dylib", 70 "libsherpa-onnx-c-api.dylib",
71 "libsherpa-onnx-core.dylib", 71 "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",
74 "libsherpa-onnx-kaldifst-core.dylib", 74 "libsherpa-onnx-kaldifst-core.dylib",
75 "libucd.dylib", 75 "libucd.dylib",
76 ] 76 ]
@@ -56,6 +56,9 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl { @@ -56,6 +56,9 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
56 } 56 }
57 std::vector<std::string> files; 57 std::vector<std::string> files;
58 SplitStringToVector(config.rule_fars, ",", false, &files); 58 SplitStringToVector(config.rule_fars, ",", false, &files);
  59 +
  60 + tn_list_.reserve(files.size() + tn_list_.size());
  61 +
59 for (const auto &f : files) { 62 for (const auto &f : files) {
60 if (config.model.debug) { 63 if (config.model.debug) {
61 SHERPA_ONNX_LOGE("rule far: %s", f.c_str()); 64 SHERPA_ONNX_LOGE("rule far: %s", f.c_str());
@@ -96,6 +99,34 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl { @@ -96,6 +99,34 @@ class OfflineTtsVitsImpl : public OfflineTtsImpl {
96 tn_list_.push_back(std::make_unique<kaldifst::TextNormalizer>(is)); 99 tn_list_.push_back(std::make_unique<kaldifst::TextNormalizer>(is));
97 } 100 }
98 } 101 }
  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())
99 } 130 }
100 #endif 131 #endif
101 132
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 4
5 #include "sherpa-onnx/python/csrc/offline-stream.h" 5 #include "sherpa-onnx/python/csrc/offline-stream.h"
6 6
  7 +#include <vector>
  8 +
7 #include "sherpa-onnx/csrc/offline-stream.h" 9 #include "sherpa-onnx/csrc/offline-stream.h"
8 10
9 namespace sherpa_onnx { 11 namespace sherpa_onnx {
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 4
5 #include "sherpa-onnx/python/csrc/online-stream.h" 5 #include "sherpa-onnx/python/csrc/online-stream.h"
6 6
  7 +#include <vector>
  8 +
7 #include "sherpa-onnx/csrc/online-stream.h" 9 #include "sherpa-onnx/csrc/online-stream.h"
8 10
9 namespace sherpa_onnx { 11 namespace sherpa_onnx {