-
Notifications
You must be signed in to change notification settings - Fork 20
/
MultiBandMelGAN.cpp
52 lines (29 loc) · 933 Bytes
/
MultiBandMelGAN.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
#include "MultiBandMelGAN.h"
#define IF_EXCEPT(cond,ex) if (cond){throw std::exception(ex);}
bool MultiBandMelGAN::Initialize(const std::string & VocoderPath)
{
try {
MelGAN = std::make_unique<cppflow::model>(VocoderPath);
}
catch (...) {
return false;
}
return true;
}
TFTensor<float> MultiBandMelGAN::DoInference(const TFTensor<float>& InMel)
{
IF_EXCEPT(!MelGAN, "Tried to infer MB-MelGAN on uninitialized model!!!!")
// Convenience reference so that we don't have to constantly derefer pointers.
cppflow::model& Mdl = *MelGAN;
cppflow::tensor input_mels{ InMel.Data, InMel.Shape};
auto out_audio = Mdl({{"serving_default_mels:0",input_mels}}, {"StatefulPartitionedCall:0"})[0];
TFTensor<float> RetTensor = VoxUtil::CopyTensor<float>(out_audio);
return RetTensor;
}
MultiBandMelGAN::MultiBandMelGAN()
{
MelGAN = nullptr;
}
MultiBandMelGAN::~MultiBandMelGAN()
{
}