Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI
on:
push:
branches: ['codex/**']
# Every pull request, including ones stacked on another branch.
pull_request:
branches: [main]

permissions:
contents: read
Expand Down
278 changes: 227 additions & 51 deletions README.md

Large diffs are not rendered by default.

Binary file removed assets/demo.png
Binary file not shown.
Binary file added assets/screenshots/check-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/create-audio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/dark-mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/export.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/library.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/screenshots/pick-a-voice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def _parser():
parser.add_argument("--resume", action="store_true", help="Reuse chapters only when source/settings/audio hashes match")
parser.add_argument("--title")
parser.add_argument("--author")
parser.add_argument("--ui", choices=["desktop", "classic"], default="desktop",
help="Without an input file: open the desktop app, or the classic Tk window")
parser.add_argument("--dev", action="store_true", help=argparse.SUPPRESS)
return parser


Expand Down Expand Up @@ -77,6 +80,9 @@ def _export(args, source, output_dir, audio_files, temporary, chapters):
def main(argv=None):
args = _parser().parse_args(argv)
if args.input is None:
if args.ui == "desktop":
from webui.app import run
return run(dev=args.dev)
from ui import AudiobookApp
AudiobookApp().mainloop()
return 0
Expand Down
27 changes: 26 additions & 1 deletion generate_audiobook_kokoro.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from kokoro import KPipeline

DEFAULT_SAMPLE_RATE = 24000
SPEECH_BLOCK_CHARS = 450
MODEL_REPO = "hexgrad/Kokoro-82M"
DEVICE = "auto"

Expand Down Expand Up @@ -84,6 +85,30 @@ def _spoken_text(text):
return bool(re.search(r"[^\W_]", text or "", re.UNICODE))


def speech_blocks(text, limit=SPEECH_BLOCK_CHARS):
"""Join extracted lines into paragraph-sized blocks, one per line.

Extraction leaves about one sentence per line. Sending each sentence to Kokoro
separately is ~5x slower and adds a pause after every sentence, so lines are
joined up to `limit` characters; blank lines still end a paragraph.
"""
blocks = []
for paragraph in re.split(r"\n\s*\n", text):
current = ""
for line in paragraph.splitlines():
line = line.strip()
if not _spoken_text(line):
continue
if current and len(current) + 1 + len(line) > limit:
blocks.append(current)
current = line
else:
current = f"{current} {line}" if current else line
if current:
blocks.append(current)
return "\n".join(blocks)


def _audio_array(audio):
if audio is None:
return None
Expand Down Expand Up @@ -132,7 +157,7 @@ def generate_audio_for_file_kokoro(input_path, pipeline, voice, output_path,
temporary = None
try:
text = Path(input_path).read_text(encoding="utf-8")
text = "\n".join(line for line in text.splitlines() if _spoken_text(line))
text = speech_blocks(text)
if not _spoken_text(text):
raise ValueError("Input contains no letters or digits.")
destination = Path(output_path)
Expand Down
Loading
Loading