Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
|
| 3 |
import soundfile as sf
|
| 4 |
|
| 5 |
-
# Tải
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
# Nhập văn bản
|
| 10 |
-
text = "
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
inputs =
|
| 14 |
|
| 15 |
-
# Sinh
|
| 16 |
with torch.no_grad():
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
sf.write("
|
|
|
|
| 1 |
+
from transformers import VitsModel, VitsTokenizer
|
| 2 |
import torch
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
|
| 5 |
+
# Tải tokenizer và model VITS
|
| 6 |
+
model_id = "facebook/mms-tts-mhr"
|
| 7 |
+
tokenizer = VitsTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = VitsModel.from_pretrained(model_id)
|
| 9 |
|
| 10 |
+
# Nhập văn bản muốn đọc
|
| 11 |
+
text = "Привет" # hoặc tiếng Meadow Mari nếu em có
|
| 12 |
|
| 13 |
+
# Token hóa
|
| 14 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 15 |
|
| 16 |
+
# Sinh audio
|
| 17 |
with torch.no_grad():
|
| 18 |
+
output = model(**inputs).waveform
|
| 19 |
|
| 20 |
+
# Lưu file
|
| 21 |
+
sf.write("output.wav", output.squeeze().numpy(), samplerate=22050)
|