-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
29 lines (25 loc) · 1.02 KB
/
main.cpp
File metadata and controls
29 lines (25 loc) · 1.02 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
#include <iostream>
#include <chrono>
#include <string>
#include "wavfile.hpp"
#include "chatterbox.h"
#include "bpe_tokenizer.hpp"
int main(){
BPETokenizer tokenizer;
std::cout << "\nLoading tokenizer from tokenizer.json..." << std::endl;
if (!tokenizer.loadFromFile("assets/tokenizer.json")) {
std::cerr << "Failed to load tokenizer!" << std::endl;
return 1;
}
ChatterBox chatterbox("ModelDir", false);
chatterbox.LoadStyle("StyleDir");
std::string text = "Hello, welcome to my world!";
std::vector<int64_t> inputIds = tokenizer.encode(text, true);
std::vector<int64_t> generatedTokens = chatterbox.SynthesizeSpeechTokens(inputIds);
std::vector<int16_t> audioBuffer = chatterbox.synthesizeSpeech(generatedTokens);
std::ofstream audioFile("test.wav", std::ios::binary);
writeWavHeader(24000, 2, 1, (int32_t)audioBuffer.size(), audioFile);
audioFile.write((const char *)audioBuffer.data(), sizeof(int16_t) * audioBuffer.size());
audioFile.close();
return 0;
}