diff --git a/AGENTS.md b/AGENTS.md index 268e0bcd..dff6385f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -453,6 +453,12 @@ How the page is put together: Delete; rewriting it or choosing another voice makes the reader's own copy. It downloads no model until play is pressed. `scripts/voices.mjs` writes these files with the function's own instructions (needs `OPENROUTER_API_KEY`); the first, Dinosaurs, was written by hand as a sample. +- **A phone never loads the voice model (Nov 2026, asked for, after the page crashed on a phone: "avoid those + heavy gpu usage and voiceover downloads for phone").** On a phone or a tablet (`light()` in `site/voice.js`: + what `isMobile()` names, or a screen worked by touch alone) Offline is never offered and `offlineOn()` is + always no, so the model is never fetched and `warm()` does nothing; `gpuOk()` answers no without asking for the + graphics card and the GPU voice is not offered. A voiceover there is said by the server voice, or a view's own + MP3, else by the device's own voice. - **Stopping an export is asked once more (Nov 2026, asked for).** In the export dialog Stop turns the foot into "Stop the export?" with "Yes, stop" and "Keep exporting"; from the note under the pill it is a small dialog. The export goes on until the reader answers. diff --git a/site/account.js b/site/account.js index 9ce0fb6a..37c3b53b 100644 --- a/site/account.js +++ b/site/account.js @@ -10,7 +10,7 @@ import { EFFORTS, MAX_ENTRIES, MODELS, findPictures, partialSpec, specToView, vi import { createEditor } from './editor.js'; // Public by design: the key only allows what the database's row level security allows. -import { VOICES, DEFAULT_VOICE, isVoice, voiceLabel, voiceOf, isSlow, gpuOk, GPU_MB, MODEL_MB, isMobile, offlineOn, listen as hear } from './voice.js'; +import { VOICES, DEFAULT_VOICE, isVoice, voiceLabel, voiceOf, isSlow, gpuOk, GPU_MB, MODEL_MB, light, offlineOn, listen as hear } from './voice.js'; export const CONFIG = { url: 'https://wwgmelafchslapxiccot.supabase.co', key: 'sb_publishable_IykysSfgNLw4CfaqxP2CqA_YNcfq0SW', @@ -166,7 +166,7 @@ export function createAccount(app) { // may turn on Offline voice, which downloads the model and makes the voice there. let spent = false, plainSaid = false; const hasSpeak = () => !!user && !spent; - const offlineHint = () => (isMobile() ? '' : ' Or switch the voice to Offline where you choose it.'); + const offlineHint = () => (light() ? '' : ' Or switch the voice to Offline where you choose it.'); function plainVoice() { if (plainSaid) return; plainSaid = true; if (!user) toast('This is your browser’s own voice. Sign in to hear the full voice.' + offlineHint()); @@ -955,7 +955,7 @@ export function createAccount(app) { const HAVE = 'cg-voice-have', have = () => { try { return localStorage.getItem(HAVE) === '1'; } catch (e) { return false; } }; let getting = false; const drawMode = () => { - const on = offlineOn(), ok = !isMobile(), v = pick(), [, name, w] = VOICES.find(([id]) => id === v) || VOICES[0]; + const on = offlineOn(), ok = !light(), v = pick(), [, name, w] = VOICES.find(([id]) => id === v) || VOICES[0]; tabsEl.hidden = !ok; tabsEl.querySelectorAll('[data-mode]').forEach((b) => b.setAttribute('aria-selected', String((b.dataset.mode === 'off') === on))); if (sp.ready() && !have()) { try { localStorage.setItem(HAVE, '1'); } catch (e) {} } @@ -977,7 +977,7 @@ export function createAccount(app) { const drawPick = () => { drawMode(); gp.hidden = !gpuFine || !kokoro() || !offlineOn(); drawGpu(); if (kokoro() && offlineOn() && (have() || getting)) sp.warm(); }; tabsEl.addEventListener('click', (e) => { const b = e.target.closest('[data-mode]'); if (!b) return; e.preventDefault(); sp.offline(b.dataset.mode === 'off'); drawPick(); }); mode.querySelector('[data-get]').addEventListener('click', (e) => { e.preventDefault(); getting = true; sp.warm(); drawPick(); }); - gpuOk().then((ok) => { gpuFine = ok && !isMobile(); drawPick(); }); + gpuOk().then((ok) => { gpuFine = ok && !light(); drawPick(); }); gp.querySelector('button').addEventListener('click', () => { getting = true; sp.engine(!sp.gpu()); drawGpu(); drawSlow(); sp.warm(); }); d.addEventListener('change', (e) => { if (e.target.name === 'voice') drawPick(); }); const ld = d.querySelector('.vo-load'), tick = setInterval(() => { diff --git a/site/voice.js b/site/voice.js index 70810e27..250410f4 100644 --- a/site/voice.js +++ b/site/voice.js @@ -42,12 +42,12 @@ export function speedOf(gpu = gpuOn()) { try { const v = Number(localStorage.get // download, only when the user clicks download"). If it fails to load, the voice goes back to the processor. export const GPU_MB = 326; const GPU = 'cg-voice-gpu'; -export function gpuOn() { try { return localStorage.getItem(GPU) === '1'; } catch (e) { return false; } } +export function gpuOn() { try { return !light() && localStorage.getItem(GPU) === '1'; } catch (e) { return false; } } let gpuAsk = null; export function gpuOk() { return (gpuAsk ??= (async () => { try { - if (typeof navigator === 'undefined' || !navigator.gpu) return false; + if (typeof navigator === 'undefined' || !navigator.gpu || light()) return false; const a = await navigator.gpu.requestAdapter({ powerPreference: 'high-performance' }); return !!a && !(a.isFallbackAdapter || a.info?.isFallbackAdapter); } catch (e) { return false; } @@ -62,7 +62,15 @@ export function isMobile(n = typeof navigator === 'undefined' ? null : navigator if (!n) return false; return !!n.userAgentData?.mobile || /Android|iPhone|iPad|iPod|Mobile/i.test(n.userAgent || '') || (/Mac/i.test(n.platform || '') && n.maxTouchPoints > 1); } -export function offlineOn() { try { return !isMobile() && localStorage.getItem(OFFLINE) === '1'; } catch (e) { return false; } } +// A phone or a tablet never loads the model and never asks for the graphics card (asked for, Nov 2026, after the +// page crashed on a phone: "avoid those heavy gpu usage and voiceover downloads for phone"). `light()` is a +// device `isMobile()` names, or a screen worked by touch alone; there the voice is the server's (or a view's own +// file), else the device's own, and Offline and the GPU voice are never offered. +export function light() { + if (isMobile()) return true; + try { return typeof matchMedia === 'function' && matchMedia('(hover: none) and (pointer: coarse)').matches; } catch (e) { return false; } +} +export function offlineOn() { try { return !light() && localStorage.getItem(OFFLINE) === '1'; } catch (e) { return false; } } export const isSlow = (r = speedOf()) => r != null && r > SLOW; export const isVoice = (v) => VOICES.some(([id]) => id === v); @@ -251,7 +259,7 @@ export function createSpeaker(status = () => {}) { } // Have the model ready before anything is said: when a timeline with a voiceover is opened. let warmed = false; - function warm() { if (warmed || booted || has() || !offlineOn()) return; warmed = true; boot(); worker.postMessage({ id: 0 }); } + function warm() { if (warmed || booted || has() || !offlineOn() || light()) return; warmed = true; boot(); worker.postMessage({ id: 0 }); } // Change between the processor and the graphics card: the worker starts again on the other model; lines // waiting to be made are made by it. `failed` is set when the graphics card could not load it. function engine(on, failed = false) {