File size: 837 Bytes
a68ddcb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import tensorflow as tf
import numpy as np
import soundfile as sf
import os

MODEL_PATH = "model/clone_tts_model.h5"
TEXT_MAX_LEN = 100
SAMPLE_RATE = 22050

# Load model once
model = tf.keras.models.load_model(MODEL_PATH)

def synthesize(text):
    x_input = np.array([[ord(c) for c in text.ljust(TEXT_MAX_LEN)[:TEXT_MAX_LEN]]])
    audio = model.predict(x_input)[0]
    output_path = "output/generated.wav"
    os.makedirs("output", exist_ok=True)
    sf.write(output_path, audio, SAMPLE_RATE)
    return output_path

demo = gr.Interface(
    fn=synthesize,
    inputs=gr.Textbox(label="Enter Text"),
    outputs=gr.Audio(label="Generated Speech", type="filepath"),
    title="Clone TTS",
    description="A simple Text-to-Speech model trained on the 'clone' dataset."
)

if __name__ == "__main__":
    demo.launch()