piper-phonemize-test.cc
2.1 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// sherpa-onnx/csrc/piper-phonemize-test.cc
//
// Copyright (c) 2023 Xiaomi Corporation
#include "espeak-ng/speak_lib.h"
#include "gtest/gtest.h"
#include "phoneme_ids.hpp"
#include "phonemize.hpp"
#include "sherpa-onnx/csrc/file-utils.h"
#include "sherpa-onnx/csrc/macros.h"
namespace sherpa_onnx {
TEST(PiperPhonemize, Case1) {
std::string data_dir = "./install/share/espeak-ng-data";
if (!FileExists(data_dir + "/en_dict")) {
SHERPA_ONNX_LOGE("%s/en_dict does not exist. Skipping test",
data_dir.c_str());
return;
}
if (!FileExists(data_dir + "/phontab")) {
SHERPA_ONNX_LOGE("%s/phontab does not exist. Skipping test",
data_dir.c_str());
return;
}
if (!FileExists(data_dir + "/phonindex")) {
SHERPA_ONNX_LOGE("%s/phonindex does not exist. Skipping test",
data_dir.c_str());
return;
}
if (!FileExists(data_dir + "/phondata")) {
SHERPA_ONNX_LOGE("%s/phondata does not exist. Skipping test",
data_dir.c_str());
return;
}
if (!FileExists(data_dir + "/intonations")) {
SHERPA_ONNX_LOGE("%s/intonations does not exist. Skipping test",
data_dir.c_str());
return;
}
int32_t result =
espeak_Initialize(AUDIO_OUTPUT_SYNCHRONOUS, 0, data_dir.c_str(), 0);
EXPECT_EQ(result, 22050);
piper::eSpeakPhonemeConfig config;
// ./bin/espeak-ng-bin --path ./install/share/espeak-ng-data/ --voices
// to list available voices
config.voice = "en-us";
std::vector<std::vector<piper::Phoneme>> phonemes;
std::string text = "how are you doing?";
piper::phonemize_eSpeak(text, config, phonemes);
for (int32_t p : phonemes[0]) {
std::cout << p << " ";
}
std::cout << "\n";
std::vector<piper::PhonemeId> phoneme_ids;
std::map<piper::Phoneme, std::size_t> missing_phonemes;
{
piper::PhonemeIdConfig config;
phonemes_to_ids(phonemes[0], config, phoneme_ids, missing_phonemes);
}
for (int32_t p : phoneme_ids) {
std::cout << p << " ";
}
std::cout << "\n";
}
} // namespace sherpa_onnx