Update tts.py
Browse files
tts.py
CHANGED
@@ -1,18 +1,19 @@
|
|
1 |
import torch
|
2 |
-
from transformers import
|
3 |
import logging
|
4 |
import numpy as np
|
5 |
import soundfile as sf
|
|
|
6 |
|
7 |
# Set up logging
|
8 |
logging.basicConfig(level=logging.DEBUG)
|
9 |
|
10 |
-
MODEL_ID = "
|
11 |
|
12 |
# Try to load the model and processor
|
13 |
try:
|
14 |
-
processor =
|
15 |
-
model =
|
16 |
logging.info("Model and processor loaded successfully.")
|
17 |
except Exception as e:
|
18 |
logging.error(f"Error loading model or processor: {e}")
|
@@ -25,7 +26,6 @@ def synthesize_speech(text):
|
|
25 |
logging.error("Text input is empty.")
|
26 |
return None
|
27 |
|
28 |
-
# Include language code explicitly if needed
|
29 |
inputs = processor(text, return_tensors="pt")
|
30 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
31 |
model.to(device)
|
|
|
1 |
import torch
|
2 |
+
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
|
3 |
import logging
|
4 |
import numpy as np
|
5 |
import soundfile as sf
|
6 |
+
from huggingface_hub import hf_hub_download
|
7 |
|
8 |
# Set up logging
|
9 |
logging.basicConfig(level=logging.DEBUG)
|
10 |
|
11 |
+
MODEL_ID = "facebook/mms-tts-fao"
|
12 |
|
13 |
# Try to load the model and processor
|
14 |
try:
|
15 |
+
processor = Wav2Vec2Processor.from_pretrained(MODEL_ID)
|
16 |
+
model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
|
17 |
logging.info("Model and processor loaded successfully.")
|
18 |
except Exception as e:
|
19 |
logging.error(f"Error loading model or processor: {e}")
|
|
|
26 |
logging.error("Text input is empty.")
|
27 |
return None
|
28 |
|
|
|
29 |
inputs = processor(text, return_tensors="pt")
|
30 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
31 |
model.to(device)
|