Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9bbc68e
Default voiceovers as one MP3 a view: Japan's script, the sound tools…
claude Nov 28, 2026
5ebda20
Scripts for default voiceovers can be written through the function wi…
claude Nov 28, 2026
a9d95ce
Default voiceover scripts for the other 229 wiki views
claude Nov 28, 2026
9b70c85
tools/voice/all.mjs: make and upload every voiceover not yet in the s…
claude Nov 28, 2026
e29f6ec
Voiceover timings for the views made so far
claude Nov 28, 2026
de67dd6
Voiceover timings for the views made so far
claude Nov 28, 2026
0f9048c
tools/voice: one script for a Mac (mac.sh) that makes every voiceover…
claude Nov 28, 2026
cc1d8e1
Voiceover timings for the views made so far
claude Nov 28, 2026
29589ef
mac.sh: update an existing copy, say which step failed
claude Nov 28, 2026
795bba8
Take the Mac script out of the repository
claude Nov 28, 2026
f5b3c13
Voiceover timings for every wiki view, from the store
claude Nov 28, 2026
edbe016
A wiki view's default voiceover is told as it is: no rewrite or other…
claude Nov 28, 2026
b2b8c0d
Music under the voiceover a little quieter
claude Nov 28, 2026
6223615
AGENTS.md: note the music level history
claude Nov 28, 2026
573fcde
Music under the voiceover at the usual background level
claude Nov 28, 2026
e9e3c93
Voiceover: set off for the next card as a line ends, so lines follow …
claude Nov 28, 2026
c257b7e
Voiceover: allow for play easing up to speed when setting off early
claude Nov 28, 2026
ab3a3d0
Voiceover: about a second between lines; the marker of the time line …
claude Nov 28, 2026
c13ca0c
Time line: marker exactly on the dot, as measured
claude Nov 28, 2026
ca590d8
Pressing an entry on the time line during play glides there and play …
claude Nov 28, 2026
a1f50a4
Export: take a wiki view's voiceover from its one file
claude Nov 28, 2026
749512b
Voice follows a press or drag on the time line during play
claude Nov 28, 2026
f803e41
Time line: entries to come keep their dot, only the name waits
claude Nov 28, 2026
9ca1118
Published timelines get their voiceover as one MP3 on the server
claude Nov 28, 2026
954d8ae
Keep the merged branch's history (squashed into main as #47)
claude Nov 28, 2026
13fd953
Free accounts: 10 published timelines at once, 50,000 voice character…
claude Nov 28, 2026
723d68e
Limits on the account's row: publish_max and voice_monthly, set by plan
claude Nov 28, 2026
f7a643f
Write the years on the time line in full, and name the entries' own y…
claude Nov 28, 2026
ed74de6
Stand the time line's marker exactly on each dot
claude Nov 28, 2026
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
19 changes: 11 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,17 @@ How the page is put together:
devices". The two are plain modes: online the server says the lines, offline this computer makes
them and the server is not asked (`line()` in `site/voice.js`); the switch says which is on and whether the
model is downloaded, and the download's progress and the GPU voice stand inside it. The GPU voice shows only with offline mode on. Server video export is planned, not built.
- **The voice's sound is kept in Cloudflare R2 (Nov 2026, asked for: "the users ones also goes to the
Cloudflare", and what is heard often is served from its cache; this replaces "never on the server" above for
the server voice).** One file a line, named by the voice and a hash of the words (`storeKey()` in
`site/voice.js` and in the function `voiceover`; change the two together), so a line is made and paid for once,
whoever asks. The function looks in the store before it counts a line against the account, and writes what it
makes. The page asks the store's public address first (`STORE` in `site/voice.js`, `fromStore()`; empty until
the bucket has one), which needs no sign-in, and gives up after `STORE_MISSES` misses in a row. Voiceovers for
the built views are to be made into the same store. Without the function's R2 secrets nothing is kept.
- **A voiceover is one file in Cloudflare R2 (Nov 2026, asked for: a wiki view and a published timeline alike,
"for consistency"; per-line files were found "complicated" and were dropped).** A wiki view's file is made by
`tools/voice/` and kept at `views/wiki/<view>/<voice>/<v>.mp3`. A published timeline's is made by the
function `voiceover` (`{ record: { id } }`): every line is said by the server voice as an MP3, side by side, and
the lines are joined frame by frame with `GAP` seconds of silence between them (`joinMp3()` in
`supabase/functions/voiceover/mp3.js`, nothing encoded again), kept at `views/<username>/<slug>/<voice>/<v>.mp3`
with its words and cues in the same table as the wiki's. The page asks for it when the timeline is published
and when a published timeline's voiceover changes (`voiceFile()` in `site/account.js`), and keeps the answer
on the row as `voice.audio`, so every reader plays from that one file (`STORE`, `fileOf()` in `site/voice.js`).
An unpublished timeline's voice stays on the reader's device: taking a timeline down deletes its file. Lines on
their own are not kept on the server. Without the function's R2 secrets nothing is kept.
- **The voice dialog is design A, "Two tabs" (Nov 2026, picked from three after the pill and box were found "too
noisy"; this replaces what the points above say about the voice dialogs).** `voiceMenu()` draws one column
(`.vo-form.vx`): the title, Online and Offline as two tabs (`.vo-tabs`, hidden on a phone), the voice as one
Expand Down
17 changes: 16 additions & 1 deletion docs/ACCOUNTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,23 @@ the function `voiceover` (`{ speak }`). There is nothing to download, so it star
works on a phone. Nothing is stored on the server: the sound goes to the reader's browser, which
keeps each line (`server()` in `site/voice.js`, `speak()` in `site/account.js`).

**A published timeline's voiceover is one file.** When a timeline with a voiceover is published, or its
voiceover changes while it is published, the function `voiceover` (`{ record: { id } }`) has every line said
as an MP3, side by side, joins them into one file with a short silence between lines, and keeps it in the
public store at `views/<username>/<slug>/<voice>/<v>.mp3`, the same shape as a wiki view's. Where each line
starts goes on the row (`voice.audio`), so every reader plays the one file. The same words in the same voice
are made once; the characters count against the owner's month. Taking the timeline down deletes the file: an
unpublished timeline's voice stays on the reader's device.

**An account's limits are on its own row**, so each can be changed without new code, for every account by
plan (`stripe-webhook` writes them) or for one account by hand: `ai_daily` (AI requests a day: 20 free, 200
pro), `publish_max` (timelines published at once: 10 free, 1,000 pro; the database refuses one more, and the
publish dialog says to make one private or delete one first) and `voice_monthly` (characters of the server
voice a month: 5,000 free, 500,000 pro). The real guarantee on the bill is the spending limit on the voice's
own OpenRouter key (`VOICE_API_KEY`): whatever the accounts do, it stops there.

Every signed-in account has a share of it a month, counted in characters by the server: a taste
for a free account (30,000, about half an hour of speech) and far more for pro (500,000, about
for a free account (5,000, about five minutes of speech, half a cent, so even a thousand free accounts cost at most about $5 a month) and far more for pro (500,000, about
nine hours). The account menu shows what is left. When the share is used up, and for a reader who
is not signed in, the browser's own voice says the lines.

Expand Down
36 changes: 32 additions & 4 deletions site/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const PHONE = '(max-width: 699px)';
const KEY = 'cg-session', FOLD = 'cg-sb', INTENT = 'cg-intent', MODEL = 'cg-model', PROMPT = 'cg-prompt', FAILED = 'cg-ai-failed';
// An account's share of the server voice a month, in characters (the function `voiceover` holds the same
// numbers and is the one that counts), and about how many characters make a minute of speech.
export const SPEECH = { free: 30000, pro: 500000 }, CHARS_A_MINUTE = 900;
export const SPEECH = { free: 5000, pro: 500000 }, CHARS_A_MINUTE = 900;
const AI_PER_DAY = 20; // the allowance until the account's row is read (`profiles.ai_daily`)

/* `app` is what the page lends: $, esc, views() (ids on the road), view(id),
Expand Down Expand Up @@ -128,7 +128,7 @@ export function createAccount(app) {
async function refreshList() {
if (!user) return;
const [p, l] = await Promise.all([
api(`/rest/v1/profiles?id=eq.${user.id}&select=username,ai_daily,plan`),
api(`/rest/v1/profiles?id=eq.${user.id}&select=username,ai_daily,plan,voice_monthly`),
api(`/rest/v1/timelines?owner=eq.${user.id}&select=id,slug,title,visibility,entries,updated_at&order=updated_at.desc`),
]);
profile = p[0] || { username: null };
Expand Down Expand Up @@ -259,13 +259,36 @@ export function createAccount(app) {
} catch (e) { a.fail(e.message); }
}
async function patch(row, body) {
const said = (t) => { const v = t && JSON.parse(t).voice; return v ? JSON.stringify([v.voice, v.lines]) : ''; }, before = said(row.text);
const got = await api(`/rest/v1/timelines?id=eq.${row.id}&select=id,slug,title,description,visibility,entries,updated_at`, { method: 'PATCH', headers: { Prefer: 'return=representation' }, body });
if (!got[0]) throw new Error('That timeline is no longer there.');
Object.assign(row, got[0]);
if (body.data) row.text = JSON.stringify(body.data);
app.replace(payloadOf(row));
if (editor.row() === row) editor.reload();
await refreshList();
// Published, or taken down, or its voiceover changed while published: the one file on the server follows.
if (body.visibility || (body.data && row.visibility !== 'private' && said(row.text) !== before)) voiceFile(row);
}
// A published timeline's voiceover is one MP3 made on the server, kept under the username like a wiki view's
// (asked for, Nov 2026); a private one keeps its voice on this device only, and the server deletes its file.
// The answer (`audio`: where the file is and where each line starts) goes on the row, so every reader plays
// from that one file. Nothing waits for it: until it is there, the lines are said one by one as before.
const filing = new Map();
function voiceFile(row) {
if (filing.get(row.id)) return filing.get(row.id).again = true;
const job = { again: false };
filing.set(row.id, job);
voiceFn({ record: { id: row.id } }).then(async (d) => {
const data = JSON.parse(row.text), v = data.voice, had = JSON.stringify(v?.audio || null);
if (!v || had === JSON.stringify(d.audio || null)) return;
if (d.audio && (d.audio.voice !== v.voice || d.audio.cues.length !== v.lines.length)) return;
if (d.audio) v.audio = d.audio; else delete v.audio;
await api(`/rest/v1/timelines?id=eq.${row.id}`, { method: 'PATCH', body: { data } });
row.text = JSON.stringify(data);
app.replace(payloadOf(row));
}).catch((x) => { if (row.visibility !== 'private') toast('The voiceover file could not be made: ' + x.message); })
.finally(() => { filing.delete(row.id); if (job.again) voiceFile(row); });
}
async function ensureRow(uuid) { if (!rows.has(uuid)) await fetchView('t/' + uuid); return rows.get(uuid); }
async function rawEntry(id) {
Expand Down Expand Up @@ -624,7 +647,12 @@ export function createAccount(app) {
// other single view, this browser (asked for, Nov 2026: Generate voiceover on the existing views too).
function holder() {
const cur = current();
if (cur) return { own: true, title: cur.title, description: cur.description || '', get: () => JSON.parse(cur.text).voice, set: (v) => { const data = JSON.parse(cur.text); if (v) data.voice = v; else delete data.voice; return patch(cur, { data }); } };
if (cur) return { own: true, title: cur.title, description: cur.description || '', get: () => JSON.parse(cur.text).voice, set: (v) => {
// The file of the voice before is kept only while the voice and its words are the same.
const data = JSON.parse(cur.text), was = data.voice;
if (v) { data.voice = { ...v }; delete data.voice.audio; if (was?.audio && was.voice === v.voice && JSON.stringify(was.lines) === JSON.stringify(v.lines)) data.voice.audio = was.audio; } else delete data.voice;
return patch(cur, { data });
} };
const o = app.one();
// `fixed`: a built view's default voiceover, which is told as it is (Make it your own to change it).
return o ? { own: false, fixed: !!o.voice?.base, title: o.title, description: o.description, get: () => app.one()?.voice, set: async (v) => app.keepVoice(v) } : null;
Expand Down Expand Up @@ -1366,7 +1394,7 @@ export function createAccount(app) {
// the characters said; `SPEECH` here only says how large the share is, to draw it).
api(`/rest/v1/speech_use?select=chars&month=eq.${new Date().toISOString().slice(0, 7)}-01`).then((got) => {
const box = d.querySelector('#me-say'); if (!box) return;
const most = SPEECH[isPro() ? 'pro' : 'free'], left = Math.max(0, most - (got?.[0]?.chars || 0));
const most = Number(profile?.voice_monthly) || SPEECH[isPro() ? 'pro' : 'free'], left = Math.max(0, most - (got?.[0]?.chars || 0));
box.querySelector('span').textContent = `${Math.round(left / CHARS_A_MINUTE).toLocaleString('en-US')} of ${Math.round(most / CHARS_A_MINUTE).toLocaleString('en-US')} min left`;
box.querySelector('u').style.width = (100 * left / most) + '%';
box.classList.toggle('none', !left);
Expand Down
21 changes: 14 additions & 7 deletions site/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
let RANKED = false, AX = null;
const axisKey = (v) => (v?.axis === 'scale' ? 'scale:' + v.id : v?.axis === 'rank' ? 'rank' : 'time');
const isRanked = () => state.views.length > 0 && axisKey(viewById.get(state.views[0])) !== 'time';
function yearText(y) {
function yearText(y, short = false) {
if (RANKED) return axisLabel(AX, y);
if (y > 0) return y < 1000 ? y + ' CE' : String(y);
const a = -y;
if (a < 10000) return a + ' BCE';
if (a < 1e5) return group(sig(a)) + ' BCE';
// on a phone the deep-time words are short: 100k, 66M, 13.8B years ago (asked for, Nov 2026)
const ph = matchMedia(PHONE).matches;
const ph = short || matchMedia(PHONE).matches;
if (a < 1e6) return (ph ? sig(a / 1e3) + 'k' : group(sig(a))) + ' years ago';
if (a < 1e9) return sig(a / 1e6) + (ph ? 'M' : ' million') + ' years ago';
return sig(a / 1e9) + (ph ? 'B' : ' billion') + ' years ago';
Expand Down Expand Up @@ -705,7 +705,10 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
}
// A step of a plan with no end that starts after today still stands where it starts.
const inSpan = (t) => (t.lead ?? t.born) < tMax && Math.max(t.end ?? NOW, t.born) >= tMin;
return { selected, groupsOf, rowsOf, all, fitMin, fitMax, autoMin, tMin, tMax, inSpan };
// The first start and the last date of the entries in sight, for the year pill.
const seen = all.filter(inSpan), first = seen.length ? Math.min(...seen.map((t) => t.born)) : null;
const lastIn = seen.length ? Math.max(...seen.map((t) => Math.max(t.end ?? NOW, t.born))) : null;
return { selected, groupsOf, rowsOf, all, fitMin, fitMax, autoMin, tMin, tMax, inSpan, first, lastIn };
}
// ---------------------------------------------------------------- render
function render() {
Expand Down Expand Up @@ -802,7 +805,7 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
const camAtEnd = () => { const [lo, hi] = camLimits(); return camDir() > 0 ? road.t >= hi - L.D * 0.01 : road.t <= lo + L.D * 0.01; };

function roadLayout() {
const { selected, groupsOf, rowsOf, all, fitMin, fitMax, autoMin, tMin, tMax, inSpan } = chosen();
const { selected, groupsOf, rowsOf, all, fitMin, fitMax, autoMin, tMin, tMax, inSpan, first, lastIn } = chosen();
const box = $('road'), G = stageOf(box.clientWidth, box.clientHeight, TOP, ($('axisbar')?.offsetWidth || 0) / 2);
$('road-views').style.left = G.vx + 'px';
const lanes = [];
Expand Down Expand Up @@ -846,7 +849,7 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
const own = state.views.some((id) => viewById.get(id)?.stored) || shown.filter((p) => wallMedia(p.t).length).length >= Math.max(3, 0.15 * shown.length);
// The latest start on the road: turned round, the reader opens just before it, even when it stands close to the end.
const lastA = shown.reduce((m, p) => (p.a <= tMax && p.a > m ? p.a : m), -Infinity);
L = { eps: Math.min(0.01, (tMax - tMin) / 2000), own, tMin, tMax, lastA, fitMin, fitMax, autoMin, shown, groups, total: groupsOf.size, D, G, lanes, place, when,
L = { eps: Math.min(0.01, (tMax - tMin) / 2000), own, first, last: lastIn, tMin, tMax, lastA, fitMin, fitMax, autoMin, shown, groups, total: groupsOf.size, D, G, lanes, place, when,
at: new Map([...shown].reverse().map((p) => [p.t.id, p])), byKey: new Map(shown.map((p) => [p.key, p])), barH: $('axis').clientHeight };
return L;
}
Expand Down Expand Up @@ -989,7 +992,7 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
const t = p.t, P = roadPalette();
return { id: t.id, name: t.name, kind: t.cat.short || t.cat.name, when: spanOf(t), summary: t.summary || '', img: t.image && !t.noImage ? mediaUrl(t.image.src) : '',
imgs: t.image && !t.noImage ? [t.image, ...(t.media || []).filter((m) => m && m.src && (!m.type || m.type === 'image'))].map((m) => mediaUrl(m.src)).filter((u, i, a) => a.indexOf(u) === i).slice(0, 4) : [],
mark: shortYear(writtenOf(t.born)), col: colVar(p.lane.col), rgb: `rgb(${colRgb(P, p.lane.col).join(',')})`, place: t.where ? [t.where[0], t.where[1], 'city', ''] : !RANKED && t.born > DEEP ? places[t.id] || null : null };
mark: RANKED ? shortYear(writtenOf(t.born)) : yearText(writtenOf(t.born), true), col: colVar(p.lane.col), rgb: `rgb(${colRgb(P, p.lane.col).join(',')})`, place: t.where ? [t.where[0], t.where[1], 'city', ''] : !RANKED && t.born > DEEP ? places[t.id] || null : null };
}
function globeShow() {
if (!globe) {
Expand Down Expand Up @@ -1981,7 +1984,11 @@ import { NEAR, GONE, FAR, FINE, calMarks, dayText, sizeAt, warp, focalYears, tra
if (document.activeElement !== $('y-from')) $('y-from').value = pos(lo);
if (document.activeElement !== $('y-to')) $('y-to').value = pos(hi);
const last = hi >= NOW - 0.5 ? 'today' : yearText(writtenOf(hi - 1e-9));
$('years-out').textContent = `${yearText(writtenOf(lo))} – ${last}`;
// The pill names the years of the entries themselves, not the room the road leaves before the first
// (Japan read "801 BCE" for a first entry of 660 BCE); a range the reader narrowed is named as chosen.
const said = (t) => yearText(writtenOf(t));
const out = !L || state.span ? [said(lo), last] : [said(Math.max(lo, L.first ?? lo)), L.last != null && L.last < hi && L.last < NOW - 0.5 ? said(L.last) : last];
$('years-out').textContent = `${out[0]} – ${out[1]}`;
$('y-from').setAttribute('aria-valuetext', yearText(writtenOf(lo)));
$('y-to').setAttribute('aria-valuetext', last);
// Reset a narrowed range; or, when the timeline opened on its busy part, reach back to the first entry.
Expand Down
6 changes: 4 additions & 2 deletions site/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ export function painter(cv, { title, steps, scenes, fonts, subsOf, globe }) {
c.font = font(!s.place && globe);
const nm = s.name.length > 36 ? s.name.slice(0, 34) + '…' : s.name, w = px(18) + c.measureText(nm).width;
const o = { x, nm, w, yr: s.mark && s.mark !== said ? s.mark : '', it: !s.place && globe }; if (o.yr) said = s.mark;
x += w + gap; return o;
// A year wider than its name keeps the next name clear of it, as on the page.
if (o.yr) { c.font = `500 ${ys}px ${sans}`; o.w = Math.max(o.w, c.measureText(o.yr).width + px(6)); }
x += o.w + gap; return o;
});
}
// As on the page: the marker stands on the dot of the entry in front, what has passed at its
// left, and what is still to come shows only its dot until its turn (asked for, Nov 2026).
const pos = posAt(scenes, t), k = Math.min(strip.length - 1, Math.max(0, Math.floor(pos))), nx = strip[k + 1];
const at = pos < 0 ? strip[0].x + px(40) * pos : nx ? strip[k].x + (nx.x - strip[k].x) * (pos - k) : strip[k].x;
const at = pos < 0 ? strip[0].x : nx ? strip[k].x + (nx.x - strip[k].x) * (pos - k) : strip[k].x;
const xm = x1 - px(lay.wide ? 380 : 300), off = xm - px(5) - at, acc = steps[now].rgb || '#e8b04a';
c.save(); c.textBaseline = 'alphabetic'; c.textAlign = 'left';
strip.forEach((o, n) => {
Expand Down
Loading
Loading