Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,14 +39,14 @@ st.sidebar.markdown("""
|
|
39 |
- π¨π³ **Chinese** (Mandarin)
|
40 |
- π―π΅ **Japanese**
|
41 |
3. **Select Voice**:
|
42 |
-
- Choose the voice you want for the speech. There are multiple voice styles based on tone and gender (e.g.,
|
43 |
|
44 |
4. **Adjust Speech Speed**:
|
45 |
-
- Use the slider to adjust how fast the speech will be generated. The speed can be set from
|
46 |
5. **Generate Speech**:
|
47 |
- Once you've selected the text, language, voice, and speed, click the **"Generate Audio"** button. The app will process the text and generate the speech.
|
48 |
6. **Download Audio**:
|
49 |
-
- After the audio is generated, you can play it directly within the app or download it as a
|
50 |
### Additional Features:
|
51 |
- **Text Translation**:
|
52 |
- The app can automatically translate the text to English before generating audio. After the translation, you will hear the audio in English with your chosen voice.
|
@@ -121,23 +121,6 @@ def generate_audio(text, lang_code, voice, speed):
|
|
121 |
|
122 |
# Generate and display the audio file
|
123 |
if st.button('Generate Audio'):
|
124 |
-
|
125 |
-
# Generate audio for the original text
|
126 |
-
st.write("Generating speech for the original text...")
|
127 |
-
audio_buffer = generate_audio(input_text, lang_code, voice, speed)
|
128 |
-
|
129 |
-
# Display Audio player for the original language
|
130 |
-
st.audio(audio_buffer, format='audio/wav')
|
131 |
-
|
132 |
-
# Optional: Save the generated audio file for download (Original Text)
|
133 |
-
st.download_button(
|
134 |
-
label="Download Audio (Original Text)",
|
135 |
-
data=audio_buffer,
|
136 |
-
file_name="generated_speech_original.wav",
|
137 |
-
mime="audio/wav"
|
138 |
-
)
|
139 |
-
|
140 |
-
# Check if OpenAI API Key is provided for translation and English audio generation
|
141 |
if openai_api_key:
|
142 |
# Translate the input text to English using OpenAI
|
143 |
translated_text = translate_to_english(openai_api_key, input_text, lang_code)
|
@@ -156,3 +139,19 @@ if st.button('Generate Audio'):
|
|
156 |
file_name="generated_speech_translated.wav",
|
157 |
mime="audio/wav"
|
158 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
- π¨π³ **Chinese** (Mandarin)
|
40 |
- π―π΅ **Japanese**
|
41 |
3. **Select Voice**:
|
42 |
+
- Choose the voice you want for the speech. There are multiple voice styles based on tone and gender (e.g., af_heart, af_joy, etc.).
|
43 |
|
44 |
4. **Adjust Speech Speed**:
|
45 |
+
- Use the slider to adjust how fast the speech will be generated. The speed can be set from 0.5x to 2.0x, with 1.0x being the default normal speed.
|
46 |
5. **Generate Speech**:
|
47 |
- Once you've selected the text, language, voice, and speed, click the **"Generate Audio"** button. The app will process the text and generate the speech.
|
48 |
6. **Download Audio**:
|
49 |
+
- After the audio is generated, you can play it directly within the app or download it as a .wav file by clicking the **"Download Audio"** button.
|
50 |
### Additional Features:
|
51 |
- **Text Translation**:
|
52 |
- The app can automatically translate the text to English before generating audio. After the translation, you will hear the audio in English with your chosen voice.
|
|
|
121 |
|
122 |
# Generate and display the audio file
|
123 |
if st.button('Generate Audio'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if openai_api_key:
|
125 |
# Translate the input text to English using OpenAI
|
126 |
translated_text = translate_to_english(openai_api_key, input_text, lang_code)
|
|
|
139 |
file_name="generated_speech_translated.wav",
|
140 |
mime="audio/wav"
|
141 |
)
|
142 |
+
|
143 |
+
else:
|
144 |
+
# Generate audio for the original text
|
145 |
+
st.write("Generating speech for the original text...")
|
146 |
+
audio_buffer = generate_audio(input_text, lang_code, voice, speed)
|
147 |
+
|
148 |
+
# Display Audio player for the original language
|
149 |
+
st.audio(audio_buffer, format='audio/wav')
|
150 |
+
|
151 |
+
# Optional: Save the generated audio file for download (Original Text)
|
152 |
+
st.download_button(
|
153 |
+
label="Download Audio (Original Text)",
|
154 |
+
data=audio_buffer,
|
155 |
+
file_name="generated_speech_original.wav",
|
156 |
+
mime="audio/wav"
|
157 |
+
)
|