Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,3 @@
|
|
1 |
-
import subprocess
|
2 |
-
import sys
|
3 |
-
|
4 |
-
# Install the PortAudio library
|
5 |
-
try:
|
6 |
-
subprocess.run(["apt-get", "install", "-y", "portaudio19-dev"], check=True)
|
7 |
-
except subprocess.CalledProcessError as e:
|
8 |
-
print(f"Error occurred while installing PortAudio: {e}")
|
9 |
-
sys.exit(1)
|
10 |
-
|
11 |
-
# Now import sounddevice
|
12 |
-
try:
|
13 |
-
import sounddevice as sd
|
14 |
-
except OSError as e:
|
15 |
-
print(f"Failed to import sounddevice: {e}")
|
16 |
-
sys.exit(1)
|
17 |
-
|
18 |
import gradio as gr
|
19 |
import requests
|
20 |
import os
|
@@ -806,14 +789,18 @@ def generate_audio_parler_tts(text):
|
|
806 |
for new_audio in streamer:
|
807 |
if new_audio.shape[0] == 0:
|
808 |
break
|
809 |
-
#
|
810 |
-
sd.play(new_audio, samplerate=sampling_rate)
|
811 |
-
sd.wait() # Wait until the audio is played before moving to the next chunk
|
812 |
yield sampling_rate, new_audio
|
813 |
|
814 |
audio_segments = []
|
815 |
for (sampling_rate, audio_chunk) in generate(text, description, chunk_size_in_s):
|
816 |
audio_segments.append(audio_chunk)
|
|
|
|
|
|
|
|
|
|
|
|
|
817 |
|
818 |
# Combine all the audio chunks into one audio file
|
819 |
combined_audio = np.concatenate(audio_segments)
|
@@ -821,7 +808,7 @@ def generate_audio_parler_tts(text):
|
|
821 |
|
822 |
write_wav(combined_audio_path, sampling_rate, combined_audio.astype(np.float32))
|
823 |
|
824 |
-
logging.debug(f"
|
825 |
return combined_audio_path
|
826 |
|
827 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
|
|
789 |
for new_audio in streamer:
|
790 |
if new_audio.shape[0] == 0:
|
791 |
break
|
792 |
+
# Save or process each audio chunk as it is generated
|
|
|
|
|
793 |
yield sampling_rate, new_audio
|
794 |
|
795 |
audio_segments = []
|
796 |
for (sampling_rate, audio_chunk) in generate(text, description, chunk_size_in_s):
|
797 |
audio_segments.append(audio_chunk)
|
798 |
+
# Here, you can save the chunk to a file or send it to a frontend
|
799 |
+
# For example, you could write the chunk to a file immediately:
|
800 |
+
temp_audio_path = os.path.join(tempfile.gettempdir(), f"parler_tts_audio_chunk_{len(audio_segments)}.wav")
|
801 |
+
write_wav(temp_audio_path, sampling_rate, audio_chunk.astype(np.float32))
|
802 |
+
logging.debug(f"Saved chunk to {temp_audio_path}")
|
803 |
+
# You could also send the chunk to a web client if this was a web application
|
804 |
|
805 |
# Combine all the audio chunks into one audio file
|
806 |
combined_audio = np.concatenate(audio_segments)
|
|
|
808 |
|
809 |
write_wav(combined_audio_path, sampling_rate, combined_audio.astype(np.float32))
|
810 |
|
811 |
+
logging.debug(f"Combined audio saved to {combined_audio_path}")
|
812 |
return combined_audio_path
|
813 |
|
814 |
|