Emmylahot12 commited on
Commit
a68ddcb
·
verified ·
1 Parent(s): da2fe4a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import soundfile as sf
5
+ import os
6
+
7
+ MODEL_PATH = "model/clone_tts_model.h5"
8
+ TEXT_MAX_LEN = 100
9
+ SAMPLE_RATE = 22050
10
+
11
+ # Load model once
12
+ model = tf.keras.models.load_model(MODEL_PATH)
13
+
14
+ def synthesize(text):
15
+ x_input = np.array([[ord(c) for c in text.ljust(TEXT_MAX_LEN)[:TEXT_MAX_LEN]]])
16
+ audio = model.predict(x_input)[0]
17
+ output_path = "output/generated.wav"
18
+ os.makedirs("output", exist_ok=True)
19
+ sf.write(output_path, audio, SAMPLE_RATE)
20
+ return output_path
21
+
22
+ demo = gr.Interface(
23
+ fn=synthesize,
24
+ inputs=gr.Textbox(label="Enter Text"),
25
+ outputs=gr.Audio(label="Generated Speech", type="filepath"),
26
+ title="Clone TTS",
27
+ description="A simple Text-to-Speech model trained on the 'clone' dataset."
28
+ )
29
+
30
+ if __name__ == "__main__":
31
+ demo.launch()