File size: 2,191 Bytes
a1f7e54
 
c4bb280
a1f7e54
c4bb280
 
 
631b35a
 
c4bb280
a1f7e54
 
 
 
c4bb280
a1f7e54
c4bb280
a5e4486
 
c4bb280
3500994
a1f7e54
 
 
 
 
 
c4bb280
 
2dd31fa
a1f7e54
 
c4bb280
a1f7e54
c4bb280
a1f7e54
 
 
c4bb280
a5e4486
c4bb280
 
936f09a
c4bb280
a1f7e54
 
 
 
ddf4bd4
c4bb280
a1f7e54
 
 
c4bb280
 
4b5957f
 
 
 
 
c4bb280
4b5957f
60d04ad
c4bb280
 
a1f7e54
 
 
 
4b5957f
 
 
 
a1f7e54
 
 
 
 
 
 
 
e77ccbf
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
import gradio as gr
import librosa
import numpy as np
import torch

from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan

from datasets import load_dataset


checkpoint = "microsoft/speecht5_tts"
processor = SpeechT5Processor.from_pretrained(checkpoint)
model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

default_voice = "CLB (female)"

embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)

speaker_embedding = {
    "BDL": "spkemb/cmu_us_bdl_arctic-wav-arctic_a0009.npy",
    "CLB": "spkemb/cmu_us_clb_arctic-wav-arctic_a0144.npy",
    "KSP": "spkemb/cmu_us_ksp_arctic-wav-arctic_b0087.npy",
    "RMS": "spkemb/cmu_us_rms_arctic-wav-arctic_b0353.npy",
    "SLT": "spkemb/cmu_us_slt_arctic-wav-arctic_a0508.npy",
}


def predict(text):
    if len(text.strip()) == 0:
        return (16000, np.zeros(0).astype(np.int16))

    inputs = processor(text=text, return_tensors="pt")

    # limit input length
    input_ids = inputs["input_ids"]
    input_ids = input_ids[..., :model.config.max_text_positions]

    
    

    speech = model.generate_speech(input_ids, speaker_embeddings, vocoder=vocoder)

    speech = (speech.numpy() * 32767).astype(np.int16)
    return (16000, speech)


title = "Prosody Project"

description = """
This is the Prosody Project for DT2112 Speech Technology
"""


# examples = [
#     ["Hi, my name is Santiago", "CLB (female)"],
#     ["Two bros, chilling in a hot tub, five feet apart cause they are not gay.", "CLB (female)"]
# ]

examples = [
    ["Hi, my name is Santiago"],
    ["I am becoming a vampire, so I would like no garlic, please."]
]

gr.Interface(
    fn=predict,
    inputs=[
        gr.Text(label="Input Text"),
        #gr.Radio(label="Speaker", choices=[
        #    "CLB (female)"
        #],
        # value="CLB (female)"),
    ],
    outputs=[
        gr.Audio(label="Generated Speech", type="numpy"),
    ],
    title=title,
    description=description,
    article=None,
    examples=examples,
).launch()