AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(audio): merge MiniMax word timings that share one original-text span
hugohe396742ffb1aeb
diff --git a/skills/ppt-master/scripts/docs/narration.md b/skills/ppt-master/scripts/docs/narration.mdindex a7ddd6e9..54c00a20 100644--- a/skills/ppt-master/scripts/docs/narration.md+++ b/skills/ppt-master/scripts/docs/narration.md@@ -24,7 +24,7 @@ python3 skills/ppt-master/scripts/notes_to_audio.py <project_path> --provider co- **Outputs**: one `audio/<stem>.<ext>` per note plus `audio/<stem>.srt` on provider-timed paths (edge, ElevenLabs, MiniMax, timestamp-capable CosyVoice); Qwen and explicit `--cosyvoice-audio-only` write audio only. The flat `audio/` directory is the single active set — no provider subdirectories unless the user asks to keep variants. Stale `audio/manifest.json` and `audio/total.srt` are removed before generation; a successful audio-only run also removes same-stem stale SRT; the manifest (provider/model, formats, voice settings, SHA-256 voice fingerprint — no per-slide inventory, hashes, or keys) is published atomically only after the complete roster succeeds.- **Formats**: PowerPoint-reliable audio is `m4a` (AAC), `mp3`, or `wav`; edge defaults to `mp3`; provider `pcm` / `opus` / `flac` output must be transcoded before embedding.- **Edge SRT**: MP3 and page SRT come from the same `edge-tts` stream using `WordBoundary` timing. Sentence-ending punctuation always closes a cue; text over the 20-visible-character default (`--subtitle-max-chars`) splits at commas, semicolons, or colons, then at the nearest word boundary. Adjacent overlap up to 100 ms moves the later cue start to the previous end; larger overlap fails. Each SRT uses a page-local timeline starting at `00:00:00,000` including leading silence. Default concurrency is three slide pairs (`--concurrency 1` for serial troubleshooting); cloud providers stay serial.-- **Provider timing**: MiniMax reads word timing from its synchronous subtitle file; ElevenLabs uses `/with-timestamps` with original-text character alignment; CosyVoice enables HTTP streaming plus `word_timestamp_enabled` and uses the final audio URL and word timing — unsupported model/voice pairs fail without replacing the prior pair unless `--cosyvoice-audio-only` was explicit (model and voice families must match; cloned voices need a supported v3.5/v3/v2 model or a timestamp-supported system voice); Qwen exposes no timing and never gets estimated SRT. Provider-timed paths share punctuation-first, `--subtitle-max-chars`-bounded regrouping, exact-text validation, and rollback-safe pair publication.+- **Provider timing**: MiniMax reads word timing from its synchronous subtitle file (a normalized number such as `42` comes back as one row per spoken syllable sharing one original-text span; the adapter merges rows by that span, never by text alone); ElevenLabs uses `/with-timestamps` with original-text character alignment; CosyVoice enables HTTP streaming plus `word_timestamp_enabled` and uses the final audio URL and word timing — unsupported model/voice pairs fail without replacing the prior pair unless `--cosyvoice-audio-only` was explicit (model and voice families must match; cloned voices need a supported v3.5/v3/v2 model or a timestamp-supported system voice); Qwen exposes no timing and never gets estimated SRT. Provider-timed paths share punctuation-first, `--subtitle-max-chars`-bounded regrouping, exact-text validation, and rollback-safe pair publication.## `narration_sync.py`diff --git a/skills/ppt-master/scripts/tests/test_minimax_subtitles.py b/skills/ppt-master/scripts/tests/test_minimax_subtitles.pynew file mode 100644index 00000000..49c65774--- /dev/null+++ b/skills/ppt-master/scripts/tests/test_minimax_subtitles.py@@ -0,0 +1,96 @@+#!/usr/bin/env python3+"""Exercise MiniMax original-text subtitle spans through audio generation.++Usage:+ python3 -m unittest tests.test_minimax_subtitles++Dependencies:+ None (only uses standard library).+"""++import json+import tempfile+import unittest+from pathlib import Path+from unittest.mock import patch++from tts_backends import backend_minimax+++class MiniMaxSubtitleTests(unittest.TestCase):+ def generate(self, text: str, words: list[dict], directory: Path) -> None:+ response = {+ "base_resp": {"status_code": 0},+ "data": {+ "audio": b"mock-audio".hex(),+ "subtitle_file": "https://example.invalid/subtitles.json",+ },+ }+ subtitle = json.dumps([{"timestamped_words": words}]).encode("utf-8")+ with (+ patch.object(backend_minimax, "post_json", return_value=response),+ patch.object(backend_minimax, "get_bytes", return_value=subtitle),+ ):+ backend_minimax.generate(+ text, directory / "page.mp3",+ api_key="test-key", voice_id="test-voice", model="speech-2.8-hd",+ audio_format="mp3", sample_rate=32000, bitrate=128000, channel=1,+ speed=1.0, volume=1.0, pitch=0, language_boost="auto", base_url=None,+ subtitle_path=directory / "page.srt",+ )++ def test_spoken_number_parts_keep_one_original_token_and_full_duration(self):+ words = [+ {"word": "第", "word_begin": 0, "word_end": 1, "time_begin": 0, "time_end": 100},+ {"word": "42", "word_begin": 1, "word_end": 3, "time_begin": 100, "time_end": 200},+ {"word": "42", "word_begin": 1, "word_end": 3, "time_begin": 200, "time_end": 300},+ {"word": "42", "word_begin": 1, "word_end": 3, "time_begin": 300, "time_end": 450},+ ]+ with tempfile.TemporaryDirectory() as temporary:+ directory = Path(temporary)+ self.generate("第42。", words, directory)+ self.assertEqual((directory / "page.mp3").read_bytes(), b"mock-audio")+ self.assertEqual(+ (directory / "page.srt").read_text(encoding="utf-8"),+ "1\n00:00:00,000 --> 00:00:00,450\n第42。\n",+ )++ def test_repeated_words_at_distinct_positions_are_preserved(self):+ words = [+ {"word": "42", "word_begin": 0, "word_end": 2, "time_begin": 0, "time_end": 100},+ {"word": "42", "word_begin": 3, "word_end": 5, "time_begin": 100, "time_end": 200},+ ]+ with tempfile.TemporaryDirectory() as temporary:+ directory = Path(temporary)+ self.generate("42,42。", words, directory)+ self.assertIn("42,42。", (directory / "page.srt").read_text(encoding="utf-8"))++ def test_missing_or_invalid_spans_do_not_hide_text_mismatches(self):+ for span in (None, (-1, 2), (0, 0), ("0", "2"), (False, 2)):+ with self.subTest(span=span), tempfile.TemporaryDirectory() as temporary:+ directory = Path(temporary)+ (directory / "page.mp3").write_bytes(b"previous-audio")+ (directory / "page.srt").write_text("previous-subtitles", encoding="utf-8")+ words = [+ {"word": "42", "time_begin": 0, "time_end": 100},+ {"word": "42", "time_begin": 100, "time_end": 200},+ ]+ if span is not None:+ for word in words:+ word.update(word_begin=span[0], word_end=span[1])+ with self.assertRaisesRegex(RuntimeError, "could not be aligned"):+ self.generate("42。", words, directory)+ self.assertEqual((directory / "page.mp3").read_bytes(), b"previous-audio")+ self.assertEqual(+ (directory / "page.srt").read_text(encoding="utf-8"), "previous-subtitles"+ )++ def test_merged_number_still_rejects_backwards_word_times(self):+ words = [+ {"word": "42", "word_begin": 0, "word_end": 2, "time_begin": 0, "time_end": 100},+ {"word": "42", "word_begin": 0, "word_end": 2, "time_begin": 100, "time_end": 200},+ {"word": "42", "word_begin": 0, "word_end": 2, "time_begin": 50, "time_end": 150},+ ]+ with tempfile.TemporaryDirectory() as temporary:+ with self.assertRaisesRegex(RuntimeError, "not in chronological order"):+ self.generate("42。", words, Path(temporary))diff --git a/skills/ppt-master/scripts/tts_backends/backend_minimax.py b/skills/ppt-master/scripts/tts_backends/backend_minimax.pyindex 46b7dd65..a8f75cba 100644--- a/skills/ppt-master/scripts/tts_backends/backend_minimax.py+++ b/skills/ppt-master/scripts/tts_backends/backend_minimax.py@@ -63,12 +63,14 @@ def _word_boundaries(raw: object) -> list[dict]:raise RuntimeError("MiniMax subtitle response contains no sentence blocks")boundaries: list[dict] = []+ previous_start = -1for sentence in raw:if not isinstance(sentence, dict):raise RuntimeError("MiniMax subtitle sentence block is not an object")words = sentence.get("timestamped_words")if not isinstance(words, list) or not words:raise RuntimeError("MiniMax subtitle sentence block contains no word timings")+ previous_span = Nonefor item in words:if not isinstance(item, dict):raise RuntimeError("MiniMax subtitle word timing is not an object")@@ -81,8 +83,29 @@ def _word_boundaries(raw: object) -> list[dict]:raise RuntimeError("MiniMax subtitle response contains an invalid word interval")- if boundaries and start < boundaries[-1]["offset"]:+ if start < previous_start:raise RuntimeError("MiniMax subtitle words are not in chronological order")+ previous_start = start+ word_begin, word_end = item.get("word_begin"), item.get("word_end")+ span = (+ (word_begin, word_end)+ if type(word_begin) is int+ and type(word_end) is int+ and 0 <= word_begin < word_end+ else None+ )+ # Normalized numbers can emit one row per spoken syllable, all+ # pointing at the same original-text span (e.g. "42" three times).+ # The span is the merge key; the text match is a guard — a same-span+ # row with a different word falls through and the shared alignment+ # check reports it instead of merging it silently.+ if span is not None and span == previous_span and boundaries[-1]["text"] == word:+ previous = boundaries[-1]+ previous["duration"] = max(+ previous["duration"], end - previous["offset"]+ )+ continue+ previous_span = spanboundaries.append({"text": word,