-
Notifications
You must be signed in to change notification settings - Fork 77
/
phonemize.hpp
80 lines (63 loc) · 2.42 KB
/
phonemize.hpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef PHOEMIZE_H_
#define PHOEMIZE_H_
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "shared.hpp"
#define CLAUSE_INTONATION_FULL_STOP 0x00000000
#define CLAUSE_INTONATION_COMMA 0x00001000
#define CLAUSE_INTONATION_QUESTION 0x00002000
#define CLAUSE_INTONATION_EXCLAMATION 0x00003000
#define CLAUSE_TYPE_CLAUSE 0x00040000
#define CLAUSE_TYPE_SENTENCE 0x00080000
#define CLAUSE_PERIOD (40 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_SENTENCE)
#define CLAUSE_COMMA (20 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE)
#define CLAUSE_QUESTION (40 | CLAUSE_INTONATION_QUESTION | CLAUSE_TYPE_SENTENCE)
#define CLAUSE_EXCLAMATION \
(45 | CLAUSE_INTONATION_EXCLAMATION | CLAUSE_TYPE_SENTENCE)
#define CLAUSE_COLON (30 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_CLAUSE)
#define CLAUSE_SEMICOLON (30 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE)
namespace piper {
typedef char32_t Phoneme;
typedef std::map<Phoneme, std::vector<Phoneme>> PhonemeMap;
struct eSpeakPhonemeConfig {
std::string voice = "en-us";
Phoneme period = U'.'; // CLAUSE_PERIOD
Phoneme comma = U','; // CLAUSE_COMMA
Phoneme question = U'?'; // CLAUSE_QUESTION
Phoneme exclamation = U'!'; // CLAUSE_EXCLAMATION
Phoneme colon = U':'; // CLAUSE_COLON
Phoneme semicolon = U';'; // CLAUSE_SEMICOLON
Phoneme space = U' ';
// Remove language switch flags like "(en)"
bool keepLanguageFlags = false;
std::shared_ptr<PhonemeMap> phonemeMap;
};
// Phonemizes text using espeak-ng.
// Returns phonemes for each sentence as a separate std::vector.
//
// Assumes espeak_Initialize has already been called.
PIPERPHONEMIZE_EXPORT void
phonemize_eSpeak(std::string text, eSpeakPhonemeConfig &config,
std::vector<std::vector<Phoneme>> &phonemes);
enum TextCasing {
CASING_IGNORE = 0,
CASING_LOWER = 1,
CASING_UPPER = 2,
CASING_FOLD = 3
};
// Configuration for phonemize_codepoints
struct CodepointsPhonemeConfig {
TextCasing casing = CASING_FOLD;
std::shared_ptr<PhonemeMap> phonemeMap;
};
// "Phonemizes" text as a series of normalized UTF-8 codepoints.
// Returns a single std::vector of "phonemes".
//
// Does not detect sentence boundaries.
PIPERPHONEMIZE_EXPORT void
phonemize_codepoints(std::string text, CodepointsPhonemeConfig &config,
std::vector<std::vector<Phoneme>> &phonemes);
} // namespace piper
#endif // PHONEMIZE_H_