def synthesize(text):
    input = text + "|00-" + lang + "|" + lang

    # Change to Multi_TTS path
    sys.path.append(
        os.path.join(os.path.dirname(__file__),
                     "dependencies/Multilingual_Text_to_Speech"))

    if "utils" in sys.modules: del sys.modules["utils"]

    from synthesize import synthesize
    from utils import build_model

    # Load Mulilingual pretrained model
    model = build_model(
        os.path.abspath("./dependencies/checkpoints/generated_switching.pyt"))
    model.eval()

    # generate spectogram
    spectogram = synthesize(model, "|" + input)

    # Change to WaveRNN Path
    sys.path.append(
        os.path.join(os.path.dirname(__file__), "dependencies/WaveRNN"))

    if "utils" in sys.modules: del sys.modules["utils"]

    from models.fatchord_version import WaveRNN
    from utils import hparams as hp
    from gen_wavernn import generate
    import torch

    # Load WaveRNN pretrained model
    hp.configure("hparams.py")
    model = WaveRNN(
        rnn_dims=hp.voc_rnn_dims,
        fc_dims=hp.voc_fc_dims,
        bits=hp.bits,
        pad=hp.voc_pad,
        upsample_factors=hp.voc_upsample_factors,
        feat_dims=hp.num_mels,
        compute_dims=hp.voc_compute_dims,
        res_out_dims=hp.voc_res_out_dims,
        res_blocks=hp.voc_res_blocks,
        hop_length=hp.hop_length,
        sample_rate=hp.sample_rate,
        mode=hp.voc_mode).to(
            torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
    model.load(
        os.path.join(os.path.dirname(__file__),
                     "dependencies/checkpoints/wavernn_weight.pyt"))

    waveform = generate(model, s, hp.voc_gen_batched, hp.voc_target,
                        hp.voc_overlap)

    f = write("./temp/result.wav", "x")
    f.write(waveform)
    f.close()
示例#2
0
sys.path.append(WAVERNN_FOLDER)

from gen_wavernn import generate
from utils import hparams as hp
from models.fatchord_version import WaveRNN

hp.configure(WAVERNN_FOLDER+'/hparams.py')
model = WaveRNN(rnn_dims=hp.voc_rnn_dims, fc_dims=hp.voc_fc_dims, bits=hp.bits, pad=hp.voc_pad, upsample_factors=hp.voc_upsample_factors,
                feat_dims=hp.num_mels, compute_dims=hp.voc_compute_dims, res_out_dims=hp.voc_res_out_dims, res_blocks=hp.voc_res_blocks,
                hop_length=hp.hop_length, sample_rate=hp.sample_rate, mode=hp.voc_mode).to('cpu')
model.load(CHECKPOINTS_FOLDER + "/" + wavernn_chpt)

y = []

ix=1
while os.path.exists(CHR_FOLDER+"/"+str(ix)+".npy"):
    print("Found", CHR_FOLDER+"/"+str(ix)+".npy")
    y.append(np.load(CHR_FOLDER+"/"+str(ix)+".npy"))
    ix+=1

idx=1
for s in y:
    waveform = generate(model, s, hp.voc_gen_batched,
                      hp.voc_target, hp.voc_overlap)
    sf.write("wg-"+str(idx)+".wav", waveform, hp.sample_rate)
    idx+=1
    



示例#3
0
from gen_wavernn import generate
from utils import hparams as hp
from models.fatchord_version import WaveRNN

hp.configure(WAVERNN_FOLDER+'/hparams.py')
model = WaveRNN(rnn_dims=hp.voc_rnn_dims, fc_dims=hp.voc_fc_dims, bits=hp.bits, pad=hp.voc_pad, upsample_factors=hp.voc_upsample_factors,
                feat_dims=hp.num_mels, compute_dims=hp.voc_compute_dims, res_out_dims=hp.voc_res_out_dims, res_blocks=hp.voc_res_blocks,
                hop_length=hp.hop_length, sample_rate=hp.sample_rate, mode=hp.voc_mode).to('cuda')
model.load(CHECKPOINTS_FOLDER + "/" + wavernn_chpt)

y = []


y.append(np.load(TACOTRON_FOLDER + "/1.npy"))
y.append(np.load(TACOTRON_FOLDER + "/2.npy"))
y.append(np.load(TACOTRON_FOLDER + "/3.npy"))
y.append(np.load(TACOTRON_FOLDER + "/4.npy"))
y.append(np.load(TACOTRON_FOLDER + "/5.npy"))
y.append(np.load(TACOTRON_FOLDER + "/6.npy"))
y.append(np.load(TACOTRON_FOLDER + "/7.npy"))
y.append(np.load(TACOTRON_FOLDER + "/8.npy"))

waveforms = [generate(model, s, hp.voc_gen_batched,
                      hp.voc_target, hp.voc_overlap) for s in y]

for idx, w in enumerate(waveforms):
    sf.write("wg-"+str(idx+1)+".wav", w, hp.sample_rate)



示例#4
0
model = WaveRNN(rnn_dims=hp.voc_rnn_dims,
                fc_dims=hp.voc_fc_dims,
                bits=hp.bits,
                pad=hp.voc_pad,
                upsample_factors=hp.voc_upsample_factors,
                feat_dims=hp.num_mels,
                compute_dims=hp.voc_compute_dims,
                res_out_dims=hp.voc_res_out_dims,
                res_blocks=hp.voc_res_blocks,
                hop_length=hp.hop_length,
                sample_rate=hp.sample_rate,
                mode=hp.voc_mode).to('cpu')
model.load(CHECKPOINTS_FOLDER + "/" + wavernn_chpt)

y = []

ix = 1
while os.path.exists(CHR_FOLDER + "/" + str(ix) + ".npy"):
    y.append(np.load(CHR_FOLDER + "/" + str(ix) + ".npy"))
    ix += 1

idx = 1
for s in y:
    waveform = generate(model,
                        s,
                        batched=True,
                        target=11025,
                        overlap=int(11025 / 4))
    sf.write("wg-" + str(idx) + ".wav", waveform, hp.sample_rate)
    idx += 1
示例#5
0
    sys.path.append(WAVERNN_FOLDER)

    from gen_wavernn import generate
    from utils import hparams as hp
    from models.fatchord_version import WaveRNN

    hp.configure(WAVERNN_FOLDER + '/hparams.py')
    model = WaveRNN(rnn_dims=hp.voc_rnn_dims,
                    fc_dims=hp.voc_fc_dims,
                    bits=hp.bits,
                    pad=hp.voc_pad,
                    upsample_factors=hp.voc_upsample_factors,
                    feat_dims=hp.num_mels,
                    compute_dims=hp.voc_compute_dims,
                    res_out_dims=hp.voc_res_out_dims,
                    res_blocks=hp.voc_res_blocks,
                    hop_length=hp.hop_length,
                    sample_rate=hp.sample_rate,
                    mode="RAW").to(device)

    model.load(CHECKPOINTS_FOLDER + "/" + wavernn_chpt)
    waveform = generate(model,
                        np.load(cwd + "/tmp.npy"),
                        batched=True,
                        target=hp.voc_target,
                        overlap=hp.voc_overlap)
    sf.write(cwd + "/tmp.wav", waveform, hp.sample_rate)

    sys.exit()