GeminiAi commited on
Commit
6f0abc8
·
verified ·
1 Parent(s): a07adb9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torchaudio
4
+ from tortoise.api import TextToSpeech
5
+ from tortoise.utils.audio import load_voice
6
+
7
+ # Initialize Tortoise-TTS
8
+ tts = TextToSpeech()
9
+
10
+ # Function to generate speech
11
+ def generate_speech(text, voice):
12
+ # Load the selected voice
13
+ voice_samples, conditioning_latents = load_voice(voice)
14
+
15
+ # Generate speech
16
+ with torch.no_grad():
17
+ gen = tts.tts_with_preset(text, voice_samples=voice_samples, conditioning_latents=conditioning_latents, preset="fast")
18
+ torchaudio.save("output.wav", gen.squeeze(0).cpu(), 24000)
19
+
20
+ return "output.wav"
21
+
22
+ # Gradio interface
23
+ def tts_app(text, voice):
24
+ if not text:
25
+ return "Please enter some text."
26
+ return generate_speech(text, voice)
27
+
28
+ # Gradio UI
29
+ with gr.Blocks(
30
+ theme=gr.themes.Soft(primary_hue="teal", secondary_hue="pink"),
31
+ css=".gradio-container {background: linear-gradient(135deg, #f5f7fa, #c3cfe2);} "
32
+ "button {background: linear-gradient(135deg, #6a11cb, #2575fc); color: white; border: none; padding: 10px 20px; border-radius: 5px;} "
33
+ "button:hover {background: linear-gradient(135deg, #2575fc, #6a11cb);} "
34
+ ) as demo:
35
+ gr.Markdown(
36
+ """
37
+ # 🎤 **Voice Cloning and Text-to-Speech**
38
+ **Convert text into natural-sounding speech or clone a voice!**
39
+ """
40
+ )
41
+
42
+ with gr.Row():
43
+ text_input = gr.Textbox(
44
+ lines=5,
45
+ label="📝 **Enter Text**",
46
+ placeholder="Type your text here..."
47
+ )
48
+ voice_input = gr.Dropdown(
49
+ choices=["random", "custom_voice"], # Add more voices as needed
50
+ label="🗣️ **Select Voice**",
51
+ value="random"
52
+ )
53
+
54
+ output_audio = gr.Audio(label="🎧 **Generated Speech**", type="filepath")
55
+
56
+ submit_button = gr.Button("✨ **Generate Speech**")
57
+
58
+ submit_button.click(
59
+ tts_app,
60
+ inputs=[text_input, voice_input],
61
+ outputs=output_audio
62
+ )
63
+
64
+ # Launch the app
65
+ demo.launch()