Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from datasets import load_dataset
|
|
11 |
from huggingface_hub import hf_hub_download
|
12 |
import uuid
|
13 |
import wave
|
|
|
14 |
|
15 |
|
16 |
from piper import PiperVoice
|
@@ -138,6 +139,8 @@ def text_to_speech(text, audio_file=None):
|
|
138 |
# Split text while preserving "..." (ellipsis)
|
139 |
segments = re.split(r'(\.\.\.|[\n.])', normalized_text)
|
140 |
|
|
|
|
|
141 |
print("segments: ", segments)
|
142 |
|
143 |
# Merge back the ellipsis with previous segment
|
@@ -151,6 +154,8 @@ def text_to_speech(text, audio_file=None):
|
|
151 |
if temp_segment:
|
152 |
combined_segments.append(temp_segment.strip())
|
153 |
temp_segment = ""
|
|
|
|
|
154 |
else:
|
155 |
if temp_segment:
|
156 |
combined_segments.append(temp_segment.strip())
|
@@ -167,6 +172,9 @@ def text_to_speech(text, audio_file=None):
|
|
167 |
combined_audio = np.array([], dtype=np.int16)
|
168 |
|
169 |
for segment in combined_segments:
|
|
|
|
|
|
|
170 |
with io.BytesIO() as buffer:
|
171 |
voice.synthesize(segment, buffer, **synthesize_args)
|
172 |
buffer.seek(0)
|
|
|
11 |
from huggingface_hub import hf_hub_download
|
12 |
import uuid
|
13 |
import wave
|
14 |
+
import io
|
15 |
|
16 |
|
17 |
from piper import PiperVoice
|
|
|
139 |
# Split text while preserving "..." (ellipsis)
|
140 |
segments = re.split(r'(\.\.\.|[\n.])', normalized_text)
|
141 |
|
142 |
+
segments = [x.strip() for x in segments]
|
143 |
+
|
144 |
print("segments: ", segments)
|
145 |
|
146 |
# Merge back the ellipsis with previous segment
|
|
|
154 |
if temp_segment:
|
155 |
combined_segments.append(temp_segment.strip())
|
156 |
temp_segment = ""
|
157 |
+
elif segment.strip() == "":
|
158 |
+
temp_segment = ""
|
159 |
else:
|
160 |
if temp_segment:
|
161 |
combined_segments.append(temp_segment.strip())
|
|
|
172 |
combined_audio = np.array([], dtype=np.int16)
|
173 |
|
174 |
for segment in combined_segments:
|
175 |
+
if segment.strip() == "":
|
176 |
+
continue
|
177 |
+
|
178 |
with io.BytesIO() as buffer:
|
179 |
voice.synthesize(segment, buffer, **synthesize_args)
|
180 |
buffer.seek(0)
|