Fangjun Kuang
Committed by GitHub

Add friendly log messages for Android and HarmonyOs TTS users. (#2427)

@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 #include "sherpa-onnx/csrc/jieba.h" 5 #include "sherpa-onnx/csrc/jieba.h"
6 6
7 #include "sherpa-onnx/csrc/file-utils.h" 7 #include "sherpa-onnx/csrc/file-utils.h"
  8 +#include "sherpa-onnx/csrc/macros.h"
8 9
9 namespace sherpa_onnx { 10 namespace sherpa_onnx {
10 11
@@ -19,6 +20,21 @@ std::unique_ptr<cppjieba::Jieba> InitJieba(const std::string &dict_dir) { @@ -19,6 +20,21 @@ std::unique_ptr<cppjieba::Jieba> InitJieba(const std::string &dict_dir) {
19 std::string idf = dict_dir + "/idf.utf8"; 20 std::string idf = dict_dir + "/idf.utf8";
20 std::string stop_word = dict_dir + "/stop_words.utf8"; 21 std::string stop_word = dict_dir + "/stop_words.utf8";
21 22
  23 +#if __ANDROID_API__ >= 9 || defined(__OHOS__)
  24 + if (dict[0] != '/') {
  25 + SHERPA_ONNX_LOGE(
  26 + "You need to follow our examples to copy the jieba dict directory from "
  27 + "the assets folder to an external storage directory");
  28 +
  29 + SHERPA_ONNX_LOGE(
  30 + "Hint: Please see\n"
  31 + "https://github.com/k2-fsa/sherpa-onnx/blob/master/android/"
  32 + "SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/"
  33 + "engine/TtsEngine.kt#L193\n"
  34 + "The function copyDataDir()\n");
  35 + }
  36 +#endif
  37 +
22 AssertFileExists(dict); 38 AssertFileExists(dict);
23 AssertFileExists(hmm); 39 AssertFileExists(hmm);
24 AssertFileExists(user_dict); 40 AssertFileExists(user_dict);
@@ -247,6 +247,22 @@ static std::vector<int64_t> CoquiPhonemesToIds( @@ -247,6 +247,22 @@ static std::vector<int64_t> CoquiPhonemesToIds(
247 void InitEspeak(const std::string &data_dir) { 247 void InitEspeak(const std::string &data_dir) {
248 static std::once_flag init_flag; 248 static std::once_flag init_flag;
249 std::call_once(init_flag, [data_dir]() { 249 std::call_once(init_flag, [data_dir]() {
  250 +
  251 +#if __ANDROID_API__ >= 9 || defined(__OHOS__)
  252 + if (data_dir[0] != '/') {
  253 + SHERPA_ONNX_LOGE(
  254 + "You need to follow our examples to copy the espeak-ng-data "
  255 + "directory from the assets folder to an external storage directory.");
  256 +
  257 + SHERPA_ONNX_LOGE(
  258 + "Hint: Please see\n"
  259 + "https://github.com/k2-fsa/sherpa-onnx/blob/master/android/"
  260 + "SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/"
  261 + "engine/TtsEngine.kt#L188\n"
  262 + "The function copyDataDir()\n");
  263 + }
  264 +#endif
  265 +
250 int32_t result = 266 int32_t result =
251 espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_dir.c_str(), 0); 267 espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_dir.c_str(), 0);
252 if (result != 22050) { 268 if (result != 22050) {