Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -485,14 +485,14 @@ def overlay_text_on_image(image, text):
|
|
485 |
return None
|
486 |
|
487 |
def generate_combined_audio_from_story(story_text, voice='af_heart', speed=1):
|
488 |
-
"
|
489 |
# Split story into paragraphs (reuse logic from generate_image_prompts)
|
490 |
paragraphs = []
|
491 |
current_paragraph = []
|
492 |
|
493 |
for line in story_text.split('\n'):
|
494 |
line = line.strip()
|
495 |
-
if not line:
|
496 |
if current_paragraph:
|
497 |
paragraphs.append(' '.join(current_paragraph))
|
498 |
current_paragraph = []
|
@@ -502,28 +502,32 @@ def generate_combined_audio_from_story(story_text, voice='af_heart', speed=1):
|
|
502 |
if current_paragraph:
|
503 |
paragraphs.append(' '.join(current_paragraph))
|
504 |
|
505 |
-
|
|
|
506 |
combined_audio = []
|
507 |
-
for paragraph in paragraphs:
|
508 |
if not paragraph.strip():
|
509 |
-
continue
|
510 |
|
|
|
511 |
generator = pipeline(
|
512 |
paragraph,
|
513 |
voice=voice,
|
514 |
speed=speed,
|
515 |
-
split_pattern=r'\n+'
|
516 |
)
|
517 |
-
|
518 |
-
|
|
|
|
|
519 |
|
520 |
-
|
521 |
combined_audio = np.array(combined_audio)
|
522 |
filename = "combined_story.wav"
|
523 |
-
sf.write(filename, combined_audio, 24000)
|
524 |
clear_memory()
|
525 |
return filename
|
526 |
-
|
527 |
# Helper functions
|
528 |
def clean_story_output(story):
|
529 |
"""Clean up the generated story text."""
|
|
|
485 |
return None
|
486 |
|
487 |
def generate_combined_audio_from_story(story_text, voice='af_heart', speed=1):
|
488 |
+
print("Starting audio generation...")
|
489 |
# Split story into paragraphs (reuse logic from generate_image_prompts)
|
490 |
paragraphs = []
|
491 |
current_paragraph = []
|
492 |
|
493 |
for line in story_text.split('\n'):
|
494 |
line = line.strip()
|
495 |
+
if not line:
|
496 |
if current_paragraph:
|
497 |
paragraphs.append(' '.join(current_paragraph))
|
498 |
current_paragraph = []
|
|
|
502 |
if current_paragraph:
|
503 |
paragraphs.append(' '.join(current_paragraph))
|
504 |
|
505 |
+
print(f"Found {len(paragraphs)} paragraphs")
|
506 |
+
|
507 |
combined_audio = []
|
508 |
+
for i, paragraph in enumerate(paragraphs):
|
509 |
if not paragraph.strip():
|
510 |
+
continue
|
511 |
|
512 |
+
print(f"Processing paragraph {i+1}: {paragraph[:100]}...")
|
513 |
generator = pipeline(
|
514 |
paragraph,
|
515 |
voice=voice,
|
516 |
speed=speed,
|
517 |
+
split_pattern=r'\n+'
|
518 |
)
|
519 |
+
print(f"Generator created for paragraph {i+1}")
|
520 |
+
for batch_idx, metadata, audio in generator:
|
521 |
+
print(f"Got audio batch {batch_idx}, length: {len(audio) if audio is not None else 0}")
|
522 |
+
combined_audio.extend(audio)
|
523 |
|
524 |
+
print("Converting to array...")
|
525 |
combined_audio = np.array(combined_audio)
|
526 |
filename = "combined_story.wav"
|
527 |
+
sf.write(filename, combined_audio, 24000)
|
528 |
clear_memory()
|
529 |
return filename
|
530 |
+
|
531 |
# Helper functions
|
532 |
def clean_story_output(story):
|
533 |
"""Clean up the generated story text."""
|