-
Notifications
You must be signed in to change notification settings - Fork 544
/
Copy pathtest.cpp
60 lines (47 loc) · 1.37 KB
/
test.cpp
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
#include <fstream>
#include <functional>
#include <iostream>
#include <optional>
#include <stdexcept>
#include <string>
#include <vector>
#include "json.hpp"
#include "piper.hpp"
using namespace std;
using json = nlohmann::json;
int main(int argc, char *argv[]) {
piper::PiperConfig piperConfig;
piper::Voice voice;
if (argc < 2) {
std::cerr << "Need voice model path" << std::endl;
return 1;
}
if (argc < 3) {
std::cerr << "Need espeak-ng-data path" << std::endl;
return 1;
}
if (argc < 4) {
std::cerr << "Need output WAV path" << std::endl;
return 1;
}
auto modelPath = std::string(argv[1]);
piperConfig.eSpeakDataPath = std::string(argv[2]);
auto outputPath = std::string(argv[3]);
optional<piper::SpeakerId> speakerId;
loadVoice(piperConfig, modelPath, modelPath + ".json", voice, speakerId,
false);
piper::initialize(piperConfig);
// Output audio to WAV file
ofstream audioFile(outputPath, ios::binary);
piper::SynthesisResult result;
piper::textToWavFile(piperConfig, voice, "This is a test.", audioFile,
result);
piper::terminate(piperConfig);
// Verify that file has some data
if (audioFile.tellp() < 10000) {
std::cerr << "ERROR: Output file is smaller than expected!" << std::endl;
return EXIT_FAILURE;
}
std::cout << "OK" << std::endl;
return EXIT_SUCCESS;
}