-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZHG2P.h
More file actions
48 lines (38 loc) · 1.38 KB
/
Copy pathZHG2P.h
File metadata and controls
48 lines (38 loc) · 1.38 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
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <memory>
#include <utility>
#include "Utils.h"
#include "ZHFrontend.h"
#include "EnG2P.h"
// ZHG2P class definition...
class ZHG2P {
public:
// 构造函数注入文本处理器依赖
ZHG2P(std::shared_ptr<TextProcessor> processor, const std::string& version = "1.1", const std::string& unk = "<unk>", const std::string& eng_dict_path = "");
// 主调用接口: 返回 (IPA字符串, 附加信息/None)
std::pair<std::string, std::string> operator()(const std::string& text);
// 静态工具方法
static std::string retone(std::string p);
static std::string py2ipa(const std::string& py);
static std::string map_punctuation(std::string text);
// 核心逻辑
std::string legacy_call(const std::string& text);
struct PinyinParts {
std::string initial;
std::string final;
int tone;
};
static PinyinParts parse_pinyin(const std::string& pinyin);
bool is_chinese(const std::string& str);
private:
std::string version;
std::string unk;
std::shared_ptr<TextProcessor> processor;
std::unique_ptr<ZHFrontend> frontend;
std::unique_ptr<EnG2P> eng_g2p;
// IPA 转换相关的内部结构
static std::string pinyin_to_ipa_convert(const std::string& pinyin);
};