Path: blob/master/examples/cppwin/TensorflowTTSCppInference/MultiBandMelGAN.cpp
1559 views
#include "MultiBandMelGAN.h"1#include <stdexcept>2#define IF_EXCEPT(cond,ex) if (cond){throw std::invalid_argument(ex);}3456bool MultiBandMelGAN::Initialize(const std::string & VocoderPath)7{8try {9MelGAN = new Model(VocoderPath);10}11catch (...) {12MelGAN = nullptr;13return false;1415}16return true;171819}2021TFTensor<float> MultiBandMelGAN::DoInference(const TFTensor<float>& InMel)22{23IF_EXCEPT(!MelGAN, "Tried to infer MB-MelGAN on uninitialized model!!!!")2425// Convenience reference so that we don't have to constantly derefer pointers.26Model& Mdl = *MelGAN;2728Tensor input_mels{ Mdl,"serving_default_mels" };29input_mels.set_data(InMel.Data, InMel.Shape);3031Tensor out_audio{ Mdl,"StatefulPartitionedCall" };3233MelGAN->run(input_mels, out_audio);3435TFTensor<float> RetTensor = VoxUtil::CopyTensor<float>(out_audio);3637return RetTensor;383940}4142MultiBandMelGAN::MultiBandMelGAN()43{44MelGAN = nullptr;45}464748MultiBandMelGAN::~MultiBandMelGAN()49{50if (MelGAN)51delete MelGAN;5253}545556