offline-tts-zipvoice-frontend.h
2.5 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
59
60
61
62
// sherpa-onnx/csrc/offline-tts-zipvoice-frontend.h
//
// Copyright (c) 2025 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_OFFLINE_TTS_ZIPVOICE_FRONTEND_H_
#define SHERPA_ONNX_CSRC_OFFLINE_TTS_ZIPVOICE_FRONTEND_H_
#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "cppinyin/csrc/cppinyin.h"
#include "sherpa-onnx/csrc/offline-tts-frontend.h"
#include "sherpa-onnx/csrc/offline-tts-zipvoice-model-meta-data.h"
namespace sherpa_onnx {
class OfflineTtsZipvoiceFrontend : public OfflineTtsFrontend {
public:
OfflineTtsZipvoiceFrontend(const std::string &tokens,
const std::string &data_dir,
const std::string &pinyin_dict,
const OfflineTtsZipvoiceModelMetaData &meta_data,
bool debug = false);
template <typename Manager>
OfflineTtsZipvoiceFrontend(Manager *mgr, const std::string &tokens,
const std::string &data_dir,
const std::string &pinyin_dict,
const OfflineTtsZipvoiceModelMetaData &meta_data,
bool debug = false);
/** Convert a string to token IDs.
*
* @param text The input text.
* Example 1: "This is the first sample sentence; this is the
* second one." Example 2: "这是第一句。这是第二句。"
* @param voice Optional. It is for espeak-ng.
*
* @return Return a vector-of-vector of token IDs. Each subvector contains
* a sentence that can be processed independently.
* If a frontend does not support splitting the text into
* sentences, the resulting vector contains only one subvector.
*/
std::vector<TokenIDs> ConvertTextToTokenIds(
const std::string &text, const std::string &voice = "") const override;
private:
bool debug_ = false;
std::unordered_map<std::string, int32_t> token2id_;
const std::unordered_map<std::string, std::string> punct_map_ = {
{",", ","}, {"。", "."}, {"!", "!"}, {"?", "?"}, {";", ";"},
{":", ":"}, {"、", ","}, {"‘", "'"}, {"“", "\""}, {"”", "\""},
{"’", "'"}, {"⋯", "…"}, {"···", "…"}, {"・・・", "…"}, {"...", "…"}};
OfflineTtsZipvoiceModelMetaData meta_data_;
std::unique_ptr<cppinyin::PinyinEncoder> pinyin_encoder_;
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_OFFLINE_TTS_ZIPVOICE_FRONTEND_H_