File size: 2,114 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
#include "VoxCommon.hpp"
#include "ext/json.hpp"
using namespace nlohmann;
const std::vector<std::string> Text2MelNames = {"FastSpeech2","Tacotron2"};
const std::vector<std::string> VocoderNames = {"Multi-Band MelGAN"};
const std::vector<std::string> RepoNames = {"TensorflowTTS"};
const std::vector<std::string> LanguageNames = {"English","Spanish"};
void VoxUtil::ExportWAV(const std::string & Filename, const std::vector<float>& Data, unsigned SampleRate) {
AudioFile<float>::AudioBuffer Buffer;
Buffer.resize(1);
Buffer[0] = Data;
size_t BufSz = Data.size();
AudioFile<float> 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<int>();
CuArch.Text2Mel = Arch["text2mel"].get<int>();
CuArch.Vocoder = Arch["vocoder"].get<int>();
// 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<uint32_t>();
VoiceInfo Inf{JS["name"].get<std::string>(),
JS["author"].get<std::string>(),
JS["version"].get<int>(),
JS["description"].get<std::string>(),
CuArch,
JS["note"].get<std::string>(),
JS["sarate"].get<uint32_t>(),
Lang,
LanguageNames[Lang],
" " + JS["pad"].get<std::string>()}; // 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;
}
|