Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

fix(books): text overlaps, a blank opening, a clipped narration clip

yzrf1adf30560b7
diff --git a/.claude/skills/papermorph/scripts/tts.py b/.claude/skills/papermorph/scripts/tts.py
index 7439787..0e5c274 100644
--- a/.claude/skills/papermorph/scripts/tts.py
+++ b/.claude/skills/papermorph/scripts/tts.py
@@ -141,8 +141,9 @@ def split_marks(raw):
return "".join(clean), marks
-def time_at(clean, words):
- """Return f(pos): start time of the first spoken word at or after char pos."""
+def time_at(clean, words, estimate=False):
+ """Return f(pos): start time of the first spoken word at or after char pos. The voice's word list can stop
+ short of the text; with estimate, a position past its last word is timed at the speaking rate so far."""
cursor, located = 0, []
for t, w in words:
i = clean.find(w, cursor)
@@ -150,7 +151,13 @@ def time_at(clean, words):
continue
located.append((i, t))
cursor = i + len(w)
- return lambda pos: next((round(t, 3) for i, t in located if i >= pos), None)
+ def at(pos):
+ t = next((t for i, t in located if i >= pos), None)
+ if t is None and estimate and located:
+ i, t = located[-1]
+ t += (pos - i) * t / max(i, 1)
+ return None if t is None else round(t, 3)
+ return at
def mark_times(clean, marks, words):
@@ -162,10 +169,15 @@ def mark_times(clean, marks, words):
return out
+ABBREV = re.compile(r"(?<![\w.])(?:Mr|Mrs|Ms|Dr|Prof|St|vs|approx|e\.g|i\.e|cf)\.$")
+
+
def caption_cues(clean, words):
"""One cue per sentence: [start seconds, sentence]."""
- at, cues, start = time_at(clean, words), [], 0
- for m in list(re.finditer(r"[.?!]\s+", clean)) + [None]:
+ at, cues, start = time_at(clean, words, estimate=True), [], 0
+ for m in list(re.finditer(r"[.?!]\s+|[。!?]\s*", clean)) + [None]:
+ if m and ABBREV.search(clean, 0, m.start() + 1): # "Mr. Lee", "e.g. a lot" go on
+ continue
end = m.end() if m else len(clean)
text = clean[start:end].strip()
if text:
@@ -243,6 +255,11 @@ async def main(src, out_dir):
if tmp:
tmp.replace(mp3)
print(f"{beat}: synthesized")
+ # Edge has returned clips that stop a sentence early: the last spoken word should end the text
+ ends = re.findall(r"[A-Za-z][\w'-]*", clean[-40:])
+ if words and ends and clean.isascii() and words[-1][1].strip(".,;:!?\"'") != ends[-1]:
+ print(f"{beat}: WARNING the voice's last word is {words[-1][1]!r} but the text ends {ends[-1]!r}: the clip "
+ "may be cut short; listen to it, and synthesize it again (change its cached key) if so")
result[beat] = entry
cache[beat] = entry
# A later failed beat must not discard the successful beats' cache.
diff --git a/site/elementary-algebra/ch03/index.html b/site/elementary-algebra/ch03/index.html
index a3a888a..26c4de8 100644
--- a/site/elementary-algebra/ch03/index.html
+++ b/site/elementary-algebra/ch03/index.html
@@ -138,7 +138,7 @@ const BEATS = [
show(g, m(mark, i === 3 || i === 5 ? .5 : 0));
return g;
});
- show(T(p, 'Handy, but it can mislead you.', { x: 200, y: 590, size: 28, fill: COL.bad, o: 0 }), m('trap'));
+ show(T(p, 'Handy, but it can mislead you.', { x: 200, y: 670, size: 28, fill: COL.bad, o: 0 }), m('trap'));
tw(rows[3], { x: 560, y: 340 }, m('md'), 1);
tw(rows[4], { y: 420 }, m('md'), 1); tw(rows[5], { y: 500 }, m('md'), 1);
arrowLine(p, 180, 880, 366, LM, m('md', 1.2));
diff --git a/site/elementary-algebra/ch16/index.html b/site/elementary-algebra/ch16/index.html
index c65a9a7..6c953e9 100644
--- a/site/elementary-algebra/ch16/index.html
+++ b/site/elementary-algebra/ch16/index.html
@@ -114,7 +114,7 @@ const BEATS = [
c.add(20.4 * 3, CP, m('y2c'), '+$20.40');
mline(p, ['$1040'], 500, 770, m('y2s', 1), IN, 40);
mline(p, ['$1040.40'], 1100, 770, m('y2c', 2), CP, 40);
- caption(p, 'compound interest earns interest on interest', m('gap'), 780, COL.task, 30, 800);
+ caption(p, 'compound interest earns interest on interest', m('gap'), 845, COL.task, 30, 800);
show(T(p, 'interest blocks drawn larger to be visible', { x: 800, y: 460, size: 20, fill: COL.faint, anchor: 'middle', o: 0 }), m('y1'));
}],
['q3', 'Quick check', () => { panel(0); }, { ask: done => quiz(BAND, [{
diff --git a/site/elementary-algebra/ch63/index.html b/site/elementary-algebra/ch63/index.html
index 9c66b9e..3daa4d9 100644
--- a/site/elementary-algebra/ch63/index.html
+++ b/site/elementary-algebra/ch63/index.html
@@ -73,7 +73,7 @@ const BEATS = [
const cnt = T(p, '', { x: 300, y: 300, size: 46, fill: HIT, weight: 600, anchor: 'middle' });
const set = b => {
ln.setAttribute('d', `M${P.PX(-6)} ${P.PY(b)}H${P.PX(6)}`);
- put(lab, { y: P.PY(b) + 10 }); lab.textContent = `y = ${num(Math.round(b * 10) / 10)}`;
+ put(lab, { y: P.PY(b) + 10 - 22 * Math.max(0, 1 - Math.abs(b) / 2) }); lab.textContent = `y = ${num(Math.round(b * 10) / 10)}`; // the label lifts above the line near the x axis
const r = b > 0 ? Math.sqrt(b) : 0;
put(dA, { x: P.PX(r), y: P.PY(b), o: b >= -.05 ? 1 : 0 }); put(dB, { x: P.PX(-r), y: P.PY(b), o: b > .05 ? 1 : 0 });
cnt.textContent = b > .05 ? 'two solutions' : b >= -.05 ? 'one solution' : 'no real solution';
diff --git a/site/elementary-algebra/ch65/index.html b/site/elementary-algebra/ch65/index.html
index 9ee9486..87650fa 100644
--- a/site/elementary-algebra/ch65/index.html
+++ b/site/elementary-algebra/ch65/index.html
@@ -75,7 +75,7 @@ const BEATS = [
xeq(p, '7 − 5', '4', 1150, 500, m('two', .6), { size: 50 });
mline(p, 'x = 3', 900, 700, m('ans'), HIT, 56);
mline(p, ['x = ', F(1, 2)], 1230, 700, m('ans', .8), HIT, 56);
- text(p, '−(−7) = 7', 820, 340, m('sub', 2.5), { size: 28, fill: CB, weight: 600 });
+ text(p, '−(−7) = 7', 875, 340, m('sub', 2.5), { size: 28, fill: CB, weight: 600 });
}],
['graph', 'Checking on a graph', (m) => {
const p = panel(0), P = plane(p, { cx: 560, cy: 520, u: 70, x0: -2, x1: 5, y0: -4, y1: 4, t0: m('par') });
diff --git a/site/elementary-algebra/ch68/index.html b/site/elementary-algebra/ch68/index.html
index d853160..839428f 100644
--- a/site/elementary-algebra/ch68/index.html
+++ b/site/elementary-algebra/ch68/index.html
@@ -95,7 +95,7 @@ const BEATS = [
text(p, 'axis of symmetry x = −4', 140, 270, m('axis'), { size: 30, fill: AXC, weight: 600 });
P.arrow(-4, .5, -6, .5, ROOT, m('dist'), { label: '2' });
P.arrow(-4, .5, -2, .5, HIT, m('mirror'), { label: '2' });
- P.dot(-2, 0, HIT, m('mirror', .8), { label: '(−2, 0)', dx: 14, dy: 40 });
+ P.dot(-2, 0, HIT, m('mirror', .8)); // named in the text on the left: a label here sat on the tick numbers
P.fn(x => .75 * (x + 4) ** 2 - 3, -6.3, -1.7, PAR, m('mirror', 1.4));
text(p, 'other root: (−2, 0)', 140, 360, m('mirror', 1), { size: 34, fill: HIT, weight: 700 });
}],
diff --git a/site/math-notebook/ch14/audio/en/repartition.mp3 b/site/math-notebook/ch14/audio/en/repartition.mp3
index 204ff0b..ab29c7c 100644
Binary files a/site/math-notebook/ch14/audio/en/repartition.mp3 and b/site/math-notebook/ch14/audio/en/repartition.mp3 differ
diff --git a/site/math-notebook/ch14/audio/en/timings.js b/site/math-notebook/ch14/audio/en/timings.js
index 77db3d6..ac0c7c6 100644
--- a/site/math-notebook/ch14/audio/en/timings.js
+++ b/site/math-notebook/ch14/audio/en/timings.js
@@ -285,11 +285,11 @@ window.TIMINGS = {
]
},
"repartition": {
- "dur": 36.84,
+ "dur": 44.376,
"marks": {
- "cuts": 3.633,
- "labels": 14.518,
- "compare": 25.443
+ "cuts": 3.828,
+ "labels": 14.596,
+ "compare": 26.042
},
"cues": [
[
@@ -297,39 +297,39 @@ window.TIMINGS = {
"Keep every original fourth and fifth in place."
],
[
- 3.633,
+ 3.828,
"Split each fourth into five equal pieces and each fifth into four equal pieces."
],
[
- 9.935,
+ 10.117,
"Both rows now use twentieths."
],
[
- 12.201,
+ 12.331,
"No length was added or removed."
],
[
- 14.518,
+ 14.596,
"Negative three fourths is negative fifteen twentieths."
],
[
- 18.516,
+ 18.672,
"Negative three fifths is negative twelve twentieths."
],
[
- 22.266,
+ 22.552,
"The points remain in exactly the same positions."
],
[
- 25.443,
+ 26.042,
"Negative fifteen is less than negative twelve, so negative fifteen twentieths is less than negative twelve twentieths."
],
[
- 33.32,
+ 33.997,
"Common denominators compare equal-sized pieces."
],
[
- 0,
+ 37.669,
"They are one useful method; they are not required when another exact comparison already settles the order."
]
]
diff --git a/site/science/ch10/index.html b/site/science/ch10/index.html
index 2542792..4649794 100644
--- a/site/science/ch10/index.html
+++ b/site/science/ch10/index.html
@@ -438,6 +438,8 @@ const BEATS = [
T(big, 'acceleration', { x: 560, y: 470, size: 64, weight: 700, fill: ACC, anchor: 'end' }); T(big, '=', { x: 640, y: 470, size: 64, weight: 700, anchor: 'middle' });
T(big, 'net force', { x: 900, y: 420, size: 60, weight: 700, fill: FORCE, anchor: 'middle' }); mk('rect', { x: 720, y: 446, width: 360, height: 6, fill: COL.chalk }, big);
T(big, 'mass', { x: 900, y: 520, size: 60, weight: 700, anchor: 'middle' });
+ const name = T(p, "Newton's second law", { x: 800, y: 300, size: 44, weight: 700, fill: COL.dim, anchor: 'middle', o: 0 }); // on screen while the narration names the law
+ show(name, .1); hide(name, tm - .8, .4);
show(big, tl); hide(big, tm - .8, .4);
show(runs(p, [['acceleration', ACC], [' = ', COL.chalk], ['net force', FORCE], [' ÷ mass', COL.chalk]], { x: 800, y: 110, size: 44, weight: 700 }), tm - .5);
show(runs(p, [['net force', FORCE], [' = mass × ', COL.chalk], ['acceleration', ACC]], { x: 800, y: 170, size: 40, weight: 700 }), m('rearr'));