Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/examples/cppwin/TensorflowTTSCppInference/MultiBandMelGAN.cpp
1559 views
1
#include "MultiBandMelGAN.h"
2
#include <stdexcept>
3
#define IF_EXCEPT(cond,ex) if (cond){throw std::invalid_argument(ex);}
4
5
6
7
bool MultiBandMelGAN::Initialize(const std::string & VocoderPath)
8
{
9
try {
10
MelGAN = new Model(VocoderPath);
11
}
12
catch (...) {
13
MelGAN = nullptr;
14
return false;
15
16
}
17
return true;
18
19
20
}
21
22
TFTensor<float> MultiBandMelGAN::DoInference(const TFTensor<float>& InMel)
23
{
24
IF_EXCEPT(!MelGAN, "Tried to infer MB-MelGAN on uninitialized model!!!!")
25
26
// Convenience reference so that we don't have to constantly derefer pointers.
27
Model& Mdl = *MelGAN;
28
29
Tensor input_mels{ Mdl,"serving_default_mels" };
30
input_mels.set_data(InMel.Data, InMel.Shape);
31
32
Tensor out_audio{ Mdl,"StatefulPartitionedCall" };
33
34
MelGAN->run(input_mels, out_audio);
35
36
TFTensor<float> RetTensor = VoxUtil::CopyTensor<float>(out_audio);
37
38
return RetTensor;
39
40
41
}
42
43
MultiBandMelGAN::MultiBandMelGAN()
44
{
45
MelGAN = nullptr;
46
}
47
48
49
MultiBandMelGAN::~MultiBandMelGAN()
50
{
51
if (MelGAN)
52
delete MelGAN;
53
54
}
55
56