yapbook 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yapbook-0.1.0/.github/workflows/ci.yml +25 -0
- yapbook-0.1.0/.gitignore +35 -0
- yapbook-0.1.0/ARCHITECTURE.md +262 -0
- yapbook-0.1.0/CHANGELOG.md +80 -0
- yapbook-0.1.0/LICENSE +202 -0
- yapbook-0.1.0/PKG-INFO +266 -0
- yapbook-0.1.0/README.md +201 -0
- yapbook-0.1.0/SPEC.md +83 -0
- yapbook-0.1.0/assets/logo.svg +21 -0
- yapbook-0.1.0/integrations/README.md +60 -0
- yapbook-0.1.0/integrations/skill/yapbook/SKILL.md +96 -0
- yapbook-0.1.0/pyproject.toml +95 -0
- yapbook-0.1.0/src/yapbook/__init__.py +3 -0
- yapbook-0.1.0/src/yapbook/audio/__init__.py +6 -0
- yapbook-0.1.0/src/yapbook/audio/lexicon.py +203 -0
- yapbook-0.1.0/src/yapbook/audio/player.py +514 -0
- yapbook-0.1.0/src/yapbook/audio/tts.py +192 -0
- yapbook-0.1.0/src/yapbook/cli.py +1337 -0
- yapbook-0.1.0/src/yapbook/config.py +212 -0
- yapbook-0.1.0/src/yapbook/doctor.py +324 -0
- yapbook-0.1.0/src/yapbook/ingest/__init__.py +12 -0
- yapbook-0.1.0/src/yapbook/ingest/arxiv.py +117 -0
- yapbook-0.1.0/src/yapbook/ingest/figures.py +183 -0
- yapbook-0.1.0/src/yapbook/ingest/kb.py +150 -0
- yapbook-0.1.0/src/yapbook/ingest/mathspeak.py +1322 -0
- yapbook-0.1.0/src/yapbook/ingest/pipeline.py +682 -0
- yapbook-0.1.0/src/yapbook/listen/__init__.py +7 -0
- yapbook-0.1.0/src/yapbook/listen/recorder.py +262 -0
- yapbook-0.1.0/src/yapbook/listen/stt.py +88 -0
- yapbook-0.1.0/src/yapbook/mcp_server.py +253 -0
- yapbook-0.1.0/src/yapbook/podcast.py +291 -0
- yapbook-0.1.0/src/yapbook/preview.py +171 -0
- yapbook-0.1.0/src/yapbook/qa/__init__.py +6 -0
- yapbook-0.1.0/src/yapbook/qa/answer.py +144 -0
- yapbook-0.1.0/src/yapbook/qa/context.py +220 -0
- yapbook-0.1.0/src/yapbook/qa/ollama_client.py +185 -0
- yapbook-0.1.0/src/yapbook/session.py +439 -0
- yapbook-0.1.0/src/yapbook/skips.py +116 -0
- yapbook-0.1.0/src/yapbook/tap/__init__.py +11 -0
- yapbook-0.1.0/src/yapbook/tap/base.py +47 -0
- yapbook-0.1.0/src/yapbook/tap/factory.py +70 -0
- yapbook-0.1.0/src/yapbook/tap/hotkey.py +148 -0
- yapbook-0.1.0/src/yapbook/tap/macos_nowplaying.py +190 -0
- yapbook-0.1.0/src/yapbook/tap/windows_smtc.py +182 -0
- yapbook-0.1.0/src/yapbook/types.py +102 -0
- yapbook-0.1.0/src/yapbook/ui/__init__.py +2 -0
- yapbook-0.1.0/src/yapbook/ui/server.py +458 -0
- yapbook-0.1.0/src/yapbook/ui/static/favicon.svg +21 -0
- yapbook-0.1.0/src/yapbook/ui/static/index.html +292 -0
- yapbook-0.1.0/tests/test_arxiv.py +140 -0
- yapbook-0.1.0/tests/test_audio_player.py +558 -0
- yapbook-0.1.0/tests/test_cli.py +435 -0
- yapbook-0.1.0/tests/test_cli_ask_podcast.py +212 -0
- yapbook-0.1.0/tests/test_config.py +168 -0
- yapbook-0.1.0/tests/test_kb.py +199 -0
- yapbook-0.1.0/tests/test_lexicon.py +119 -0
- yapbook-0.1.0/tests/test_listen_devices.py +267 -0
- yapbook-0.1.0/tests/test_mathspeak.py +383 -0
- yapbook-0.1.0/tests/test_mcp_server.py +186 -0
- yapbook-0.1.0/tests/test_pipeline_routing.py +566 -0
- yapbook-0.1.0/tests/test_podcast.py +245 -0
- yapbook-0.1.0/tests/test_preview.py +271 -0
- yapbook-0.1.0/tests/test_qa_context.py +300 -0
- yapbook-0.1.0/tests/test_session.py +632 -0
- yapbook-0.1.0/tests/test_skips.py +190 -0
- yapbook-0.1.0/tests/test_tap_factory.py +203 -0
- yapbook-0.1.0/tests/test_ui.py +294 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
strategy:
|
|
11
|
+
fail-fast: false
|
|
12
|
+
matrix:
|
|
13
|
+
os: [ubuntu-latest, windows-latest]
|
|
14
|
+
python: ["3.10", "3.12"]
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: ${{ matrix.python }}
|
|
21
|
+
# Core deps + dev tools only: the test suite runs entirely on fakes —
|
|
22
|
+
# no docling, kokoro, whisper, winrt, or audio hardware required.
|
|
23
|
+
- run: pip install -e ".[dev]"
|
|
24
|
+
- run: ruff check src tests
|
|
25
|
+
- run: pytest -q
|
yapbook-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.ruff_cache/
|
|
11
|
+
.mypy_cache/
|
|
12
|
+
|
|
13
|
+
# OS
|
|
14
|
+
.DS_Store
|
|
15
|
+
Thumbs.db
|
|
16
|
+
|
|
17
|
+
# Editors
|
|
18
|
+
.vscode/
|
|
19
|
+
.idea/
|
|
20
|
+
|
|
21
|
+
# Never commit book content, audio, or models.
|
|
22
|
+
# Real user data lives under the platformdirs user-data dir, not the repo,
|
|
23
|
+
# but belt-and-suspenders in case someone points YAPBOOK_DATA_DIR here:
|
|
24
|
+
*.pdf
|
|
25
|
+
*.epub
|
|
26
|
+
*.wav
|
|
27
|
+
*.mp3
|
|
28
|
+
*.flac
|
|
29
|
+
*.onnx
|
|
30
|
+
*.gguf
|
|
31
|
+
*.pt
|
|
32
|
+
*.pth
|
|
33
|
+
*.safetensors
|
|
34
|
+
# Public-domain test fixtures are the only exception:
|
|
35
|
+
!tests/fixtures/**
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# yapbook — Architecture
|
|
2
|
+
|
|
3
|
+
**One sentence:** yapbook turns a textbook PDF you own into a natural-voice audiobook that
|
|
4
|
+
plays through your earbuds, and when you tap play/pause it listens to your spoken question,
|
|
5
|
+
answers it *from the book, at the exact spot you were listening to*, and resumes.
|
|
6
|
+
|
|
7
|
+
Everything runs on your machine. No accounts, no uploads, no meters.
|
|
8
|
+
|
|
9
|
+
This document is the build contract. Every design decision below exists because the naive
|
|
10
|
+
alternative was tested and found broken; the "why" notes are load-bearing — do not
|
|
11
|
+
"simplify" them away.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1. The loop
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌────────────────────────────────────────────────────────────────────┐
|
|
19
|
+
│ PLAY Kokoro narrates chapter segments through earbuds (A2DP) │
|
|
20
|
+
│ │ │
|
|
21
|
+
│ TAP earbud tap = media play/pause → yapbook (registered as the │
|
|
22
|
+
│ │ system Now Playing app) pauses and arms the mic │
|
|
23
|
+
│ ASK LAPTOP mic records; Silero VAD endpoints; faster-whisper │
|
|
24
|
+
│ │ transcribes with chapter jargon as initial_prompt │
|
|
25
|
+
│ ANSWER Ollama answers from the chapter context that was KV- │
|
|
26
|
+
│ │ prewarmed during playback, grounded at the playhead; │
|
|
27
|
+
│ │ sentences stream into Kokoro as they generate │
|
|
28
|
+
│ RESUME playback continues from the same segment │
|
|
29
|
+
└────────────────────────────────────────────────────────────────────┘
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Target: 3–6 s from end-of-question to first spoken answer word, on CPU.
|
|
33
|
+
|
|
34
|
+
## 2. Module map
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
src/yapbook/
|
|
38
|
+
types.py shared dataclasses (Segment, Chapter, BookManifest, PlaybackPosition)
|
|
39
|
+
config.py platformdirs data dir, config.toml load/save, YAPBOOK_DATA_DIR override
|
|
40
|
+
cli.py argparse CLI: add / listen / books / doctor
|
|
41
|
+
doctor.py environment probes (see §9)
|
|
42
|
+
session.py the orchestrating state machine for the loop above
|
|
43
|
+
ingest/
|
|
44
|
+
pipeline.py PDF → KB via docling element-level routing
|
|
45
|
+
mathspeak.py LaTeX → spoken English (rule-based + optional LLM polish)
|
|
46
|
+
figures.py VLM description of cropped figure images via Ollama
|
|
47
|
+
kb.py KB read/write (book.json + chapters/chNNN.jsonl)
|
|
48
|
+
audio/
|
|
49
|
+
tts.py Kokoro synthesis (lazy-loaded), per-segment WAV cache
|
|
50
|
+
player.py sounddevice playback queue + continuous position persistence
|
|
51
|
+
tap/
|
|
52
|
+
base.py TapListener protocol + TapEvent
|
|
53
|
+
windows_smtc.py winrt SMTC media session (Windows)
|
|
54
|
+
macos_nowplaying.py pyobjc MPRemoteCommandCenter (macOS)
|
|
55
|
+
hotkey.py cross-platform fallback (Ctrl+Space) — no media session
|
|
56
|
+
factory.py choose the right listener per OS with graceful fallback
|
|
57
|
+
listen/
|
|
58
|
+
recorder.py laptop-mic capture (16 kHz mono) + Silero VAD endpointing
|
|
59
|
+
stt.py faster-whisper small.en int8 transcription
|
|
60
|
+
qa/
|
|
61
|
+
ollama_client.py HTTP client for localhost:11434, explicit num_ctx, health probe
|
|
62
|
+
context.py chapter-scoped append-only context window + KV prewarm
|
|
63
|
+
answer.py prompt assembly + sentence-streaming answers
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Heavy imports (torch, kokoro, faster_whisper, docling, winrt, pyobjc) are **lazy** —
|
|
67
|
+
imported inside functions, never at module top level. `yapbook doctor`, `yapbook books`,
|
|
68
|
+
and the test suite must run on a machine with none of the extras installed.
|
|
69
|
+
|
|
70
|
+
## 3. Ingest (`yapbook add book.pdf`)
|
|
71
|
+
|
|
72
|
+
**Why not a page-level text/image gatekeeper:** on born-digital textbooks it is dead code —
|
|
73
|
+
in testing, 143/143 figure-bearing pages of a standard ML textbook had selectable text, so a
|
|
74
|
+
"page has text → skip VLM" rule means the VLM never fires and every figure is lost.
|
|
75
|
+
**Why not raw text extraction:** LaTeX math extracts as garbled symbol soup that TTS reads
|
|
76
|
+
as "aitch … at … I" — measured word-error rates on equations in mainstream read-aloud tools
|
|
77
|
+
are 0.51–0.62 (MathReader, arXiv 2501.07088). Math handling is yapbook's headline feature,
|
|
78
|
+
not an edge case.
|
|
79
|
+
|
|
80
|
+
Pipeline (docling, element-level):
|
|
81
|
+
|
|
82
|
+
1. `docling` converts the PDF with layout labels per element: `text`, `section_header`,
|
|
83
|
+
`formula`, `picture`, `caption`, `code`, `page_header`/`page_footer`/`footnote`.
|
|
84
|
+
2. Routing:
|
|
85
|
+
- `text`/`section_header`/`caption` → cleaned prose segments (`kind=text|heading`).
|
|
86
|
+
- `formula` → docling's LaTeX (CodeFormula model) stored as `source_text`;
|
|
87
|
+
`mathspeak.verbalize()` produces `spoken_text`. Both are kept: the QA LLM sees LaTeX,
|
|
88
|
+
the TTS speaks English.
|
|
89
|
+
- `picture` → cropped image → `figures.describe()` (Ollama VLM `qwen3-vl:8b-instruct`, fallback
|
|
90
|
+
`qwen3-vl:4b-instruct`/`2b-instruct` for low RAM; the bare non-instruct tags are THINKING builds that return empty responses). Constraints: temperature 0, hard max-token cap,
|
|
91
|
+
n-gram repetition detector on output, and the prompt forbids transcribing equations
|
|
92
|
+
inside figures (describe what the figure *shows*). Emitted as
|
|
93
|
+
`kind=figure` with `spoken_text = "Figure: <description>"`.
|
|
94
|
+
- `page_header`/`page_footer` → dropped. `footnote` → appended at chapter end.
|
|
95
|
+
- `code` → `kind=code`; spoken as a short paraphrase line ("Code listing: …" from its
|
|
96
|
+
caption/first comment), full text kept in `source_text` for the QA LLM.
|
|
97
|
+
3. Chapters are split on top-level `section_header` elements; each chapter also gets a
|
|
98
|
+
`jargon` list (distinctive capitalized/technical terms, frequency-ranked) used later as
|
|
99
|
+
the STT `initial_prompt`.
|
|
100
|
+
4. Output (see §8 for location):
|
|
101
|
+
- `book.json` — `BookManifest`
|
|
102
|
+
- `chapters/chNNN.jsonl` — one `Segment` JSON per line, in narration order.
|
|
103
|
+
|
|
104
|
+
Segments are sentence-sized for prose (split on sentence boundaries, merged to ≥ ~120
|
|
105
|
+
chars so the TTS cache isn't thousands of tiny files), one per formula/figure.
|
|
106
|
+
|
|
107
|
+
`mathspeak` is rule-based first (Greek letters, sub/superscripts, fractions, sums,
|
|
108
|
+
products, integrals, expectations, norms, gradients, common ML operators), with an
|
|
109
|
+
optional Ollama polish pass at ingest time for equations above a complexity threshold
|
|
110
|
+
(cached in the KB — never at listen time). It must degrade gracefully: unknown LaTeX
|
|
111
|
+
falls back to a cleaned literal reading, never an exception.
|
|
112
|
+
|
|
113
|
+
## 4. Audio out (`audio/`)
|
|
114
|
+
|
|
115
|
+
- Kokoro-82M (`af_heart` default voice), Apache-2.0. Speed is applied via Kokoro's
|
|
116
|
+
synthesis-time `speed` parameter (default 1.1). **Never resample to change speed**
|
|
117
|
+
(chipmunk artifact).
|
|
118
|
+
- Phonemization: `espeakng-loader` pip wheel + `phonemizer-fork` — never require a system
|
|
119
|
+
espeak-ng install (the Windows .msi + env-var dance is the #1 Kokoro install failure).
|
|
120
|
+
espeak-ng is misaki's out-of-dictionary fallback and IS needed for ML jargon.
|
|
121
|
+
- Synthesis is per-segment, written to the audio cache (`audio-cache/chNNN/SSSSS.wav`),
|
|
122
|
+
with a small look-ahead worker (synthesize N+1, N+2 while N plays). Cache hits skip
|
|
123
|
+
synthesis entirely — re-listening is instant and free.
|
|
124
|
+
- Playback: `sounddevice` OutputStream, one short-lived stream per segment run. On any
|
|
125
|
+
PortAudio error: close, re-scan devices, reopen (PortAudio has no hotplug; Bluetooth
|
|
126
|
+
earbuds appear/disappear as endpoints).
|
|
127
|
+
- `PlaybackPosition` (book, chapter, segment) is persisted to `positions.json` with an
|
|
128
|
+
atomic write **on every segment boundary and on every pause** — a crash may never lose
|
|
129
|
+
the user's place. That file is the playhead the QA engine grounds on.
|
|
130
|
+
|
|
131
|
+
## 5. Tap capture (`tap/`)
|
|
132
|
+
|
|
133
|
+
**Why not a keyboard listener:** earbud taps are *media-transport* events, not keystrokes.
|
|
134
|
+
On macOS they route via MediaRemote to the current "Now Playing" app — pynput never sees
|
|
135
|
+
them, and if no app claims Now Playing, the tap launches Apple Music over your session.
|
|
136
|
+
On Windows a passive hook still lets Spotify/the browser grab the same tap.
|
|
137
|
+
|
|
138
|
+
So yapbook registers as a **real media session**:
|
|
139
|
+
|
|
140
|
+
- **Windows** (`windows_smtc.py`): modern `winrt-*` modular packages (the monolithic
|
|
141
|
+
`winsdk` package is deprecated). A `Windows.Media.Playback.MediaPlayer` with
|
|
142
|
+
`CommandManager` disabled-then-configured exposes SMTC; handle Play/Pause/Toggle
|
|
143
|
+
button events; publish title/artist ("yapbook — <book title>") and playback status so
|
|
144
|
+
the OS routes earbud taps to us.
|
|
145
|
+
- **macOS** (`macos_nowplaying.py`): pyobjc `MPNowPlayingInfoCenter` +
|
|
146
|
+
`MPRemoteCommandCenter` (togglePlayPauseCommand etc.). Requires an NSRunLoop pump on a
|
|
147
|
+
dedicated thread. This kills any need for the Accessibility permission. Keep
|
|
148
|
+
`MPNowPlayingInfoPropertyPlaybackRate` and `DefaultPlaybackRate` in lockstep with the
|
|
149
|
+
actual (1.1×) rate, or Bluetooth pause commands can be dropped.
|
|
150
|
+
- **Fallback** (`hotkey.py`): Ctrl+Space global hotkey for setups where media routing
|
|
151
|
+
is broken; selected explicitly or when the native listener fails to initialize.
|
|
152
|
+
|
|
153
|
+
The listener surfaces a single `TapEvent` stream; `session.py` interprets it
|
|
154
|
+
(pause→ask vs resume) — listeners carry no session logic.
|
|
155
|
+
|
|
156
|
+
## 6. Voice in (`listen/`)
|
|
157
|
+
|
|
158
|
+
**Why the laptop mic, not the earbud mic:** opening a Bluetooth headset mic switches the
|
|
159
|
+
whole headset from A2DP (stereo, high quality) to HFP/SCO — playback collapses to mono
|
|
160
|
+
8–16 kHz with a 1–3 s glitch on each switch, and Windows 11 is notorious for getting stuck
|
|
161
|
+
in Hands-Free mode afterwards (Microsoft's own guidance: use a different mic). The user is
|
|
162
|
+
in the same room as the laptop (kitchen counter, desk); the laptop mic hears them fine and
|
|
163
|
+
playback quality never degrades.
|
|
164
|
+
|
|
165
|
+
- Default input: system default *non-Bluetooth* input device (prefer built-in mic when the
|
|
166
|
+
default input is the earbuds' Hands-Free endpoint; warn once). `--earbud-mic` opts in to
|
|
167
|
+
the HFP tradeoff explicitly.
|
|
168
|
+
- Capture 16 kHz mono via sounddevice InputStream.
|
|
169
|
+
- Endpointing: Silero VAD (bundled with faster-whisper) — stop after ~1.2 s trailing
|
|
170
|
+
silence, hard cap 30 s.
|
|
171
|
+
- STT: `faster-whisper` `small.en` int8 (~1–3 s for a 10 s clip on CPU). `initial_prompt`
|
|
172
|
+
is seeded with the current chapter's `jargon` list so "RLHF", "KL penalty", "logits"
|
|
173
|
+
transcribe correctly.
|
|
174
|
+
|
|
175
|
+
## 7. QA (`qa/`)
|
|
176
|
+
|
|
177
|
+
**Why not "stuff the whole book in the prompt":** a 300–600 page book is 156k–390k tokens
|
|
178
|
+
— over every local model's window — and Ollama's default context on <24 GiB VRAM machines
|
|
179
|
+
is 4k with **silent truncation from the front**, so naive stuffing yields a model that has
|
|
180
|
+
only seen the last few pages and answers confidently from the wrong place. 50k tokens of
|
|
181
|
+
context ≈ 2–8 min of CPU prefill — unusable per-question.
|
|
182
|
+
|
|
183
|
+
Design:
|
|
184
|
+
|
|
185
|
+
- **Chapter-scoped, append-only context.** The conversation context is: a fixed system
|
|
186
|
+
prompt + the current chapter's segments *up to the playhead* (append-only as playback
|
|
187
|
+
advances) + the Q&A turns. Append-only matters: it preserves llama.cpp's prefix KV
|
|
188
|
+
cache, so each new question only prefills the delta.
|
|
189
|
+
- **KV prewarm during playback.** While a segment plays, `context.py` sends the grown
|
|
190
|
+
context to Ollama with `"prompt": ""`-style warm requests so the KV cache is already hot
|
|
191
|
+
when the tap comes. Result: tap-to-first-word stays in the 3–6 s budget on CPU.
|
|
192
|
+
- Brain: `qwen3:4b-instruct` (Apache-2.0, non-thinking variant — never a thinking
|
|
193
|
+
model; latency budget). `num_ctx` set **explicitly** (default 16384); at session start,
|
|
194
|
+
assert the planned chapter context fits and log the token count (never trust silent
|
|
195
|
+
defaults).
|
|
196
|
+
- Cross-chapter questions ("how does this relate to chapter 2?") are detected by a cheap
|
|
197
|
+
heuristic (mentions of other chapters / "earlier in the book") and answered via optional
|
|
198
|
+
embedding retrieval (nomic-embed-text + a flat numpy index built at ingest) spliced in
|
|
199
|
+
as a clearly-delimited RETRIEVED block — appended, never prepended (prefix cache).
|
|
200
|
+
- Grounding rule in the system prompt: answer *at the listener's position* — "what did it
|
|
201
|
+
just say?" refers to the last ~3 segments; never spoil content past the playhead unless
|
|
202
|
+
asked explicitly.
|
|
203
|
+
- Answers are capped at 2–4 spoken sentences and stream sentence-by-sentence into Kokoro
|
|
204
|
+
— first sentence speaks while the rest generates.
|
|
205
|
+
|
|
206
|
+
## 8. Data locations (`config.py`)
|
|
207
|
+
|
|
208
|
+
All user data lives under `platformdirs.user_data_dir("yapbook")` (override:
|
|
209
|
+
`YAPBOOK_DATA_DIR`):
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
yapbook/
|
|
213
|
+
config.toml
|
|
214
|
+
positions.json
|
|
215
|
+
books/<slug>/
|
|
216
|
+
book.json
|
|
217
|
+
chapters/chNNN.jsonl
|
|
218
|
+
audio-cache/chNNN/SSSSS.wav
|
|
219
|
+
figures/…png (cropped, for re-description)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Never inside the repo/install dir**: the KB markdown and audio cache are derivative
|
|
223
|
+
copies of a copyrighted book. `.gitignore` is not a privacy mechanism; the data dir is.
|
|
224
|
+
|
|
225
|
+
## 9. Doctor (`yapbook doctor`)
|
|
226
|
+
|
|
227
|
+
Probes, each with a one-line PASS/FAIL/SKIP and a fix hint:
|
|
228
|
+
|
|
229
|
+
1. Python version, OS, yapbook version.
|
|
230
|
+
2. Ollama reachable at `localhost:11434`; required models pulled (brain, VLM, embed) —
|
|
231
|
+
exact pinned tags; VRAM/RAM estimate note.
|
|
232
|
+
3. Kokoro importable; espeakng-loader data path resolves; 1-word test synth (optional).
|
|
233
|
+
4. faster-whisper importable; `small.en` model present or downloadable note.
|
|
234
|
+
5. Input devices: list; flag when the default input is a Bluetooth Hands-Free endpoint.
|
|
235
|
+
6. Output devices: list; flag when no output device.
|
|
236
|
+
7. macOS: mic permission status. Windows: note SMTC availability.
|
|
237
|
+
8. Data dir writable; disk-space note (~10–12 GB for the full model set, stated plainly).
|
|
238
|
+
|
|
239
|
+
## 10. Licensing & posture
|
|
240
|
+
|
|
241
|
+
- Code: Apache-2.0.
|
|
242
|
+
- Models (all weights downloaded by the user at first run, never redistributed):
|
|
243
|
+
| Component | Model | License |
|
|
244
|
+
|---|---|---|
|
|
245
|
+
| TTS | Kokoro-82M | Apache-2.0 |
|
|
246
|
+
| Brain | qwen3:4b-instruct | Apache-2.0 |
|
|
247
|
+
| VLM | qwen3-vl (8b/4b/2b instruct) | Apache-2.0 |
|
|
248
|
+
| STT | faster-whisper small.en | MIT (weights: OpenAI Whisper, MIT) |
|
|
249
|
+
| Embeddings (optional) | nomic-embed-text | Apache-2.0 |
|
|
250
|
+
- Deliberately avoided: Qwen2.5-VL-3B (research-only license), Llama 3.x (non-OSI).
|
|
251
|
+
- Disclaimer (README, ebook2audiobook-style): for personal use with books you lawfully
|
|
252
|
+
own; no DRM circumvention; the project makes **no legal claims** — never the words
|
|
253
|
+
"legal" or "fair use" in docs.
|
|
254
|
+
- Test fixtures: public-domain text only, with a CI size check.
|
|
255
|
+
|
|
256
|
+
## 11. Non-goals (v0.x)
|
|
257
|
+
|
|
258
|
+
- No cloud fallback of any kind. No accounts, no telemetry.
|
|
259
|
+
- No mobile app; a phone-reachable playback story (local-network PWA/stream) is a
|
|
260
|
+
candidate for v0.3+, tracked in the README roadmap.
|
|
261
|
+
- No EPUB ingest in v0.1 (PDF first; EPUB is a docling flag away and lands v0.2).
|
|
262
|
+
- No wake word; the tap (or hotkey) is the only trigger.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-07-27
|
|
4
|
+
|
|
5
|
+
First release: the full loop works end to end on real hardware — verified with
|
|
6
|
+
Bluetooth earbuds against Sutton & Barto's *Reinforcement Learning* (548 pages,
|
|
7
|
+
9,000+ segments, 382 formulas, 160 figures).
|
|
8
|
+
|
|
9
|
+
### The loop
|
|
10
|
+
- `yapbook add book.pdf` — one-time ingest: docling element routing, LaTeX
|
|
11
|
+
formulas verbalized tutor-style ("the expectation over x of…"), figures
|
|
12
|
+
described by a local vision model, per-chapter jargon for the STT.
|
|
13
|
+
- `yapbook listen book` — Kokoro narration through your earbuds as a real OS
|
|
14
|
+
media session (SMTC). Tap to pause + ask a question out loud; the answer is
|
|
15
|
+
grounded at your exact listening position and playback auto-resumes.
|
|
16
|
+
- Follow-up window after each answer ("Any other questions?"), earcons when
|
|
17
|
+
the mic opens and when speech is captured, double-tap segment skip,
|
|
18
|
+
triple-tap replay, chapter auto-advance with spoken announcements.
|
|
19
|
+
- `yapbook config` / `yapbook voices` / `--voice` / `--speed`; user
|
|
20
|
+
pronunciation lexicon (`pronunciations.toml`) on top of built-in ML/STEM
|
|
21
|
+
defaults.
|
|
22
|
+
- `yapbook add 2501.07088` — arXiv papers by id or URL (PDF + title fetched
|
|
23
|
+
from the export API), the fastest way to try the math verbalization.
|
|
24
|
+
- `yapbook-mcp` — an MCP server for Claude and other MCP clients:
|
|
25
|
+
list books, check your position, ask position-grounded questions, queue
|
|
26
|
+
new papers.
|
|
27
|
+
- `yapbook ask book "question"` — the same position-grounded Q&A as a plain
|
|
28
|
+
CLI command, for scripts and shell-first agents.
|
|
29
|
+
- A portable agent skill (`integrations/skill/yapbook/SKILL.md`) — one file
|
|
30
|
+
that works in Claude Code, OpenClaw, and Codex CLI; plus per-host MCP
|
|
31
|
+
setup notes (Claude Desktop, Odysseus) in `integrations/`.
|
|
32
|
+
- `yapbook podcast book [--serve]` — export one episode per chapter + an RSS
|
|
33
|
+
feed; `--serve` publishes it on your WiFi so any podcast app can subscribe
|
|
34
|
+
(offline downloads, background play, lock-screen controls). MP3 via the
|
|
35
|
+
`podcast` extra (lameenc), WAV fallback without it; episodes are keyed to
|
|
36
|
+
voice/speed so a settings change never leaves mixed-voice episodes behind.
|
|
37
|
+
- `yapbook ui` — a local web UI (the `ui` extra: Flask + qrcode). Drag-drop
|
|
38
|
+
ingest with live background-job progress, library with positions, chapter
|
|
39
|
+
skip-list checkboxes, preview generation/reading, one-click podcast export
|
|
40
|
+
with a scan-with-your-phone QR code, and a Listen button that opens the
|
|
41
|
+
earbud session in its own console. Binds 127.0.0.1 only and rejects
|
|
42
|
+
foreign Host/Origin (DNS-rebinding/CSRF hardening); the LAN sees nothing
|
|
43
|
+
but the podcast feed, only while shared. One HTML file, no JS build step.
|
|
44
|
+
- MCP `add_book` (via `add_ref`) now reports pipeline progress through the
|
|
45
|
+
same seam the UI uses and auto-marks back matter, matching the CLI.
|
|
46
|
+
- Beyond PDFs: `yapbook add` ingests EPUB, DOCX, PPTX, HTML, and Markdown
|
|
47
|
+
through the same docling pipeline and element routing (the PDF path keeps
|
|
48
|
+
its formula/figure enrichment; other formats use docling's native readers).
|
|
49
|
+
- `yapbook preview book` — browse by ear: a spoken ~30-second summary per
|
|
50
|
+
chapter, generated locally from the chapter's own KB text and cached per
|
|
51
|
+
brain model (`--text` prints for scripts/agents; `--chapter N` for one;
|
|
52
|
+
explicit chapters preview even when marked skip).
|
|
53
|
+
- `yapbook skip book` — per-chapter skip lists honored by both `listen`
|
|
54
|
+
(auto-advance passes over them, announced) and `podcast` (excluded from the
|
|
55
|
+
feed). Back matter is auto-detected by title at ingest (References,
|
|
56
|
+
Bibliography, Acknowledgments, Index, …) with conservative matching —
|
|
57
|
+
"Reference Frames" is a physics chapter, not back matter — and
|
|
58
|
+
Introductions are never auto-marked. Playback-only: the KB keeps every
|
|
59
|
+
chapter for Q&A. An explicit `--chapter` always plays, even a skipped one.
|
|
60
|
+
- 100% local: Ollama (Qwen3) + faster-whisper + Kokoro. No accounts, no
|
|
61
|
+
uploads, no telemetry.
|
|
62
|
+
|
|
63
|
+
### Notable fixes made along the way (the sharp edges we hit so you don't)
|
|
64
|
+
- The bare `qwen3-vl:8b` Ollama tag is the *thinking* build: it burns the
|
|
65
|
+
whole `num_predict` budget on hidden reasoning and returns empty
|
|
66
|
+
descriptions. yapbook pins the `-instruct` tags and refuses to accept an
|
|
67
|
+
empty description silently.
|
|
68
|
+
- On Windows, initializing WinRT/COM (the media session) before torch's first
|
|
69
|
+
import makes `c10.dll` fail to load (WinError 1114). `listen` preloads the
|
|
70
|
+
native ML runtimes on the main thread, first.
|
|
71
|
+
- Bluetooth sinks pop when the audio device is re-acquired per utterance; a
|
|
72
|
+
persistent output stream is reused across narration, answers, and earcons.
|
|
73
|
+
- Re-ingesting a book invalidates its narration cache (cached WAVs are keyed
|
|
74
|
+
by position, and positions renumber).
|
|
75
|
+
- OCR'd formulas can loop (`\exp(\exp(\exp(…` ×24); spoken math collapses
|
|
76
|
+
degenerate repetition, drops content-free alignment fragments, and caps a
|
|
77
|
+
single formula's speech at ~40 s.
|
|
78
|
+
- Laptop mic is the default question input — opening the earbud mic would
|
|
79
|
+
collapse the whole headset to phone-quality HFP audio (`--earbud-mic` to
|
|
80
|
+
opt in anyway).
|
yapbook-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|