Update app.py
Browse files
app.py
CHANGED
|
@@ -21,21 +21,35 @@ vocoder = vocoder.to(device)
|
|
| 21 |
speaker_embedding = torch.zeros(1, 512).to(device)
|
| 22 |
|
| 23 |
def tts_generate(text):
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Gradio interface
|
| 41 |
demo = gr.Interface(
|
|
@@ -47,4 +61,5 @@ demo = gr.Interface(
|
|
| 47 |
)
|
| 48 |
|
| 49 |
if __name__ == "__main__":
|
| 50 |
-
demo.
|
|
|
|
|
|
| 21 |
speaker_embedding = torch.zeros(1, 512).to(device)
|
| 22 |
|
| 23 |
def tts_generate(text):
|
| 24 |
+
print(f"π Input text: {text}")
|
| 25 |
+
try:
|
| 26 |
+
# Preprocess input
|
| 27 |
+
print("π Processing input...")
|
| 28 |
+
inputs = processor(text=text, return_tensors="pt").to(device)
|
| 29 |
+
print("β
Text processed.")
|
| 30 |
|
| 31 |
+
# Generate mel spectrogram
|
| 32 |
+
print("π€ Generating speech...")
|
| 33 |
+
with torch.no_grad():
|
| 34 |
+
mel = model.generate_speech(inputs["input_ids"], speaker_embedding)
|
| 35 |
+
print("β
Mel spectrogram generated.")
|
| 36 |
|
| 37 |
+
# Convert mel spectrogram to waveform
|
| 38 |
+
print("ποΈ Vocoding waveform...")
|
| 39 |
+
waveform = vocoder(mel)
|
| 40 |
+
waveform = waveform.cpu()
|
| 41 |
+
print("β
Waveform generated.")
|
| 42 |
|
| 43 |
+
# Save waveform
|
| 44 |
+
output_path = "output.wav"
|
| 45 |
+
torchaudio.save(output_path, waveform, sample_rate=16000)
|
| 46 |
+
print(f"πΎ Audio saved to {output_path}")
|
| 47 |
|
| 48 |
+
return output_path
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print("β Error during TTS generation:", e)
|
| 52 |
+
return "Error during speech synthesis."
|
| 53 |
|
| 54 |
# Gradio interface
|
| 55 |
demo = gr.Interface(
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
+
print("π Launching Gradio demo...")
|
| 65 |
+
demo.launch()
|