Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ import os
|
|
7 |
import re # Import the regular expression module
|
8 |
from pathlib import Path
|
9 |
|
|
|
|
|
10 |
|
11 |
# Get all available voices
|
12 |
async def get_voices():
|
@@ -30,23 +32,18 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
30 |
audio_segments = []
|
31 |
silence_durations = []
|
32 |
parts = re.split(r'(SS\d+\.?\d*)', text)
|
33 |
-
|
34 |
for part in parts:
|
35 |
if re.match(r'SS\d+\.?\d*', part):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
else:
|
47 |
-
print(f"Warning: Silence.mp3 not found at {silence_path}")
|
48 |
-
except ValueError:
|
49 |
-
print(f"Warning: Invalid silence duration format: {part}")
|
50 |
elif part.strip():
|
51 |
processed_text = part
|
52 |
current_voice = voice
|
|
|
7 |
import re # Import the regular expression module
|
8 |
from pathlib import Path
|
9 |
|
10 |
+
# At the top of your file:
|
11 |
+
SILENCE_PATH = Path(__file__).parent.absolute() / "Silence.mp3"
|
12 |
|
13 |
# Get all available voices
|
14 |
async def get_voices():
|
|
|
32 |
audio_segments = []
|
33 |
silence_durations = []
|
34 |
parts = re.split(r'(SS\d+\.?\d*)', text)
|
|
|
35 |
for part in parts:
|
36 |
if re.match(r'SS\d+\.?\d*', part):
|
37 |
+
if SILENCE_PATH.exists():
|
38 |
+
audio_segments.append(str(SILENCE_PATH))
|
39 |
+
print(f"Silence added at {SILENCE_PATH}")
|
40 |
+
else:
|
41 |
+
# Create silent segment programmatically
|
42 |
+
silent_audio = AudioSegment.silent(duration=1000) # 1 second
|
43 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
44 |
+
silent_audio.export(tmp_file.name, format="mp3")
|
45 |
+
audio_segments.append(tmp_file.name)
|
46 |
+
print(f"Created silent segment at {tmp_file.name}")
|
|
|
|
|
|
|
|
|
47 |
elif part.strip():
|
48 |
processed_text = part
|
49 |
current_voice = voice
|