Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import VitsForTextToSpeech, AutoTokenizer
|
| 3 |
+
import soundfile as sf
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
model_id = "facebook/mms-tts-bod"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = VitsForTextToSpeech.from_pretrained(model_id)
|
| 9 |
+
|
| 10 |
+
def tts(text):
|
| 11 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 12 |
+
speech = model.generate_speech(inputs["input_ids"][0], speaker_id=0)
|
| 13 |
+
sf.write("output.wav", speech.cpu().numpy(), samplerate=16000)
|
| 14 |
+
return "output.wav"
|
| 15 |
+
|
| 16 |
+
demo = gr.Interface(fn=tts, inputs="text", outputs="audio")
|
| 17 |
+
demo.launch()
|