Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained("facebook/mms-tts-chv", torch_dtype=torch.float32).to(device)
|
| 9 |
+
processor = AutoProcessor.from_pretrained("facebook/mms-tts-chv")
|
| 10 |
+
|
| 11 |
+
def tts_fn(text):
|
| 12 |
+
inputs = processor(text=text, return_tensors="pt").to(device)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
speech = model.generate(**inputs)
|
| 15 |
+
audio = processor.batch_decode(speech, return_tensors="np")[0]
|
| 16 |
+
sf.write("output.wav", audio, 16000)
|
| 17 |
+
return "output.wav"
|
| 18 |
+
|
| 19 |
+
demo = gr.Interface(fn=tts_fn, inputs="text", outputs="audio", title="TTS Chuvash - Facebook MMS")
|
| 20 |
+
|
| 21 |
+
demo.launch()
|