jieba.cc
1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// sherpa-onnx/csrc/jieba.cc
//
// Copyright (c) 2025 Xiaomi Corporation
#include "sherpa-onnx/csrc/jieba.h"
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
std::unique_ptr<cppjieba::Jieba> InitJieba(const std::string &dict_dir) {
if (dict_dir.empty()) {
return {};
}
std::string dict = dict_dir + "/jieba.dict.utf8";
std::string hmm = dict_dir + "/hmm_model.utf8";
std::string user_dict = dict_dir + "/user.dict.utf8";
std::string idf = dict_dir + "/idf.utf8";
std::string stop_word = dict_dir + "/stop_words.utf8";
#if __ANDROID_API__ >= 9 || defined(__OHOS__)
if (dict[0] != '/') {
SHERPA_ONNX_LOGE(
"You need to follow our examples to copy the jieba dict directory from "
"the assets folder to an external storage directory");
SHERPA_ONNX_LOGE(
"Hint: Please see\n"
"https://github.com/k2-fsa/sherpa-onnx/blob/master/android/"
"SherpaOnnxTtsEngine/app/src/main/java/com/k2fsa/sherpa/onnx/tts/"
"engine/TtsEngine.kt#L193\n"
"The function copyDataDir()\n");
}
#endif
AssertFileExists(dict);
AssertFileExists(hmm);
AssertFileExists(user_dict);
AssertFileExists(idf);
AssertFileExists(stop_word);
return std::make_unique<cppjieba::Jieba>(dict, hmm, user_dict, idf,
stop_word);
}
} // namespace sherpa_onnx