homophone-replacer.h
1.3 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
49
50
51
52
53
54
55
56
57
58
// sherpa-onnx/csrc/homophone-replacer.h
//
// Copyright (c) 2025 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_HOMOPHONE_REPLACER_H_
#define SHERPA_ONNX_CSRC_HOMOPHONE_REPLACER_H_
#include <memory>
#include <string>
#include "sherpa-onnx/csrc/parse-options.h"
namespace sherpa_onnx {
struct HomophoneReplacerConfig {
std::string dict_dir;
std::string lexicon;
// comma separated fst files, e.g. a.fst,b.fst,c.fst
std::string rule_fsts;
bool debug;
HomophoneReplacerConfig() = default;
HomophoneReplacerConfig(const std::string &dict_dir,
const std::string &lexicon,
const std::string &rule_fsts, bool debug)
: dict_dir(dict_dir),
lexicon(lexicon),
rule_fsts(rule_fsts),
debug(debug) {}
void Register(ParseOptions *po);
bool Validate() const;
std::string ToString() const;
};
class HomophoneReplacer {
public:
explicit HomophoneReplacer(const HomophoneReplacerConfig &config);
template <typename Manager>
HomophoneReplacer(Manager *mgr, const HomophoneReplacerConfig &config);
~HomophoneReplacer();
std::string Apply(const std::string &text) const;
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_HOMOPHONE_REPLACER_H_