Skip to content

The open-source AI voice studio. Clone, dictate, create.

fix(stories): collapse whitespace in chapter titles; mp3 at 160k to keep 24 kHz

jamiepine450417de8a46
diff --git a/backend/routes/history.py b/backend/routes/history.py
index c1e4c200..54931cfe 100644
--- a/backend/routes/history.py
+++ b/backend/routes/history.py
@@ -179,7 +179,7 @@ async def export_generation_audio(
"""Export only the audio file from a generation.
``format=wav`` (default) returns the stored file unchanged; ``format=mp3``
- transcodes it with ffmpeg (192 kbps) and returns 503 when ffmpeg is missing.
+ transcodes it with ffmpeg (160 kbps) and returns 503 when ffmpeg is missing.
"""
fmt = (format_ or "wav").lower()
if fmt not in _EXPORT_MIME:
diff --git a/backend/services/stories.py b/backend/services/stories.py
index cb1eb6f4..da69c912 100644
--- a/backend/services/stories.py
+++ b/backend/services/stories.py
@@ -859,7 +859,7 @@ def _chapter_title_from_text(text: Optional[str], max_len: int = 80) -> str:
Takes the first sentence (or the leading slice if the sentence is long).
"""
- cleaned = (text or "").strip()
+ cleaned = re.sub(r"\s+", " ", text or "").strip()
if not cleaned:
return "Chapter"
first = _SENTENCE_BREAK.split(cleaned, maxsplit=1)[0].strip()
diff --git a/backend/tests/test_story_export.py b/backend/tests/test_story_export.py
index 41be8b8c..c38ad2b3 100644
--- a/backend/tests/test_story_export.py
+++ b/backend/tests/test_story_export.py
@@ -28,6 +28,10 @@ class TestChapterTitleFromText:
def test_returns_first_sentence(self):
assert _chapter_title_from_text("Hello world. Second sentence.") == "Hello world."
+ def test_collapses_internal_whitespace(self):
+ assert _chapter_title_from_text("Chapter One\nIt was a dark night.") == "Chapter One It was a dark night."
+ assert _chapter_title_from_text("Hello\tthere.\n\nMore.") == "Hello there."
+
def test_truncates_long_sentence(self):
long = "a" * 200
title = _chapter_title_from_text(long, max_len=80)
diff --git a/backend/utils/ffmpeg.py b/backend/utils/ffmpeg.py
index b3032365..a4f4ee32 100644
--- a/backend/utils/ffmpeg.py
+++ b/backend/utils/ffmpeg.py
@@ -34,7 +34,9 @@ MISSING_MESSAGE = (
ENCODERS = {
# The 'ipod' muxer is ffmpeg's name for the .m4b container.
"m4b": ["-c:a", "aac", "-b:a", "128k", "-f", "ipod"],
- "mp3": ["-c:a", "libmp3lame", "-b:a", "192k", "-f", "mp3"],
+ # 160k is the MPEG-2 LSF ceiling, so LAME keeps the 24 kHz source rate
+ # instead of resampling to 44.1 kHz to satisfy a higher bitrate.
+ "mp3": ["-c:a", "libmp3lame", "-b:a", "160k", "-f", "mp3"],
}