File size: 993 Bytes
d5ee97c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
#include "MultiBandMelGAN.h"
#include <stdexcept>
#define IF_EXCEPT(cond,ex) if (cond){throw std::invalid_argument(ex);}



bool MultiBandMelGAN::Initialize(const std::string & VocoderPath)
{
	try {
		MelGAN = new Model(VocoderPath);
	}
	catch (...) {
		MelGAN = nullptr;
		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.
	Model& Mdl = *MelGAN;

	Tensor input_mels{ Mdl,"serving_default_mels" };
	input_mels.set_data(InMel.Data, InMel.Shape);

	Tensor out_audio{ Mdl,"StatefulPartitionedCall" };

	MelGAN->run(input_mels, out_audio);

	TFTensor<float> RetTensor = VoxUtil::CopyTensor<float>(out_audio);

	return RetTensor;


}

MultiBandMelGAN::MultiBandMelGAN()
{
	MelGAN = nullptr;
}


MultiBandMelGAN::~MultiBandMelGAN()
{
    if (MelGAN)
        delete MelGAN;

}