#include "VoxCommon.hpp" #include "ext/json.hpp" using namespace nlohmann; const std::vector Text2MelNames = {"FastSpeech2","Tacotron2"}; const std::vector VocoderNames = {"Multi-Band MelGAN"}; const std::vector RepoNames = {"TensorflowTTS"}; const std::vector LanguageNames = {"English","Spanish"}; void VoxUtil::ExportWAV(const std::string & Filename, const std::vector& Data, unsigned SampleRate) { AudioFile::AudioBuffer Buffer; Buffer.resize(1); Buffer[0] = Data; size_t BufSz = Data.size(); AudioFile File; File.setAudioBuffer(Buffer); File.setAudioBufferSize(1, (int)BufSz); File.setNumSamplesPerChannel((int)BufSz); File.setNumChannels(1); File.setBitDepth(32); File.setSampleRate(SampleRate); File.save(Filename, AudioFileFormat::Wave); } VoiceInfo VoxUtil::ReadModelJSON(const std::string &InfoFilename) { const size_t MaxNoteSize = 80; std::ifstream JFile(InfoFilename); json JS; JFile >> JS; JFile.close(); auto Arch = JS["architecture"]; ArchitectureInfo CuArch; CuArch.Repo = Arch["repo"].get(); CuArch.Text2Mel = Arch["text2mel"].get(); CuArch.Vocoder = Arch["vocoder"].get(); // Now fill the strings CuArch.s_Repo = RepoNames[CuArch.Repo]; CuArch.s_Text2Mel = Text2MelNames[CuArch.Text2Mel]; CuArch.s_Vocoder = VocoderNames[CuArch.Vocoder]; uint32_t Lang = JS["language"].get(); VoiceInfo Inf{JS["name"].get(), JS["author"].get(), JS["version"].get(), JS["description"].get(), CuArch, JS["note"].get(), JS["sarate"].get(), Lang, LanguageNames[Lang], " " + JS["pad"].get()}; // Add a space for separation since we directly append the value to the prompt if (Inf.Note.size() > MaxNoteSize) Inf.Note = Inf.Note.substr(0,MaxNoteSize); return Inf; }