Spaces:
Sleeping
Sleeping
Phạm Anh Tuấn
commited on
Commit
·
a7ad758
1
Parent(s):
812ef64
change to TTS
Browse files- app.py +24 -11
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,35 +1,48 @@
|
|
1 |
import streamlit as st
|
2 |
-
from gtts import gTTS
|
3 |
import io
|
|
|
|
|
4 |
|
5 |
# Function to generate audio from text
|
6 |
-
def text_to_audio(text):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
st.title("Voice Synthesis App")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Input form for the user to enter text
|
14 |
user_input = st.text_area("Enter the text:")
|
15 |
-
|
16 |
if st.button("Generate"):
|
17 |
if user_input:
|
18 |
-
audio = text_to_audio(user_input)
|
|
|
|
|
|
|
19 |
|
20 |
# Display the audio
|
21 |
-
st.audio("output.
|
22 |
|
23 |
# Create a download link for the audio file
|
24 |
st.markdown("### Download the audio")
|
25 |
-
with open("output.
|
26 |
audio_bytes = audio_file.read()
|
|
|
27 |
st.download_button(
|
28 |
label="Click to download",
|
29 |
data=audio_bytes,
|
30 |
key="download_audio",
|
31 |
-
file_name="output.
|
32 |
-
mime="audio/
|
33 |
)
|
34 |
|
35 |
st.write("Note: This app uses gTTS for text-to-speech conversion.")
|
|
|
1 |
import streamlit as st
|
2 |
+
# from gtts import gTTS
|
3 |
import io
|
4 |
+
import torch
|
5 |
+
from TTS.api import TTS
|
6 |
|
7 |
# Function to generate audio from text
|
8 |
+
# def text_to_audio(text):
|
9 |
+
# tts = gTTS(text)
|
10 |
+
# audio = tts.save("output.mp3")
|
11 |
+
# return audio
|
12 |
|
13 |
st.title("Voice Synthesis App")
|
14 |
+
# Get device
|
15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
+
|
17 |
+
# List available 🐸TTS models
|
18 |
+
print(TTS().list_models())
|
19 |
+
|
20 |
+
# Init TTS
|
21 |
+
tts = TTS("tts_models/en/ljspeech/overflow").to(device)
|
22 |
|
23 |
# Input form for the user to enter text
|
24 |
user_input = st.text_area("Enter the text:")
|
|
|
25 |
if st.button("Generate"):
|
26 |
if user_input:
|
27 |
+
# audio = text_to_audio(user_input)
|
28 |
+
|
29 |
+
# Text to speech to a file
|
30 |
+
tts.tts_to_file(text="Hello world!", file_path="output.wav")
|
31 |
|
32 |
# Display the audio
|
33 |
+
st.audio("output.wav", format="audio/wav")
|
34 |
|
35 |
# Create a download link for the audio file
|
36 |
st.markdown("### Download the audio")
|
37 |
+
with open("output.wav", "rb") as audio_file:
|
38 |
audio_bytes = audio_file.read()
|
39 |
+
|
40 |
st.download_button(
|
41 |
label="Click to download",
|
42 |
data=audio_bytes,
|
43 |
key="download_audio",
|
44 |
+
file_name="output.wav",
|
45 |
+
mime="audio/wav",
|
46 |
)
|
47 |
|
48 |
st.write("Note: This app uses gTTS for text-to-speech conversion.")
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
gTTS
|
|
|
|
1 |
+
gTTS
|
2 |
+
TTS
|