diff --git a/docs/expo/PODCASTS-EXPLORATORY-SPEC.md b/docs/expo/PODCASTS-EXPLORATORY-SPEC.md new file mode 100644 index 0000000000..9c18f58c4c --- /dev/null +++ b/docs/expo/PODCASTS-EXPLORATORY-SPEC.md @@ -0,0 +1,3056 @@ +# Podcasts + MOSS ASR exploratory implementation spec + +Status: exploratory handoff draft for revision by the next worker. This document intentionally changes no production code. + +Reviewed source: `feat/expo-android-web-migration` through `242f01f4b594be17746bfc6dce9a6fd47142eabf` on 2026-10-03. Media/MOSS internals underlying this review did not change across the latest nine Expo commits; those commits continued Library/native-library/browser interaction and CI qualification work. The Library section-navigation surface and Android secure DOM host were rechecked at this head. + +Target product direction: add a Podcasts category focused first on Japanese native-immersion listening, using original publisher podcast enclosures directly in the client and reusing the existing local MOSS transcription stack. No audio proxy or Manabi audio rehosting is proposed. + +## 1. Executive recommendation + +Do not implement Podcasts as an unrelated player or as a renamed copy of Videos. + +The current branch already has most of the expensive media/transcription domain work below the video-specific UI: + +- bounded random-access media reads +- Mediabunny parsing and audio decode +- 16 kHz mono PCM production +- MOSS Worker/model lifetime +- sparse/playhead-prioritized transcription +- durable in-progress jobs and audio proofs +- caption tracks and paging +- transcript study behavior +- local media search +- cancellation, account lifetime, cross-tab MOSS serialization, and model cleanup + +The recommended architecture is therefore: + +~~~text +curated podcast catalog / RSS metadata + | + v +qualified original enclosure URL + | + +------> browser audio playback + | + v +remote HTTP ByteSource + | + v +Mediabunny / MediaPipeline + | + v +bounded 16 kHz mono PCM windows + | + v +existing TranscriptionQueue + MossClient + | + v +existing Cue / Track transcript domain + | + v +podcast-specific player shell + shared transcript/study presentation +~~~ + +The first implementation should be deliberately narrow: + +1. Japanese-language curated catalog. +2. Prefer a publisher transcript (`podcast:transcript`) when one is present, readable, and valid; enable timed follow/replay only when its timeline is qualified for the delivered rendition. +3. Only enable MOSS for episodes whose selected publisher-declared media source is browser-readable, range-capable, decodable, and sufficiently byte-stable for one admitted rendition session. +4. No proxy fallback. +5. No automatic transcription. +6. No automatic 648 MB MOSS model download. +7. Playback is immediate. +8. Local MOSS captions are explicit and use a new bounded `playback-lead` scheduler built on the existing sparse window/seam format; whole-episode completion is never the hidden default. +9. Do not overload RSS GUIDs or enclosure URLs as existing ContentKey values. +10. Do not redesign the synced video record protocol in the first implementation. +11. Treat native Android presentation as gated by the same domain/view separation still required for Videos on the Expo branch. +12. Treat intra-session rendition mismatch as a hard timed-MOSS failure. A host that is coherent within one session but changes on reopen may still support session-bound local captions; do not paper over either case with weak identity. + +The largest implementation risk is not only MOSS accuracy. It is keeping logical episode identity, delivered rendition identity, transcript timeline, and exact byte identity separate while avoiding unbounded CPU/network work. The current video system correctly treats ContentKey as a full-byte SHA-256 identity. Podcast media can be large, redirect through analytics/ad infrastructure, and may be dynamically personalized. That must remain explicit. + +## 2. What was reviewed on the Expo branch + +### 2.1 Expo route state + +The Expo branch currently has: + +- apps/web/src/app/videos.tsx -> screens/routes/videos +- apps/web/src/screens/routes/videos.web.tsx -> media-react VideosScreen +- apps/web/src/screens/routes/videos.tsx -> native placeholder saying the Android migration is still in progress +- apps/web/src/routes/videos/+page.svelte -> retained Svelte reference/route implementation +- apps/web/src/media-react/index.tsx -> React web host that still mounts the framework-neutral DOM VideoWorkspace + +This means Videos is not yet a shared Android/web feature presentation. + +The branch's own docs are explicit about this: + +- docs/expo/SHARED-UI-CONVERGENCE.md says optional video requires domain/view separation before it counts as shared. +- docs/expo/FIDELITY-MATRIX.md marks optional video shared presentation/native player layout incomplete. +- docs/expo/MIGRATION.md keeps media/moss-worker.ts inside the DOM/browser graph when video learning is enabled. + +Podcasts should not make this migration harder by adding another large web-only state machine. + +### 2.2 Library/category navigation + +The current React LibraryTabs in apps/web/src/library-react/navigation.tsx is a small Books / Videos section switcher. The Svelte reference in apps/web/src/lib/media/library-tabs.svelte has the same two destinations. + +A Podcasts category fits naturally here: + +~~~text +Books | Videos | Podcasts +~~~ + +It does not need to become a top-level AppNav destination in the first version. It is conceptually another library/listening surface, like Videos. + +The current Books screen only shows the section switcher when videoLearningEnabled is true. Podcasts should have a separate experimental feature flag initially rather than being silently coupled to the video flag. + +Suggested flag: + +~~~text +EXPO_PUBLIC_ENABLE_PODCASTS=true +~~~ + +The shared section switcher should render the enabled categories based on capabilities. Do not create separate contradictory tab definitions for Svelte, React web, and native long-term; the Expo migration direction is one shared composition with bounded platform leaves. + +There is already duplication to remove: + +- React `LibraryTabs()` renders Books / Videos and hardcodes Books as current +- `VideoWorkspace` constructs a separate DOM Books / Videos nav and marks Videos current +- the retained Svelte reference has its own tab markup + +Do **not** add a fourth Podcasts-specific switcher. Extract one host-owned section-navigation model/view with an explicit current category and enabled categories. VideoWorkspace should no longer own site/library navigation as part of its eventual domain/view split. + +### 2.3 Existing media source seam is already useful + +apps/web/src/lib/media/sources.ts defines ByteSource: + +~~~ts +interface ByteSource { + name: string + size: number + version: string + file?: File + cloud?: CloudLocator + isCurrent?(): boolean + + read( + start: number, + end: number, + signal: AbortSignal + ): Promise + + playback(): { + url: string + release(): void + } +} +~~~ + +The important point is that the rest of the decode pipeline does not fundamentally require a local video File. + +apps/web/src/lib/manabi/media-runtime.ts already adapts a non-File ByteSource to Mediabunny CustomSource using streamedRange(), bounded caching, and the network prefetch profile. + +A podcast enclosure can therefore become another ByteSource implementation rather than another decode stack. + +### 2.4 MediaPipeline is mostly audio/media generic already + +apps/web/src/lib/media/pipeline.ts already: + +- discovers audio tracks +- validates track metadata +- supports audio-only inputs because getPrimaryVideoTrack() may return null +- computes duration +- decodes bounded windows of at most 64 seconds +- validates packet/memory budgets +- uses OfflineAudioContext to resample/downmix to mono 16 kHz PCM + +That output is exactly what the current MOSS queue consumes. + +Do not create a podcast-specific MP3 decoder unless qualification exposes a real Mediabunny gap. + +### 2.5 Existing MOSS pipeline is reusable + +The current video stack already has the right product behavior for long podcast audio: + +- MossClient creates one owned Worker and lazily prepares the model. +- First opening media does not install the model. +- Generate is explicit. +- TranscriptionQueue serializes inference and owns durable jobs. +- navigator.locks coordinates MOSS across tabs where available. +- sparse/progressive policies use bounded decode windows. +- queue.prioritize(job.id, currentTime) can prioritize around the user's playhead. +- audioProofAsync records SHA-256 evidence over actual 16 kHz PCM windows that produced hypotheses. +- completed Track records carry MOSS provenance. +- model/runtime cleanup is explicit. +- search only uses already-published transcript data and does not start recognition. + +This should remain one transcription engine for video and podcasts. + +### 2.6 Current MOSS performance changes the podcast UX + +Do not design the initial Podcasts experience around "transcribe the whole 90-minute episode, then start studying." + +There are two different pieces of historical performance evidence in the media docs and neither qualifies current podcast throughput: + +- the older recovered Japanese smoke in `docs/moss-video-runtime-review.md` measured about **19.5x realtime threaded** on its short CI fixture +- the later base-v4 CPU qualification recorded in `docs/moss-progressive-transcription.md` improved the small generated-speech fixture to about **3.14x realtime threaded** and **5.7x single-threaded** + +The current v7 callback runtime has not been requalified there, those figures are not representative-device measurements, and natural Japanese/music/background-noise/long-form repair behavior remains explicitly unqualified. Even the better 3.14x figure is still slower than playback. + +This makes a podcast-specific scheduler distinction necessary. The existing v3 sparse policy is **playhead-prioritized but not playhead-bounded**: once a sparse job runs, `nextSparseWindow()` keeps selecting missing windows until the whole media item is covered. + +Do not reuse that behavior unchanged for long podcasts. + +The default podcast UX should be: + +~~~text +open episode +-> play immediately +-> use a valid publisher timed transcript if one is already available +-> otherwise user explicitly enables local MOSS captions +-> generate only the bounded caption lead needed around/after the current playhead +-> park inference when that lead is satisfied +-> resume bounded work as playback/seek approaches missing coverage +~~~ + +Whole-episode transcription must be a separate explicit policy/action, not the hidden consequence of "Generate transcript." It should not ship until representative devices establish acceptable time, power, thermal, memory and repair behavior. + +Do not claim background inference after the browser/WebView suspends or terminates the page. Background **playback** and background **MOSS inference** are separate capabilities. + +### 2.7 Existing Expo dependencies change the preferred implementation seam + +The Expo branch already depends on: + +- `expo-audio ~57.0.5` +- `fast-xml-parser 5.11.1` +- `dompurify 3.4.15` +- `mediabunny 1.59.1` + +Do not add another audio playback package or XML parser before evaluating these. + +`expo-audio` supports Android and web remote-URL playback and exposes shared play/pause/seek/rate/status APIs. Its web player also has an explicit `crossOrigin` option whose default is undefined/no CORS. That is useful because playback and ASR do not have to use the same request mode. + +The current Expo config explicitly sets: + +~~~ts +enableBackgroundPlayback: false +~~~ + +So background podcast playback is **not** an existing capability of this branch. Enabling it later is a separate native/config decision: Expo's Android path adds a foreground media-playback service, requires the audio mode to allow background playback, and requires active lock-screen controls for sustained background playback. Do not smuggle that permission/service change into the first podcast slice. + +`expo-audio` does **not** replace the MOSS byte path. ASR still needs the CORS-readable `ByteSource`/Mediabunny pipeline. + +For web, retaining a bounded DOM `