File size: 1,713 Bytes
dae4c4e
a4a22fd
dae4c4e
a4a22fd
 
c3ebb96
17722e5
a4a22fd
dae4c4e
 
a4a22fd
c3ebb96
 
 
dae4c4e
 
7c1157d
dae4c4e
 
 
 
 
 
46ebc44
 
c3ebb96
46ebc44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dae4c4e
2499cd4
dae4c4e
2499cd4
dae4c4e
 
 
 
17722e5
1204cff
dae4c4e
 
 
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
import os
import time
import torch
import urllib.request
import gradio as gr
import nltk
import numpy as np
import soundfile as sf
from espnet2.bin.tts_inference import Text2Speech
from espnet2.utils.types import str_or_none
from pathlib import Path
from nltk.tokenize import sent_tokenize

nltk.download('punkt')

gos_text2speech = Text2Speech.from_pretrained(
    model_tag="bartelds/gos_tts",
    device="cpu",
    speed_control_alpha=1.0,
    noise_scale=1.0,
    noise_scale_dur=1.0
)

def inference(text, lang):
    with torch.no_grad():
        lines = sent_tokenize(text.lower())
        outputs = []

        for line in lines:
            line = line.lower()
            if lang == "Hoogelaandsters":
                wav = gos_text2speech(line, sids=np.array([1]))["wav"]
            elif lang == "Oldambsters":
                wav = gos_text2speech(line, sids=np.array([2]))["wav"]
            elif lang == "Westerkertaaiers":
                wav = gos_text2speech(line, sids=np.array([3]))["wav"]

            outputs.append(wav)

        concatenated_wav = np.concatenate([o.view(-1).cpu().numpy() for o in outputs])
        sf.write("out.wav", concatenated_wav, gos_text2speech.fs)

    return "out.wav", "out.wav"

title = "Gronings text-to-speech"
examples = [
  ['Mamme mos even noar winkel om n bosschop.', 'Hoogelaandsters']
]

gr.Interface(
    inference,
    [gr.inputs.Textbox(label="Input text", lines=3), gr.inputs.Radio(choices=["Hoogelaandsters", "Oldambsters", "Westerkertaaiers"], type="value", default="Hoogelaandsters", label="Variant")], 
    [gr.outputs.Audio(type="file", label="Output"), gr.outputs.File()],
    title=title,
    examples=examples
    ).launch(enable_queue=True)