Skip to content

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

feat(narration): generate Edge audio with bounded concurrency

hugohe31ab05ec27eef
diff --git a/docs/audio-narration.md b/docs/audio-narration.md
index 8d9dde58..cd31aecb 100644
--- a/docs/audio-narration.md
+++ b/docs/audio-narration.md
@@ -121,6 +121,9 @@ python3 skills/ppt-master/scripts/narration_sync.py subtitles <project_path> \
```
For edge, `--voice` is required. Use `--list-voices --locale <locale>` to see what's available.
+Edge generates up to three slide-level audio/SRT pairs concurrently by default.
+Use `--concurrency <N>` to tune it or `--concurrency 1` for serial
+troubleshooting. Cloud providers remain serial.
The edge command creates `audio/<stem>.mp3` and `notes/subtitles/<stem>.srt` from the same streaming request. Sentence-ending punctuation closes a cue. A cue over 20 visible characters first splits at commas, semicolons, or colons, then at the nearest word boundary only if it is still too long. Use `--subtitle-max-chars` to change the limit. Adjacent timing overlap up to 100 ms is tolerated by moving the later cue start to the previous cue end; larger overlap fails. Each SRT uses a page-local timebase with a zero origin and preserves edge's `WordBoundary` timing, including any leading silence before the first cue. The cloud-provider commands currently create audio only.
diff --git a/docs/zh/audio-narration.md b/docs/zh/audio-narration.md
index 1f66e6ca..0e9f2aaf 100644
--- a/docs/zh/audio-narration.md
+++ b/docs/zh/audio-narration.md
@@ -120,6 +120,8 @@ python3 skills/ppt-master/scripts/narration_sync.py subtitles <project_path> \
```
edge 模式下 `--voice` 是必填项,可用 `--list-voices --locale <locale>` 查看音色。
+Edge 默认同时生成最多 3 页音频/SRT。可用 `--concurrency <N>` 调整;
+排查连接问题时可设为 `--concurrency 1`。云端 provider 仍保持串行。
Edge 命令会从同一次流式请求中生成 `audio/<stem>.mp3` 与 `notes/subtitles/<stem>.srt`。句末标点必定结束一条字幕;单条超过默认 20 个可见字符时,优先在逗号、分号或冒号处拆分,仍然过长才在最近的词边界拆分。可用 `--subtitle-max-chars` 调整上限。相邻字幕最多允许 100 毫秒的计时重叠:后一句起点会移到前一句终点;超过该范围则报错。每页 SRT 使用从零计时的页内时间基准,并保留 Edge `WordBoundary` 的实际时间(包括首条字幕前的静音);云端 provider 命令目前只生成音频。
diff --git a/skills/ppt-master/scripts/notes_to_audio.py b/skills/ppt-master/scripts/notes_to_audio.py
index f0bc1aa5..0f57eaec 100644
--- a/skills/ppt-master/scripts/notes_to_audio.py
+++ b/skills/ppt-master/scripts/notes_to_audio.py
@@ -43,6 +43,8 @@ from tts_backends import (
configure_utf8_stdio()
+DEFAULT_EDGE_CONCURRENCY = 3
+
@dataclass(frozen=True)
class AudioBackend:
@@ -52,6 +54,13 @@ class AudioBackend:
voice_id: str = ""
+@dataclass(frozen=True)
+class AudioJob:
+ note_path: Path
+ text: str
+ output_path: Path
+
+
def _load_tts_env_file() -> None:
"""Load TTS-related keys from the first .env file, without overriding shell env."""
load_prefixed_env_file((
@@ -78,6 +87,59 @@ def spoken_text(markdown: str) -> str:
return "\n".join(lines).strip()
+def _prepare_audio_jobs(
+ note_files: list[Path],
+ output_dir: Path,
+ extension: str,
+) -> list[AudioJob]:
+ """Read non-empty per-slide notes into ordered audio jobs."""
+ jobs: list[AudioJob] = []
+ for note_path in note_files:
+ text = spoken_text(note_path.read_text(encoding="utf-8"))
+ if not text:
+ print(f"[skip] {note_path.name}: empty spoken text")
+ continue
+ jobs.append(AudioJob(
+ note_path=note_path,
+ text=text,
+ output_path=output_dir / f"{note_path.stem}{extension}",
+ ))
+ return jobs
+
+
+async def _generate_edge_jobs(
+ jobs: list[AudioJob],
+ subtitle_dir: Path,
+ *,
+ voice: str,
+ rate: str,
+ subtitle_max_chars: int,
+ concurrency: int,
+) -> list[BaseException | None]:
+ """Generate ordered Edge jobs with bounded slide-level concurrency."""
+ semaphore = asyncio.Semaphore(concurrency)
+
+ async def generate_job(job: AudioJob) -> None:
+ async with semaphore:
+ await backend_edge.generate(
+ job.text,
+ job.output_path,
+ voice=voice,
+ rate=rate,
+ subtitle_path=subtitle_dir / f"{job.note_path.stem}.srt",
+ subtitle_max_chars=subtitle_max_chars,
+ )
+
+ raw_results = await asyncio.gather(
+ *(generate_job(job) for job in jobs),
+ return_exceptions=True,
+ )
+ return [
+ result if isinstance(result, BaseException) else None
+ for result in raw_results
+ ]
+
+
def main() -> int:
_load_tts_env_file()
@@ -108,6 +170,12 @@ def main() -> int:
default="+0%",
help='edge-tts speaking rate, e.g. "+0%%", "-10%%", "+15%%" (default: +0%%). Ignored by cloud providers.',
)
+ parser.add_argument(
+ "--concurrency",
+ type=int,
+ default=DEFAULT_EDGE_CONCURRENCY,
+ help="maximum concurrent Edge slide requests (default: 3; ignored by cloud providers)",
+ )
parser.add_argument(
"--subtitle-max-chars",
type=int,
@@ -256,6 +324,10 @@ def main() -> int:
parser.error("--subtitle-max-chars must be at least 1")
raise AssertionError("unreachable")
+ if args.concurrency < 1:
+ parser.error("--concurrency must be at least 1")
+ raise AssertionError("unreachable")
+
if args.provider == "elevenlabs":
if not voice_id:
parser.error("--voice-id is required for --provider elevenlabs")
@@ -314,91 +386,109 @@ def main() -> int:
print(f"error: no per-slide notes found in {notes_dir}", file=sys.stderr)
return 2
+ jobs = _prepare_audio_jobs(note_files, output_dir, backend.extension)
generated = 0
- for note_path in note_files:
- text = spoken_text(note_path.read_text(encoding="utf-8"))
- if not text:
- print(f"[skip] {note_path.name}: empty spoken text")
- continue
- output_path = output_dir / f"{note_path.stem}{backend.extension}"
+ if backend.provider == "edge":
+ print(
+ f"[Edge] Generating {len(jobs)} audio/SRT pair(s) "
+ f"with concurrency={args.concurrency}"
+ )
try:
- if backend.provider == "elevenlabs":
- backend_elevenlabs.generate(
- text,
- output_path,
- api_key=backend.api_key,
- voice_id=backend.voice_id,
- model=args.elevenlabs_model,
- output_format=args.elevenlabs_output_format,
- stability=args.elevenlabs_stability,
- similarity_boost=args.elevenlabs_similarity_boost,
- style=args.elevenlabs_style,
- speaker_boost=args.elevenlabs_speaker_boost,
- )
- elif backend.provider == "minimax":
- backend_minimax.generate(
- text,
- output_path,
- api_key=backend.api_key,
- voice_id=backend.voice_id,
- model=args.minimax_model,
- audio_format=args.minimax_output_format,
- sample_rate=args.minimax_sample_rate,
- bitrate=args.minimax_bitrate,
- channel=args.minimax_channel,
- speed=args.minimax_speed,
- volume=args.minimax_volume,
- pitch=args.minimax_pitch,
- language_boost=args.minimax_language_boost,
- base_url=args.minimax_base_url,
- )
- elif backend.provider == "qwen":
- backend_qwen.generate(
- text,
- output_path,
- api_key=backend.api_key,
- voice_id=backend.voice_id,
- model=args.qwen_model,
- language_type=args.qwen_language_type,
- instructions=args.qwen_instructions,
- optimize_instructions=args.qwen_optimize_instructions,
- base_url=args.qwen_base_url,
- )
- elif backend.provider == "cosyvoice":
- backend_cosyvoice.generate(
- text,
- output_path,
- api_key=backend.api_key,
- voice_id=backend.voice_id,
- model=args.cosyvoice_model,
- audio_format=args.cosyvoice_output_format,
- sample_rate=args.cosyvoice_sample_rate,
- volume=args.cosyvoice_volume,
- rate=args.cosyvoice_rate,
- pitch=args.cosyvoice_pitch,
- instruction=args.cosyvoice_instruction,
- language_hint=args.cosyvoice_language_hint,
- base_url=args.cosyvoice_base_url,
+ results = asyncio.run(_generate_edge_jobs(
+ jobs,
+ subtitle_dir,
+ voice=args.voice,
+ rate=args.rate,
+ subtitle_max_chars=args.subtitle_max_chars,
+ concurrency=args.concurrency,
+ ))
+ except Exception as exc:
+ print(f"error: Edge audio generation failed: {exc}", file=sys.stderr)
+ return 1
+
+ failed = False
+ for job, result in zip(jobs, results):
+ subtitle_path = subtitle_dir / f"{job.note_path.stem}.srt"
+ if result is not None:
+ print(
+ f"error: failed to generate {job.output_path}: {result}",
+ file=sys.stderr,
)
- else:
- subtitle_path = subtitle_dir / f"{note_path.stem}.srt"
- asyncio.run(
- backend_edge.generate(
+ failed = True
+ continue
+ generated += 1
+ print(f"[OK] {job.output_path}")
+ print(f" {subtitle_path}")
+ if failed:
+ return 1
+ else:
+ for job in jobs:
+ output_path = job.output_path
+ text = job.text
+ try:
+ if backend.provider == "elevenlabs":
+ backend_elevenlabs.generate(
text,
output_path,
- voice=args.voice,
- rate=args.rate,
- subtitle_path=subtitle_path,
- subtitle_max_chars=args.subtitle_max_chars,
+ api_key=backend.api_key,
+ voice_id=backend.voice_id,
+ model=args.elevenlabs_model,
+ output_format=args.elevenlabs_output_format,
+ stability=args.elevenlabs_stability,
+ similarity_boost=args.elevenlabs_similarity_boost,
+ style=args.elevenlabs_style,
+ speaker_boost=args.elevenlabs_speaker_boost,
)
- )
- except Exception as exc:
- print(f"error: failed to generate {output_path}: {exc}", file=sys.stderr)
- return 1
- generated += 1
- print(f"[OK] {output_path}")
- if backend.provider == "edge":
- print(f" {subtitle_path}")
+ elif backend.provider == "minimax":
+ backend_minimax.generate(
+ text,
+ output_path,
+ api_key=backend.api_key,
+ voice_id=backend.voice_id,
+ model=args.minimax_model,
+ audio_format=args.minimax_output_format,
+ sample_rate=args.minimax_sample_rate,
+ bitrate=args.minimax_bitrate,
+ channel=args.minimax_channel,
+ speed=args.minimax_speed,
+ volume=args.minimax_volume,
+ pitch=args.minimax_pitch,
+ language_boost=args.minimax_language_boost,
+ base_url=args.minimax_base_url,
+ )
+ elif backend.provider == "qwen":
+ backend_qwen.generate(
+ text,
+ output_path,
+ api_key=backend.api_key,
+ voice_id=backend.voice_id,
+ model=args.qwen_model,
+ language_type=args.qwen_language_type,
+ instructions=args.qwen_instructions,
+ optimize_instructions=args.qwen_optimize_instructions,
+ base_url=args.qwen_base_url,
+ )
+ elif backend.provider == "cosyvoice":
+ backend_cosyvoice.generate(
+ text,
+ output_path,
+ api_key=backend.api_key,
+ voice_id=backend.voice_id,
+ model=args.cosyvoice_model,
+ audio_format=args.cosyvoice_output_format,
+ sample_rate=args.cosyvoice_sample_rate,
+ volume=args.cosyvoice_volume,
+ rate=args.cosyvoice_rate,
+ pitch=args.cosyvoice_pitch,
+ instruction=args.cosyvoice_instruction,
+ language_hint=args.cosyvoice_language_hint,
+ base_url=args.cosyvoice_base_url,
+ )
+ except Exception as exc:
+ print(f"error: failed to generate {output_path}: {exc}", file=sys.stderr)
+ return 1
+ generated += 1
+ print(f"[OK] {output_path}")
if backend.provider == "edge":
print(
diff --git a/skills/ppt-master/workflows/stages/generate-audio.md b/skills/ppt-master/workflows/stages/generate-audio.md
index 02dab3d0..e7825383 100644
--- a/skills/ppt-master/workflows/stages/generate-audio.md
+++ b/skills/ppt-master/workflows/stages/generate-audio.md
@@ -174,6 +174,11 @@ python3 skills/ppt-master/scripts/video_subtitles.py <project_path> \
--video <powerpoint_exported_video> --language <language> --force
```
+**Default — bounded Edge concurrency (may override)**: Generate up to three
+slide-level audio/SRT pairs concurrently. Use `--concurrency <N>` to tune the
+Edge path or `--concurrency 1` for serial troubleshooting. Cloud providers
+remain serial.
+
If `notes_to_audio.py` errors with a missing dependency or missing provider API key, fix the prerequisite and re-run — do NOT swallow the error.
The edge command writes each MP3 and its internal page SRT from the same `edge-tts` stream. SRT cues use the service's `WordBoundary` timing: sentence-ending punctuation always closes a cue; text over the default 20-visible-character limit first splits at commas, semicolons, or colons, then at the nearest word boundary. Override the limit with `--subtitle-max-chars`. Adjacent timing overlap up to 100 ms is tolerated by moving the later cue start to the previous cue end; larger overlap fails instead of silently distorting timing. Each SRT uses a page-local timeline whose origin is `00:00:00,000`, including any leading silence before the first cue. Cloud-provider commands currently write audio only.