Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForTextToSpeech, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model = AutoModelForTextToSpeech.from_pretrained("parler-tts/parler_tts")
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler_tts")
|
8 |
+
|
9 |
+
# Define the TTS function
|
10 |
+
def text_to_speech(text):
|
11 |
+
inputs = tokenizer(text, return_tensors="pt")
|
12 |
+
speech = model.generate(**inputs)
|
13 |
+
|
14 |
+
# Convert to an audio format, e.g., 16kHz waveform
|
15 |
+
audio = speech[0].cpu().detach().numpy()
|
16 |
+
return 16000, audio # Sample rate, waveform
|
17 |
+
|
18 |
+
# Gradio interface
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=text_to_speech,
|
21 |
+
inputs="text",
|
22 |
+
outputs="audio",
|
23 |
+
title="Text to Speech",
|
24 |
+
description="Convert text to speech using the parler-tts/parler_tts model"
|
25 |
+
)
|
26 |
+
|
27 |
+
interface.launch()
|