Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,80 +1,74 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import
|
3 |
-
|
4 |
-
import
|
5 |
-
import
|
6 |
-
import
|
7 |
-
import
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
st.
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
st.
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
st.markdown("---")
|
77 |
-
st.caption("πΉ **Offline Mode** uses your system's built-in voices and works without the internet.")
|
78 |
-
st.caption("πΉ **Online Mode** uses Google TTS for a more natural voice but requires an internet connection.")
|
79 |
-
st.divider()
|
80 |
-
st.caption("π» So called Arman.")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import edge_tts
|
3 |
+
import asyncio
|
4 |
+
import librosa
|
5 |
+
import soundfile as sf
|
6 |
+
import time
|
7 |
+
import numpy as np
|
8 |
+
from io import BytesIO
|
9 |
+
|
10 |
+
# Function to Convert Text to Speech with More Voice Options
|
11 |
+
async def text_to_speech(text, voice="en-US-GuyNeural"):
|
12 |
+
filename = f"audio_{int(time.time())}.mp3"
|
13 |
+
|
14 |
+
# Use Edge TTS to generate speech
|
15 |
+
communicate = edge_tts.Communicate(text, voice)
|
16 |
+
await communicate.save(filename)
|
17 |
+
|
18 |
+
return filename
|
19 |
+
|
20 |
+
# Function to Modify Voice Pitch
|
21 |
+
def change_voice(input_file, gender="male"):
|
22 |
+
y, sr = librosa.load(input_file, sr=44100)
|
23 |
+
pitch_factor = -3 if gender == "male" else 5 # Adjust pitch naturally
|
24 |
+
y_shifted = librosa.effects.pitch_shift(y, n_steps=pitch_factor, sr=sr)
|
25 |
+
|
26 |
+
output_file = f"modified_{int(time.time())}.wav"
|
27 |
+
sf.write(output_file, y_shifted, sr)
|
28 |
+
|
29 |
+
return output_file
|
30 |
+
|
31 |
+
# Streamlit UI
|
32 |
+
st.set_page_config(page_title="π€ Voice Generator App", layout="centered")
|
33 |
+
st.title("π€ AI-Powered Voice Generator")
|
34 |
+
st.markdown("**Convert your text into speech with natural, clear voices!** πΆ")
|
35 |
+
st.divider()
|
36 |
+
|
37 |
+
# User Input for Text
|
38 |
+
st.subheader("Enter Your Text")
|
39 |
+
text = st.text_area("π Type or paste your text below:")
|
40 |
+
|
41 |
+
# Select Voice Type
|
42 |
+
st.subheader("Select Voice Type")
|
43 |
+
voice_options = {
|
44 |
+
"Male (US)": "en-US-GuyNeural",
|
45 |
+
"Male (UK)": "en-GB-RyanNeural",
|
46 |
+
"Female (US)": "en-US-JennyNeural",
|
47 |
+
"Female (UK)": "en-GB-SoniaNeural"
|
48 |
+
}
|
49 |
+
selected_voice = st.selectbox("π Choose a Voice:", list(voice_options.keys()))
|
50 |
+
|
51 |
+
if st.button("ποΈ Generate Voice"):
|
52 |
+
if text:
|
53 |
+
st.info("β³ Processing your request... Please wait.")
|
54 |
+
|
55 |
+
# Generate Speech
|
56 |
+
audio_file = asyncio.run(text_to_speech(text, voice_options[selected_voice]))
|
57 |
+
|
58 |
+
st.success("β
Voice generated successfully!")
|
59 |
+
st.audio(audio_file, format='audio/mp3')
|
60 |
+
|
61 |
+
# Allow users to download the generated audio
|
62 |
+
with open(audio_file, "rb") as file:
|
63 |
+
audio_bytes = file.read()
|
64 |
+
|
65 |
+
st.download_button(label="β¬οΈ Download Audio", data=audio_bytes,
|
66 |
+
file_name=audio_file, mime="audio/mp3")
|
67 |
+
else:
|
68 |
+
st.warning("β οΈ Please enter text to generate voice.")
|
69 |
+
|
70 |
+
st.markdown("---")
|
71 |
+
st.caption("πΉ **Supports high-quality male & female voices with different accents.**")
|
72 |
+
st.caption("πΉ **Runs offline using Edge TTS for fast voice generation.**")
|
73 |
+
st.divider()
|
74 |
+
st.caption("π» So called Arman.")
|
|
|
|
|
|
|
|
|
|
|
|