From 5219feab42734ff0d9eb1e35f9dec1ba738b6980 Mon Sep 17 00:00:00 2001 From: Joshua Cold Date: Fri, 6 Nov 2026 16:59:59 -0700 Subject: [PATCH 1/2] feat(listen): spoken summaries of pages, from a local LLM and Piper gA sends the page's article (found by reader's Readability) to Ollama for a short summary meant to be heard, has Piper read it into a clip, and saves it. :listen-library lists the clips to play, filter, open or delete. Co-Authored-By: Claude Opus 5.5 --- README.md | 1 + listen/README.md | 43 ++++++ listen/lua/listen/init.lua | 293 ++++++++++++++++++++++++++++++++++++ listen/pages/index.html | 28 ++++ listen/pages/library.js | 119 +++++++++++++++ listen/pages/style.css | 133 ++++++++++++++++ listen/plugin/listen.lua | 2 + listen/riptide-plugin.toml | 55 +++++++ listen/test/article.html | 21 +++ listen/test/bin/fake-curl | 12 ++ listen/test/bin/fake-piper | 12 ++ listen/test/config.lua | 13 ++ listen/test/empty.html | 3 + listen/test/listen_spec.lua | 72 +++++++++ 14 files changed, 807 insertions(+) create mode 100644 listen/README.md create mode 100644 listen/lua/listen/init.lua create mode 100644 listen/pages/index.html create mode 100644 listen/pages/library.js create mode 100644 listen/pages/style.css create mode 100644 listen/plugin/listen.lua create mode 100644 listen/riptide-plugin.toml create mode 100644 listen/test/article.html create mode 100755 listen/test/bin/fake-curl create mode 100755 listen/test/bin/fake-piper create mode 100644 listen/test/config.lua create mode 100644 listen/test/empty.html create mode 100644 listen/test/listen_spec.lua diff --git a/README.md b/README.md index 620e3b8..68a1748 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ them and checks for updates. | [flash](flash) | Jump to any text on screen by two of its characters | | [reader](reader) | Read a page's article alone, cleanly typeset | | [noice](noice) | A cleaner command line, questions, tabs and status bar | +| [listen](listen) | Hear a spoken summary of the page, from a local LLM and Piper | ## Writing one diff --git a/listen/README.md b/listen/README.md new file mode 100644 index 0000000..72dd551 --- /dev/null +++ b/listen/README.md @@ -0,0 +1,43 @@ +# listen + +Hear a spoken summary of the page you're on, written by a local LLM and read +aloud by [Piper](https://github.com/OHF-Voice/piper1-gpl), and keep the clips +to play later. + +`gA` (or `:listen`) finds the article with reader's Readability, asks +[Ollama](https://ollama.com) for a short summary meant to be heard, and has +Piper read it into a clip. It works in the background, so keep browsing; +a message says when the clip is ready. `:listen-library` lists your clips, +newest first, to play (at 0.75× to 2×), filter, read the summary, open the +page it came from, or delete. + +Nothing leaves your computer: the article goes to Ollama on `localhost`, and +the clips are saved in `~/.local/share/riptide/listen` (or the `dir` option). + +## Setup + +```sh +ollama pull llama3.2 +pipx install piper-tts +``` + +Then pick a voice from [piper-voices](https://huggingface.co/rhasspy/piper-voices) +and save its `.onnx` and `.onnx.json` side by side, e.g. in `~/.local/share/piper`. + +```lua +rt.pack.add({ "https://github.com/joshzcold/riptide-plugins", subdir = "listen", opts = { + voice = os.getenv("HOME") .. "/.local/share/piper/en_US-lessac-medium.onnx", + model = "llama3.2", -- any model you've pulled in Ollama + words = 150, -- about how long the summary is + -- ollama = "http://localhost:11434", + -- key = "gA", -- false for none +} }) +``` + +With [ffmpeg](https://ffmpeg.org) installed, clips are saved as Opus, about a +tenth the size of the WAV Piper writes. `:pack-health` checks for curl, piper, +the voice and ffmpeg. + +It brings [reader](../reader), for Readability. It asks to read the pages you +use it on, to run curl, piper and ffmpeg, and to read and delete the clips it +saved. Playing a clip needs a riptide newer than 0.17.0 (riptide#159). diff --git a/listen/lua/listen/init.lua b/listen/lua/listen/init.lua new file mode 100644 index 0000000..35e0e33 --- /dev/null +++ b/listen/lua/listen/init.lua @@ -0,0 +1,293 @@ +-- A spoken summary of the page you're on: Readability finds the article, a +-- local LLM in Ollama writes a summary meant to be heard, and Piper reads it +-- into a clip. :listen-library lists the clips and plays them. +local readability = require("reader.readability") + +local M = {} + +-- The programs it runs; the tests swap in fakes. +M.curl = "curl" + +-- Clips being made, newest last: { id, title, url, stage }. +M.pending = {} + +local opts = {} +local bound = {} +local store = rt.store() +local libraries = {} + +local MAX_CHARS = 20000 + +-- In the page: the article's title and text, or null if there's none. +local EXTRACT_JS = "(() => {\n" .. readability .. [[ + + const article = new Readability(document.cloneNode(true)).parse(); + if (!article || !article.textContent || (article.length ?? 0) < 200) return null; + return { + title: article.title || document.title, + site: article.siteName || location.hostname, + text: article.textContent.replace(/\s+/g, " ").trim().slice(0, ]] .. MAX_CHARS .. [[), + url: location.href, + }; +})()]] + +local PROMPT = [[Summarize this article as a short script to be read aloud, about %d words. +Write plain spoken sentences: no headings, lists, markdown, links or emoji. +Start with what it's about, not with "This article". + +Title: %s + +%s]] + +local function notify(text, level) rt.notify("listen: " .. text, level) end + +local function trim(s) return ((s or ""):gsub("^%s+", ""):gsub("%s+$", "")) end + +function M.dir() + if opts.dir and opts.dir ~= "" then return opts.dir end + local home = os.getenv("HOME") or "." + if rt.platform == "macos" then return home .. "/Library/Application Support/riptide/listen" end + if rt.platform == "windows" then return (os.getenv("LOCALAPPDATA") or home) .. "/riptide/listen" end + return (os.getenv("XDG_DATA_HOME") or (home .. "/.local/share")) .. "/riptide/listen" +end + +function M.clips() return store.get("clips") or {} end + +local function find(id) + for i, clip in ipairs(M.clips()) do + if clip.id == id then return clip, i end + end +end + +local function refresh() + local payload = { clips = M.clips(), pending = M.pending } + for _, page in ipairs(libraries) do pcall(page.send, page, "clips", payload) end +end + +local function program(name) + local given = opts[name] + if given and given ~= "" then return given end + return name +end + +-- The LLM's answer as plain sentences for Piper: no reasoning, no markdown. +function M.clean(text) + text = (text or ""):gsub(".-", ""):gsub("[*_#`]", "") + return trim(text) +end + +function M.summarize(article, callback) + local body = rt.json.encode({ + model = opts.model or "llama3.2", + prompt = PROMPT:format(tonumber(opts.words) or 150, article.title or "", article.text), + stream = false, + -- Ollama's default context would cut a long article short without saying so. + options = { num_ctx = 8192 }, + }) + local endpoint = (opts.ollama or "http://localhost:11434"):gsub("/+$", "") + local argv = { + M.curl, "-sS", "--fail-with-body", "--max-time", "600", + "-H", "Content-Type: application/json", "--data-binary", "@-", endpoint .. "/api/generate", + } + rt.spawn(argv, { stdin = body }, function(r) + if r.error then return callback(nil, "couldn't run curl: " .. r.error) end + local ok, answer = pcall(rt.json.decode, r.stdout or "") + if ok and type(answer) == "table" and answer.error then + return callback(nil, "Ollama: " .. tostring(answer.error)) + end + if r.code ~= 0 or not ok or type(answer) ~= "table" then + return callback(nil, "no answer from Ollama at " .. endpoint .. ": " .. trim(r.stderr ~= "" and r.stderr or r.stdout)) + end + local text = M.clean(answer.response) + if text == "" then return callback(nil, "Ollama's summary was empty") end + callback(text) + end) +end + +-- Seconds of audio in a WAV file, from its header. +local function wav_seconds(path) + local f = io.open(path, "rb") + if not f then return nil end + local header = f:read(44) + local size = f:seek("end") + f:close() + if not header or #header < 44 or header:sub(1, 4) ~= "RIFF" then return nil end + local rate = string.unpack("> 6) + 1, (i >> 6) + 1) .. B64:sub((i & 63) + 1, (i & 63) + 1) +end + +function M.base64(s) + local out, n = {}, #s + local whole = n - n % 3 + for i = 1, whole, 3 do + local a, b, c = s:byte(i, i + 2) + local v = (a << 16) | (b << 8) | c + out[#out + 1] = PAIRS[v >> 12] .. PAIRS[v & 4095] + end + local rest = n - whole + if rest > 0 then + local a, b = s:byte(whole + 1, n) + local v = (a << 16) | ((b or 0) << 8) + local quad = PAIRS[v >> 12] .. PAIRS[v & 4095] + out[#out + 1] = quad:sub(1, rest + 1) .. (rest == 1 and "==" or "=") + end + return table.concat(out) +end + +function M.play(id, page) + local clip = find(id) + local f = clip and io.open(M.dir() .. "/" .. clip.file, "rb") + if not f then return page:send("audio", { id = id, error = "this clip's file is gone" }) end + local data = f:read("a") + f:close() + local mime = clip.file:match("%.ogg$") and "audio/ogg" or "audio/wav" + page:send("audio", { id = id, mime = mime, data = M.base64(data) }) +end + +function M.delete(id) + local clip, i = find(id) + if not clip then return end + os.remove(M.dir() .. "/" .. clip.file) + local clips = M.clips() + table.remove(clips, i) + store.set("clips", clips) + refresh() +end + +function M.library() + local page = rt.ui.page({ + path = "index.html", + on_message = function(name, data, page) + if name == "ready" then + page:send("clips", { clips = M.clips(), pending = M.pending }) + elseif name == "play" then + M.play(data.id, page) + elseif name == "delete" then + M.delete(data.id) + elseif name == "open" and type(data.url) == "string" and data.url:match("^https?://") then + rt.open(data.url, "tab") + elseif name == "shown" then + M.shown = data + elseif name == "loaded" then + M.loaded = data + end + end, + }) + table.insert(libraries, page) + M.pages = libraries + return page +end + +function M.health(report) + if rt.which(M.curl) then report.ok("curl found") else report.error("curl isn't installed; it reaches Ollama") end + if rt.which(program("piper")) then + report.ok("piper found") + else + report.error("piper isn't installed (pipx install piper-tts), or set the piper option") + end + local voice = opts.voice and opts.voice ~= "" and io.open(opts.voice, "rb") + if voice then voice:close() elseif opts.voice then report.warn("no voice file at " .. opts.voice) end + if rt.which(program("ffmpeg")) then + report.ok("ffmpeg found; clips are saved as Opus") + else + report.warn("ffmpeg isn't installed; clips are saved as WAV, about 10 times larger") + end +end + +function M.setup(user_opts) + opts = user_opts or {} + rt.command("listen", function() M.make() end, "Make a spoken summary of this page") + rt.command("listen-library", function() M.library() end, "Browse and play your spoken summaries") + for _, lhs in ipairs(bound) do rt.keymap.del("normal", lhs) end + bound = {} + local key = opts.key == nil and "gA" or opts.key + if key and key ~= "" then + rt.keymap.set("normal", key, function() M.make() end, { desc = "Spoken summary of this page" }) + table.insert(bound, key) + end +end + +return M diff --git a/listen/pages/index.html b/listen/pages/index.html new file mode 100644 index 0000000..c26e602 --- /dev/null +++ b/listen/pages/index.html @@ -0,0 +1,28 @@ + + + + + Listen + + + +
+
+

Listen

+ +
+ +
    +
    • Loading…
    +
    + + + diff --git a/listen/pages/library.js b/listen/pages/library.js new file mode 100644 index 0000000..9107234 --- /dev/null +++ b/listen/pages/library.js @@ -0,0 +1,119 @@ +// The clips the plugin saved. Playing one asks the plugin for its bytes and +// plays them from a blob: URL. +"use strict"; + +const send = (name, data) => rt.send(name, JSON.stringify(data ?? {})); +const $ = (id) => document.getElementById(id); +const audio = $("audio"); + +let clips = []; +let pending = []; +let playing = null; +let url = null; + +function el(tag, props = {}, ...children) { + const node = Object.assign(document.createElement(tag), props); + node.append(...children); + return node; +} + +function duration(seconds) { + if (!seconds) return ""; + const s = Math.round(seconds); + return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`; +} + +function when(created) { + return new Date(created * 1000).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" }); +} + +function row(clip) { + const play = el("button", { className: "play", textContent: clip.id === playing ? "Playing" : "Play" }); + play.addEventListener("click", () => start(clip)); + const remove = el("button", { className: "delete", textContent: "Delete" }); + // A second click deletes, rather than a confirm() dialog. + remove.addEventListener("click", () => { + if (remove.dataset.armed) return send("delete", { id: clip.id }); + remove.dataset.armed = "1"; + remove.textContent = "Delete?"; + setTimeout(() => { + delete remove.dataset.armed; + remove.textContent = "Delete"; + }, 3000); + }); + const source = el("a", { href: clip.url, textContent: clip.site || clip.url }); + source.addEventListener("click", (e) => { + e.preventDefault(); + send("open", { url: clip.url }); + }); + const summary = el("details", {}, el("summary", { textContent: "Summary" }), el("p", { textContent: clip.summary })); + return el( + "li", + { className: clip.id === playing ? "clip current" : "clip" }, + el("div", { className: "actions" }, play, remove), + el("h2", { textContent: clip.title }), + el("p", { className: "meta" }, source, ` · ${when(clip.created)} · ${duration(clip.seconds)}`), + summary, + ); +} + +function start(clip) { + playing = clip.id; + $("now").textContent = clip.title; + $("player").hidden = false; + send("play", { id: clip.id }); + render(); +} + +function render() { + const words = $("filter").value.toLowerCase().split(/\s+/).filter(Boolean); + const shown = clips.filter((c) => { + const text = `${c.title} ${c.site} ${c.summary}`.toLowerCase(); + return words.every((w) => text.includes(w)); + }); + $("pending").replaceChildren( + ...pending.map((j) => el("li", { className: "muted", textContent: `${j.stage === "speaking" ? "Speaking" : "Summarizing"} “${j.title}”…` })), + ); + $("clips").replaceChildren( + ...(shown.length + ? shown.map(row) + : [el("li", { className: "muted", textContent: clips.length ? "No clips match." : "No clips yet. Press gA on a page to make one." })]), + ); + send("shown", { clips: shown.length, pending: pending.length }); +} + +function play(data) { + if (data.id !== playing) return; + if (data.error) { + $("now").textContent = data.error; + return send("loaded", { id: data.id, error: data.error }); + } + const bytes = Uint8Array.from(atob(data.data), (c) => c.charCodeAt(0)); + if (url) URL.revokeObjectURL(url); + url = URL.createObjectURL(new Blob([bytes], { type: data.mime })); + audio.src = url; + audio.playbackRate = Number($("speed").value); + audio.play().catch(() => {}); +} + +audio.addEventListener("loadedmetadata", () => send("loaded", { id: playing, duration: audio.duration })); +audio.addEventListener("error", () => send("loaded", { id: playing, error: audio.error?.message || "can't play this clip" })); +$("speed").addEventListener("change", () => { audio.playbackRate = Number($("speed").value); }); +$("filter").addEventListener("input", render); + +addEventListener("rtmessage", (e) => { + const { name, data } = e.detail; + if (name === "clips") { + // An empty Lua table arrives as {}, not []. + clips = Array.isArray(data.clips) ? data.clips : []; + pending = Array.isArray(data.pending) ? data.pending : []; + render(); + } else if (name === "play") { + const clip = clips.find((c) => c.id === data.id); + if (clip) start(clip); + } else if (name === "audio") { + play(data); + } +}); + +send("ready"); diff --git a/listen/pages/style.css b/listen/pages/style.css new file mode 100644 index 0000000..af13ebd --- /dev/null +++ b/listen/pages/style.css @@ -0,0 +1,133 @@ +:root { + --bg: #fbf8f1; + --fg: #2b2a28; + --muted: #7a756c; + --link: #2b5d9b; + --rule: #e3ddd0; + --card: #f4efe4; + color-scheme: light dark; +} + +@media (prefers-color-scheme: dark) { + :root { + --bg: #1d1c1a; + --fg: #e6e1d6; + --muted: #9a958b; + --link: #8ab4e8; + --rule: #3a3833; + --card: #262522; + } +} + +html { + background: var(--bg); + color: var(--fg); +} + +body { + margin: 0; + font: 16px/1.5 system-ui, sans-serif; +} + +main { + max-width: 44em; + margin: 0 auto; + padding: 2em 1em 6em; +} + +header { + display: flex; + align-items: center; + justify-content: space-between; + gap: 1em; + margin-bottom: 1.5em; +} + +h1 { + margin: 0; + font-size: 1.6em; +} + +input, select, button { + font: inherit; + color: inherit; + background: var(--card); + border: 1px solid var(--rule); + border-radius: 4px; + padding: 0.25em 0.6em; +} + +button { + cursor: pointer; +} + +#player { + position: sticky; + top: 0; + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 0.75em; + padding: 0.75em 0; + margin-bottom: 1em; + background: var(--bg); + border-bottom: 1px solid var(--rule); +} + +#now { + flex-basis: 100%; + margin: 0; + font-weight: 600; +} + +#audio { + flex: 1; + min-width: 16em; +} + +ul { + list-style: none; + margin: 0; + padding: 0; +} + +.clip { + padding: 1em 0; + border-bottom: 1px solid var(--rule); +} + +.clip.current h2 { + color: var(--link); +} + +.clip h2 { + margin: 0 0 0.2em; + font-size: 1.1em; +} + +.actions { + float: right; + display: flex; + gap: 0.4em; + margin-left: 1em; +} + +.meta, .muted { + color: var(--muted); + font-size: 0.9em; + margin: 0; +} + +a { + color: var(--link); +} + +details { + margin-top: 0.4em; + font-size: 0.95em; +} + +summary { + cursor: pointer; + color: var(--muted); +} diff --git a/listen/plugin/listen.lua b/listen/plugin/listen.lua new file mode 100644 index 0000000..3f0375a --- /dev/null +++ b/listen/plugin/listen.lua @@ -0,0 +1,2 @@ +-- The command and key from the start; rt.pack.add's opts set them up again. +require("listen").setup() diff --git a/listen/riptide-plugin.toml b/listen/riptide-plugin.toml new file mode 100644 index 0000000..b9e1895 --- /dev/null +++ b/listen/riptide-plugin.toml @@ -0,0 +1,55 @@ +name = "listen" +description = "Hear a spoken summary of the page, made by a local LLM and Piper, and keep the clips" +riptide = ">=0.17" +# Readability, to find the article. +dependencies = ["reader"] + +[permissions] +# Reads the article out of the page you're on. +pages = ["*"] +# Runs curl (to reach Ollama), piper and ffmpeg. +spawn = true +# Reads and deletes the clips it saved, to play them on its page. +files = true + +[[option]] +name = "key" +description = "The key that makes a spoken summary of the page" +default = "gA" + +[[option]] +name = "voice" +type = "path" +description = "A Piper voice's .onnx file, e.g. en_US-lessac-medium.onnx" +required = true + +[[option]] +name = "model" +description = "The Ollama model that writes the summary" +default = "llama3.2" + +[[option]] +name = "ollama" +description = "Where Ollama listens" +default = "http://localhost:11434" + +[[option]] +name = "words" +type = "number" +description = "About how long the summary is, in words" +default = 150 + +[[option]] +name = "piper" +type = "path" +description = "The piper program, if it isn't on your PATH" + +[[option]] +name = "ffmpeg" +type = "path" +description = "The ffmpeg program, if it isn't on your PATH; without it, clips stay as larger WAV files" + +[[option]] +name = "dir" +type = "path" +description = "Where clips are saved (default: riptide/listen in your data folder)" diff --git a/listen/test/article.html b/listen/test/article.html new file mode 100644 index 0000000..deb0b11 --- /dev/null +++ b/listen/test/article.html @@ -0,0 +1,21 @@ + + +Tide pools | Coast Weekly + + + + +
    Buy the thing now!
    +
    +

    Life in the tide pools

    + +

    Tide pools are small worlds that the sea leaves behind twice a day. Anemones, crabs and small fish wait in them for the water to come back, and each pool keeps its own balance of light, salt and warmth while the tide is out.

    +

    Visit at low tide and walk slowly. The rocks are slippery, and the animals you are looking for hide under ledges and in the weed. A field guide helps you put names to what you see.

    + A shore crab under a ledge +

    Leave everything where you found it. Turning a stone over is fine if you turn it back, gently, the way it was, so whatever lives under it still has a roof.

    + +

    When the water comes back the pools join the sea again, and by the next low tide everything has moved a little. No two visits are the same, which is most of the fun.

    +
    +
    Copyright Coast Weekly
    + + diff --git a/listen/test/bin/fake-curl b/listen/test/bin/fake-curl new file mode 100755 index 0000000..7fa1032 --- /dev/null +++ b/listen/test/bin/fake-curl @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# Ollama's /api/generate, as curl gets it: a summary naming the model, or +# Ollama's error for the model "missing". +import json, sys + +request = json.load(sys.stdin) +if request["model"] == "missing": + print(json.dumps({"error": 'model "missing" not found, try pulling it first'})) + sys.exit(22) +assert "Title: Life in the tide pools" in request["prompt"], request["prompt"] +answer = "plan the script# Tide pools\n**Tide pools** teem with life, says %s." % request["model"] +print(json.dumps({"model": request["model"], "response": answer, "done": True})) diff --git a/listen/test/bin/fake-piper b/listen/test/bin/fake-piper new file mode 100755 index 0000000..53c0b78 --- /dev/null +++ b/listen/test/bin/fake-piper @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# piper --model VOICE --output_file OUT: half a second of silence, as WAV. +import sys, wave + +args = sys.argv[1:] +out = args[args.index("--output_file") + 1] +assert sys.stdin.read().strip(), "no text" +with wave.open(out, "wb") as w: + w.setnchannels(1) + w.setsampwidth(2) + w.setframerate(22050) + w.writeframes(b"\0\0" * 11025) diff --git a/listen/test/config.lua b/listen/test/config.lua new file mode 100644 index 0000000..79fe1e8 --- /dev/null +++ b/listen/test/config.lua @@ -0,0 +1,13 @@ +-- Fake curl and piper from test/bin, and clips in a throwaway folder. +local dir = os.tmpname() +os.remove(dir) +rt.pack.add({ + dir = plugin_test.dir, + name = "listen", + opts = { + voice = "test-voice.onnx", + piper = plugin_test.dir .. "/test/bin/fake-piper", + ffmpeg = "no-such-ffmpeg", + dir = dir, + }, +}) diff --git a/listen/test/empty.html b/listen/test/empty.html new file mode 100644 index 0000000..5124216 --- /dev/null +++ b/listen/test/empty.html @@ -0,0 +1,3 @@ + +Empty +

    Hi.

    diff --git a/listen/test/listen_spec.lua b/listen/test/listen_spec.lua new file mode 100644 index 0000000..312d429 --- /dev/null +++ b/listen/test/listen_spec.lua @@ -0,0 +1,72 @@ +-- Run with: riptide --plugin-test listen +local function listen() return require("listen") end + +local function make_clip() + run("open " .. page("article.html")) + wait_for("load_finished", { pattern = "plugin-test.localhost" }) + local before = #listen().clips() + keys("gA") + local ok = pcall(wait_until, function() return #listen().clips() > before end, 8000) + if not ok then error("no clip: " .. table.concat(messages(), " / ")) end + return listen().clips()[1] +end + +describe("listen", function() + before_each(function() + listen().curl = plugin_test.dir .. "/test/bin/fake-curl" + for _, clip in ipairs(listen().clips()) do listen().delete(clip.id) end + end) + + it("saves a spoken summary of the page's article", function() + local clip = make_clip() + assert.equals("Life in the tide pools", clip.title) + assert.equals("Tide pools\nTide pools teem with life, says llama3.2.", clip.summary) + assert.matches("%.wav$", clip.file, "no ffmpeg in the test config") + assert.truthy(math.abs(clip.seconds - 0.5) < 0.01, tostring(clip.seconds)) + local file = io.open(listen().dir() .. "/" .. clip.file, "rb") + assert.truthy(file) + file:close() + assert.equals(0, #listen().pending) + assert.matches("^listen: ready", last_message()) + end) + + it("lists the clips and plays one", function() + local clip = make_clip() + listen().shown, listen().loaded = nil, nil + run("listen-library") + wait_until(function() return listen().shown ~= nil end, 8000) + assert.equals(1, listen().shown.clips) + assert.truthy(rt.url():match("^riptide://listen%.plugin/")) + local pages = listen().pages + pages[#pages]:send("play", { id = clip.id }) + wait_until(function() return listen().loaded ~= nil end, 8000) + assert.falsy(listen().loaded.error) + end) + + it("deletes a clip and its file", function() + local clip = make_clip() + local path = listen().dir() .. "/" .. clip.file + listen().delete(clip.id) + assert.equals(0, #listen().clips()) + assert.falsy(io.open(path, "rb")) + end) + + it("says what Ollama said when it fails", function() + listen().setup({ voice = "v.onnx", model = "missing", piper = plugin_test.dir .. "/test/bin/fake-piper", dir = listen().dir() }) + run("open " .. page("article.html")) + wait_for("load_finished", { pattern = "plugin-test.localhost" }) + clear_messages() + keys("gA") + wait_until(function() return last_message() and last_message():match("not found") end, 8000) + assert.equals('listen: Ollama: model "missing" not found, try pulling it first', last_message()) + assert.equals(0, #listen().pending) + end) + + it("says so when a page has no article", function() + run("open " .. page("empty.html")) + wait_for("load_finished", { pattern = "plugin-test.localhost" }) + clear_messages() + keys("gA") + wait_until(function() return last_message() == "listen: no article found on this page" end) + end) +end) From 77f4e2e66df4cff2a64ad627f5bd6924367964c8 Mon Sep 17 00:00:00 2001 From: Joshua Cold Date: Mon, 9 Nov 2026 13:44:19 -0700 Subject: [PATCH 2/2] chore(listen): needs riptide 0.20, whose plugin pages play audio Co-Authored-By: Claude Opus 5.5 --- listen/README.md | 2 +- listen/riptide-plugin.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/listen/README.md b/listen/README.md index 72dd551..0e28c46 100644 --- a/listen/README.md +++ b/listen/README.md @@ -40,4 +40,4 @@ the voice and ffmpeg. It brings [reader](../reader), for Readability. It asks to read the pages you use it on, to run curl, piper and ffmpeg, and to read and delete the clips it -saved. Playing a clip needs a riptide newer than 0.17.0 (riptide#159). +saved. It needs riptide 0.20 or newer, whose plugin pages can play audio. diff --git a/listen/riptide-plugin.toml b/listen/riptide-plugin.toml index b9e1895..265eeeb 100644 --- a/listen/riptide-plugin.toml +++ b/listen/riptide-plugin.toml @@ -1,6 +1,6 @@ name = "listen" description = "Hear a spoken summary of the page, made by a local LLM and Piper, and keep the clips" -riptide = ">=0.17" +riptide = ">=0.20" # Readability, to find the article. dependencies = ["reader"]