Skip to content

Narrate explainer videos with the Kokoro af_heart voice - #5

Merged
ruikelyu merged 1 commit into
mainfrom
kokoro-voice
Nov 13, 2026
Merged

ruikelyu merged 1 commit into
mainfrom
kokoro-voice

Conversation

@ruikelyu

@ruikelyu ruikelyu commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • tools/videos: Kokoro (hexgrad/Kokoro-82M, voice af_heart) is the default narration engine. kokoro_tts.py voices every sentence of a video in one batch, run from a separate environment ($KOKORO_PYTHON, the current interpreter if it has kokoro, or ~/.venvs/kokoro), so PyTorch stays out of the toolkit's dependencies.
  • --engine say keeps the macOS voice; --speed controls Kokoro's pace.
  • Scene audio is loudness-normalized to −16 LUFS (Kokoro alone is about −26).
  • READMEs: Kokoro setup and links to the re-uploaded videos.

Checked

  • All five toolkit videos (plus two project videos using the same framework) rendered; each is −16.3 to −16.6 LUFS with captions matching the sentences.

🤖 Generated with Claude Code

Summary by Sourcery

Modernize explainer video narration with Kokoro, consistent audio levels, and refreshed published videos.

New Features:

  • Add Kokoro neural narration with the af_heart voice as the default engine for explainer videos.
  • Retain macOS say as an alternative narration engine with configurable voice and speaking rate.
  • Batch narration generation and support configurable Kokoro voice and speed.

Bug Fixes:

  • Normalize rendered scene audio to approximately −16 LUFS for consistent playback volume.

Enhancements:

  • Update the video-rendering workflow to discover Kokoro in a dedicated environment while keeping PyTorch outside the toolkit dependencies.

Documentation:

  • Document Kokoro installation and usage, and update links to the re-rendered explainer videos.

- New default engine: Kokoro (kokoro_tts.py), all sentences of a video voiced
  in one batch from a separate environment ($KOKORO_PYTHON or ~/.venvs/kokoro)
- --engine say keeps the macOS voice; --speed for Kokoro
- Scene audio loudness-normalized to -16 LUFS
- README: Kokoro setup; links to the re-uploaded videos

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose Kokoro and macOS narration options through the render function and command-line interface, including Kokoro speed control.

  • tools/videos/common.py L182-183, L272-279

Implementation

Batch-synthesize narration with Kokoro or macOS say, then use the resulting clips for captions and loudness-normalized scene audio.

  • tools/videos/common.py L1-9, L17-22, L151-175 (+4 small edits)
  • tools/videos/kokoro_tts.py L1-39

Documentation

Update the published video links and document Kokoro installation, narration options, and rendered outputs.

  • README.md L68-72
  • tools/videos/README.md L7-32

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 security issue, and 1 other issue

Security issues:

  • Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tools/videos/common.py" line_range="194" />
<code_context>
+    ext = ".aiff" if engine == "say" else ".wav"
+    clips = {(si, k): ((item[1] if isinstance(item, tuple) else item), work / f"s{si:02d}_{k:02d}{ext}")
+             for si, scene in enumerate(video.scenes) for k, item in enumerate(scene.narration)}
+    durations = dict(zip(clips, synthesize(list(clips.values()), engine, voice, rate, speed)))
+
     for si, scene in enumerate(video.scenes):
</code_context>
<issue_to_address>
**Video and captions diverge**

When two invocations target the same video name and output directory with different narration timing, or a render stops after replacing the MP4, two render invocations for the same video name and output directory can synthesize different durations, then overwrite the shared MP4 and SRT separately; one invocation can therefore leave the other invocation’s captions paired with its video. A process stopping after the MP4 write can also leave the previous SRT beside the new video, so viewers see mistimed captions.

Stage the outputs as a versioned set and publish them together, or otherwise ensure readers cannot pair artifacts from different renders.
</issue_to_address>

### Comment 2
<location path="tools/videos/common.py" line_range="171-172" />
<code_context>
        subprocess.run([_kokoro_python(), str(Path(__file__).with_name("kokoro_tts.py")), str(jobs),
                        "--voice", voice, "--speed", str(speed)], check=True)
</code_context>
<issue_to_address>
**security (python.lang.security.audit.dangerous-subprocess-use-audit):** Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

*Source: opengrep*
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: tools/videos/common.py:194, tools/videos/common.py:172


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tools/videos/common.py
ext = ".aiff" if engine == "say" else ".wav"
clips = {(si, k): ((item[1] if isinstance(item, tuple) else item), work / f"s{si:02d}_{k:02d}{ext}")
for si, scene in enumerate(video.scenes) for k, item in enumerate(scene.narration)}
durations = dict(zip(clips, synthesize(list(clips.values()), engine, voice, rate, speed)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Video and captions diverge

When two invocations target the same video name and output directory with different narration timing, or a render stops after replacing the MP4, two render invocations for the same video name and output directory can synthesize different durations, then overwrite the shared MP4 and SRT separately; one invocation can therefore leave the other invocation’s captions paired with its video. A process stopping after the MP4 write can also leave the previous SRT beside the new video, so viewers see mistimed captions.

Stage the outputs as a versioned set and publish them together, or otherwise ensure readers cannot pair artifacts from different renders.

Prompt for AI agents
In `tools/videos/common.py` at line 194:

**Video and captions diverge**

When two invocations target the same video name and output directory with different narration timing, or a render stops after replacing the MP4, two render invocations for the same video name and output directory can synthesize different durations, then overwrite the shared MP4 and SRT separately; one invocation can therefore leave the other invocation’s captions paired with its video. A process stopping after the MP4 write can also leave the previous SRT beside the new video, so viewers see mistimed captions.

Stage the outputs as a versioned set and publish them together, or otherwise ensure readers cannot pair artifacts from different renders.

Comment thread tools/videos/common.py
Comment on lines +171 to +172
subprocess.run([_kokoro_python(), str(Path(__file__).with_name("kokoro_tts.py")), str(jobs),
"--voice", voice, "--speed", str(speed)], check=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'run' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

@ruikelyu
ruikelyu merged commit b9eac8d into main Nov 13, 2026
6 of 7 checks passed
@ruikelyu
ruikelyu deleted the kokoro-voice branch November 13, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant