Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cppwin/TensorflowTTSCppInference/VoxCommon.cpp
1559 views
1
#include "VoxCommon.hpp"
2
#include "ext/json.hpp"
3
using namespace nlohmann;
4
5
const std::vector<std::string> Text2MelNames = {"FastSpeech2","Tacotron2"};
6
const std::vector<std::string> VocoderNames = {"Multi-Band MelGAN"};
7
const std::vector<std::string> RepoNames = {"TensorflowTTS"};
8
9
const std::vector<std::string> LanguageNames = {"English","Spanish"};
10
11
12
void VoxUtil::ExportWAV(const std::string & Filename, const std::vector<float>& Data, unsigned SampleRate) {
13
AudioFile<float>::AudioBuffer Buffer;
14
Buffer.resize(1);
15
16
17
Buffer[0] = Data;
18
size_t BufSz = Data.size();
19
20
21
AudioFile<float> File;
22
File.setAudioBuffer(Buffer);
23
File.setAudioBufferSize(1, (int)BufSz);
24
File.setNumSamplesPerChannel((int)BufSz);
25
File.setNumChannels(1);
26
File.setBitDepth(32);
27
File.setSampleRate(SampleRate);
28
29
File.save(Filename, AudioFileFormat::Wave);
30
31
32
33
}
34
35
VoiceInfo VoxUtil::ReadModelJSON(const std::string &InfoFilename)
36
{
37
const size_t MaxNoteSize = 80;
38
39
std::ifstream JFile(InfoFilename);
40
json JS;
41
42
JFile >> JS;
43
44
45
JFile.close();
46
47
auto Arch = JS["architecture"];
48
49
ArchitectureInfo CuArch;
50
CuArch.Repo = Arch["repo"].get<int>();
51
CuArch.Text2Mel = Arch["text2mel"].get<int>();
52
CuArch.Vocoder = Arch["vocoder"].get<int>();
53
54
// Now fill the strings
55
CuArch.s_Repo = RepoNames[CuArch.Repo];
56
CuArch.s_Text2Mel = Text2MelNames[CuArch.Text2Mel];
57
CuArch.s_Vocoder = VocoderNames[CuArch.Vocoder];
58
59
60
uint32_t Lang = JS["language"].get<uint32_t>();
61
VoiceInfo Inf{JS["name"].get<std::string>(),
62
JS["author"].get<std::string>(),
63
JS["version"].get<int>(),
64
JS["description"].get<std::string>(),
65
CuArch,
66
JS["note"].get<std::string>(),
67
JS["sarate"].get<uint32_t>(),
68
Lang,
69
LanguageNames[Lang],
70
" " + JS["pad"].get<std::string>()}; // Add a space for separation since we directly append the value to the prompt
71
72
if (Inf.Note.size() > MaxNoteSize)
73
Inf.Note = Inf.Note.substr(0,MaxNoteSize);
74
75
return Inf;
76
77
78
79
80
81
82
83
}
84
85