Spaces:
Sleeping
Sleeping
github-actions[bot]
commited on
Commit
·
5af6319
1
Parent(s):
5b95d77
Sync with https://github.com/mozilla-ai/document-to-podcast
Browse files
app.py
CHANGED
@@ -2,7 +2,9 @@
|
|
2 |
|
3 |
import re
|
4 |
from pathlib import Path
|
|
|
5 |
|
|
|
6 |
import soundfile as sf
|
7 |
import streamlit as st
|
8 |
|
@@ -29,6 +31,16 @@ def load_text_to_speech_model():
|
|
29 |
return load_tts_model("OuteAI/OuteTTS-0.2-500M-GGUF/OuteTTS-0.2-500M-FP16.gguf")
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
script = "script"
|
33 |
audio = "audio"
|
34 |
gen_button = "generate podcast button"
|
@@ -171,21 +183,23 @@ if "clean_text" in st.session_state:
|
|
171 |
|
172 |
st.session_state.audio.append(speech)
|
173 |
text = ""
|
|
|
174 |
|
175 |
if st.session_state[gen_button]:
|
176 |
-
|
177 |
-
st.session_state.audio
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
st.markdown("Podcast saved to disk!")
|
186 |
|
187 |
-
if st.
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
191 |
st.markdown("Script saved to disk!")
|
|
|
2 |
|
3 |
import re
|
4 |
from pathlib import Path
|
5 |
+
import io
|
6 |
|
7 |
+
import numpy as np
|
8 |
import soundfile as sf
|
9 |
import streamlit as st
|
10 |
|
|
|
31 |
return load_tts_model("OuteAI/OuteTTS-0.2-500M-GGUF/OuteTTS-0.2-500M-FP16.gguf")
|
32 |
|
33 |
|
34 |
+
def numpy_to_wav(audio_array: np.ndarray, sample_rate: int) -> io.BytesIO:
|
35 |
+
"""
|
36 |
+
Convert a numpy array to audio bytes in .wav format, ready to save into a file.
|
37 |
+
"""
|
38 |
+
wav_io = io.BytesIO()
|
39 |
+
sf.write(wav_io, audio_array, sample_rate, format="WAV")
|
40 |
+
wav_io.seek(0)
|
41 |
+
return wav_io
|
42 |
+
|
43 |
+
|
44 |
script = "script"
|
45 |
audio = "audio"
|
46 |
gen_button = "generate podcast button"
|
|
|
183 |
|
184 |
st.session_state.audio.append(speech)
|
185 |
text = ""
|
186 |
+
st.session_state.script += "}"
|
187 |
|
188 |
if st.session_state[gen_button]:
|
189 |
+
audio_np = stack_audio_segments(
|
190 |
+
st.session_state.audio, speech_model.sample_rate
|
191 |
+
)
|
192 |
+
audio_wav = numpy_to_wav(audio_np, speech_model.sample_rate)
|
193 |
+
if st.download_button(
|
194 |
+
label="Save Podcast to audio file",
|
195 |
+
data=audio_wav,
|
196 |
+
file_name="podcast.wav",
|
197 |
+
):
|
198 |
st.markdown("Podcast saved to disk!")
|
199 |
|
200 |
+
if st.download_button(
|
201 |
+
label="Save Podcast script to text file",
|
202 |
+
data=st.session_state.script,
|
203 |
+
file_name="script.txt",
|
204 |
+
):
|
205 |
st.markdown("Script saved to disk!")
|