Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,13 +19,24 @@ model, tokenizer = load_tts_model()
|
|
| 19 |
user_text = st.text_input("Enter your text here:")
|
| 20 |
|
| 21 |
# Generate Audio on Button Click
|
| 22 |
-
if st.button("Generate Speech"):
|
| 23 |
-
if not user_text:
|
| 24 |
-
st.warning("Please enter some text.")
|
| 25 |
-
else:
|
| 26 |
-
inputs = tokenizer(user_text, return_tensors="pt")
|
| 27 |
-
with torch.no_grad():
|
| 28 |
output = model(**inputs).waveform
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
user_text = st.text_input("Enter your text here:")
|
| 20 |
|
| 21 |
# Generate Audio on Button Click
|
| 22 |
+
if st.button("Generate Speech"):
|
| 23 |
+
if not user_text:
|
| 24 |
+
st.warning("Please enter some text.")
|
| 25 |
+
else:
|
| 26 |
+
inputs = tokenizer(user_text, return_tensors="pt")
|
| 27 |
+
with torch.no_grad():
|
| 28 |
output = model(**inputs).waveform
|
| 29 |
|
| 30 |
+
# Specify sample rate (assuming it's the correct rate for the model)
|
| 31 |
+
sample_rate = 16000 # Or replace with the correct sample rate for 'facebook/mms-tts-eng'
|
| 32 |
+
|
| 33 |
+
# Optionally save to a temporary file (if needed)
|
| 34 |
+
sf.write("temp_audio.wav", output[0].numpy(), sample_rate)
|
| 35 |
+
|
| 36 |
+
# Choose one of the following playback methods:
|
| 37 |
+
|
| 38 |
+
# Method 1: Play from temporary file
|
| 39 |
+
st.audio("temp_audio.wav")
|
| 40 |
+
|
| 41 |
+
# Method 2: Play directly with sample rate
|
| 42 |
+
st.audio(output[0].numpy(), sample_rate=sample_rate)
|