offline-tts-frontend.h
1.8 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-frontend.h
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_OFFLINE_TTS_FRONTEND_H_
#define SHERPA_ONNX_CSRC_OFFLINE_TTS_FRONTEND_H_
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
struct TokenIDs {
TokenIDs() = default;
/*implicit*/ TokenIDs(std::vector<int64_t> tokens) // NOLINT
: tokens{std::move(tokens)} {}
/*implicit*/ TokenIDs(const std::vector<int32_t> &tokens) // NOLINT
: tokens{tokens.begin(), tokens.end()} {}
TokenIDs(std::vector<int64_t> tokens, // NOLINT
std::vector<int64_t> tones) // NOLINT
: tokens{std::move(tokens)}, tones{std::move(tones)} {}
std::string ToString() const;
std::vector<int64_t> tokens;
// Used only in MeloTTS
std::vector<int64_t> tones;
};
class OfflineTtsFrontend {
public:
virtual ~OfflineTtsFrontend() = default;
/** 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.
*/
virtual std::vector<TokenIDs> ConvertTextToTokenIds(
const std::string &text, const std::string &voice = "") const = 0;
};
// implementation is in ./piper-phonemize-lexicon.cc
void InitEspeak(const std::string &data_dir);
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_OFFLINE_TTS_FRONTEND_H_