Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cppwin/TensorflowTTSCppInference/VoxCommon.hpp
1559 views
1
#pragma once
2
/*
3
VoxCommon.hpp : Defines common data structures and constants to be used with TensorVox
4
*/
5
#include <iostream>
6
#include <vector>
7
#include "ext/AudioFile.hpp"
8
#include "ext/CppFlow/include/Tensor.h"
9
10
#define IF_RETURN(cond,ret) if (cond){return ret;}
11
12
13
14
template<typename T>
15
struct TFTensor {
16
std::vector<T> Data;
17
std::vector<int64_t> Shape;
18
size_t TotalSize;
19
20
};
21
22
23
namespace ETTSRepo {
24
enum Enum{
25
TensorflowTTS = 0,
26
MozillaTTS // not implemented yet
27
};
28
29
}
30
namespace EText2MelModel {
31
enum Enum{
32
FastSpeech2 = 0,
33
Tacotron2 // not implemented yet
34
};
35
36
}
37
38
namespace EVocoderModel{
39
enum Enum{
40
MultiBandMelGAN = 0
41
};
42
}
43
44
namespace ETTSLanguage{
45
enum Enum{
46
English = 0,
47
Spanish
48
};
49
50
}
51
52
53
54
struct ArchitectureInfo{
55
int Repo;
56
int Text2Mel;
57
int Vocoder;
58
59
// String versions of the info, for displaying.
60
// We want boilerplate int index to str conversion code to be low.
61
std::string s_Repo;
62
std::string s_Text2Mel;
63
std::string s_Vocoder;
64
65
};
66
struct VoiceInfo{
67
std::string Name;
68
std::string Author;
69
int32_t Version;
70
std::string Description;
71
ArchitectureInfo Architecture;
72
std::string Note;
73
74
uint32_t SampleRate;
75
76
uint32_t Language;
77
std::string s_Language;
78
79
std::string EndPadding;
80
81
82
83
};
84
85
namespace VoxUtil {
86
87
VoiceInfo ReadModelJSON(const std::string& InfoFilename);
88
89
90
template<typename F>
91
TFTensor<F> CopyTensor(Tensor& InTens)
92
{
93
std::vector<F> Data = InTens.get_data<F>();
94
std::vector<int64_t> Shape = InTens.get_shape();
95
size_t TotalSize = 1;
96
for (const int64_t& Dim : Shape)
97
TotalSize *= Dim;
98
99
return TFTensor<F>{Data, Shape, TotalSize};
100
101
102
}
103
104
template<typename V>
105
bool FindInVec(V In, const std::vector<V>& Vec, size_t& OutIdx, size_t start = 0) {
106
for (size_t xx = start;xx < Vec.size();xx++)
107
{
108
if (Vec[xx] == In) {
109
OutIdx = xx;
110
return true;
111
112
}
113
114
}
115
116
117
return false;
118
119
}
120
template<typename V, typename X>
121
bool FindInVec2(V In, const std::vector<X>& Vec, size_t& OutIdx, size_t start = 0) {
122
for (size_t xx = start;xx < Vec.size();xx++)
123
{
124
if (Vec[xx] == In) {
125
OutIdx = xx;
126
return true;
127
128
}
129
130
}
131
132
133
return false;
134
135
}
136
137
void ExportWAV(const std::string& Filename, const std::vector<float>& Data, unsigned SampleRate);
138
}
139
140