diff --git a/CHANGELOG.md b/CHANGELOG.md index e5ea6b0..a7bcc9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 0.30.0 — `VoiceMode`: talking with a chat, and a microphone that cannot be opened twice + +Owner, 2026-11-13: Cat Bot has to be a complete equivalent of Grok Bot, which has a voice mode. The chat could take dictation and read an answer aloud, but not hold a spoken conversation. + +- `VoiceMode` (the screen), `useVoiceMode` (the loop) and `voiceModeReducer` (the rules, pure): listening → thinking → speaking → listening. One big button: while listening it ends the person's turn (where the browser's own recogniser runs, a pause ends it by itself); while the answer is read it cuts in. The app passes `onTurn(text) => Promise` and, if it has one, a studio `speaker`; the microphone options are the composer's own. +- The microphone and the voice follow the phase and nothing else (`voiceModeWants`): never both open, neither open when the call is off. Two takes in a row with nothing in them close the call ("Nothing was heard"), and so do a failed transcription and an answer that never comes, each with its sentence and a "Talk again". +- **Fix, `useDictation`:** a second `start()` before the browser had handed the microphone over opened a second microphone and orphaned the first, whose track stayed live with nothing left to stop it (a double tap on the mic could do it). One request at a time now, and a take cancelled while the microphone was still opening closes it where it arrives. +- `test/voice-mode.test.js` (8, the rules in Node) and `test/browser-voice.mjs` (a real browser with a fake-device microphone, every opened track counted: the loop, cutting in, End, silence, no answer, a dead transcription, 390px and 320px). `demo/voice.html`. + ## 0.29.0 — `Messenger`: people talking to people, and to the agents among them Owner, 2026-11-12, looking at OrangeCat's direct messages on a phone: the Cat had answered in a conversation between two people and "it's hard to tell whether it was the cat or my friend"; nothing said an AI was taking part; "you scroll down and then the half screen is taken"; and nothing could be attached. That messenger was built in the app (about 8,700 lines), so none of it could be fixed for the next product either. This is the messenger as a package. diff --git a/README.md b/README.md index 6d70184..8860f11 100644 --- a/README.md +++ b/README.md @@ -679,6 +679,28 @@ punctuation but a closing colon, plus an `---` beside it. A bold sentence it is, so it never flashes. `dropReplyLabel(text)` is exported for apps that pass their own `replies`. +### Voice mode — talking with a chat + +```tsx +import { VoiceMode } from "@bitbaum/chatkit/react"; + + setTalking(false)} + name="Day Planner" + dictation={{ transcribeUrl: "/api/transcribe" }} + onTurn={async (text) => (await send(text)).answer} +/>; +``` + +A spoken conversation, full screen: listening → thinking → speaking → +listening. One big button ends the person's turn (a pause ends it by itself +where the browser's own recogniser runs) and cuts in while the answer is read. +Open it from a tap. The microphone and the voice are never both open, and +neither is open once the call is over; nothing heard twice, a failed +transcription or an answer that never comes each end the call in words. +`useVoiceMode` is the loop without the screen; `voiceModeReducer` is its rules. + ### Under every answer — Copy, Listen, Share `AnswerActions` is the row under an answer, the same in every product: diff --git a/demo/demo.tsx b/demo/demo.tsx index 71dc417..c4aa6af 100644 --- a/demo/demo.tsx +++ b/demo/demo.tsx @@ -2,6 +2,7 @@ import { mountScrollFixture } from "./scroll.js"; import { mountAppFixture } from "./app.js"; import { mountFieldFixture } from "./field.js"; import { mountMessengerFixture } from "./messenger.js"; +import { mountVoiceFixture } from "./voice.js"; // The visual check: every part of the chat on one page, in light and dark. // `pnpm run demo` builds demo/dist/; open demo/index.html. Screenshot it at // 390px and at desktop width before calling a change to chatkit done. @@ -402,3 +403,4 @@ mountScrollFixture(); mountAppFixture(); mountFieldFixture(); mountMessengerFixture(); +mountVoiceFixture(); diff --git a/demo/voice.html b/demo/voice.html new file mode 100644 index 0000000..18faf8f --- /dev/null +++ b/demo/voice.html @@ -0,0 +1,20 @@ + + + + + + Voice mode + + + + + +
+ + + diff --git a/demo/voice.tsx b/demo/voice.tsx new file mode 100644 index 0000000..f9afbc0 --- /dev/null +++ b/demo/voice.tsx @@ -0,0 +1,82 @@ +// The fixture behind demo/voice.html and test/browser-voice.mjs: VoiceMode the +// way an app mounts it. The microphone is real (the browser's fake device in +// the test); the transcription, the answer and the voice are stubs the page's +// URL steers, so the test is deterministic: +// ?heard= what the "server" says was said ("" for nothing) +// ?answer= what the chat answers ("" for no answer) +// ?fail=mic the transcription fails +import { StrictMode, useState } from "react"; +import { createRoot } from "react-dom/client"; +import { VoiceMode, type Speaker } from "../src/react/index.js"; + +declare global { + interface Window { + __voice: { turns: string[]; spoken: string[]; speaking: boolean }; + } +} + +function Fixture() { + const q = new URLSearchParams(location.search); + const heard = q.get("heard") ?? "what is next today"; + const answer = q.get("answer") ?? "The **report**, at five."; + const [open, setOpen] = useState(false); + window.__voice ??= { turns: [], spoken: [], speaking: false }; + // A voice that takes a moment, so "speaking" can be seen and cut into. + const speaker: Speaker = { + speak(text) { + window.__voice.spoken.push(text); + window.__voice.speaking = true; + return new Promise((resolve) => { + const t = setTimeout( + () => { + window.__voice.speaking = false; + resolve(); + }, + Number(q.get("voiceMs") ?? 600), + ); + speaker.cancel = () => { + clearTimeout(t); + window.__voice.speaking = false; + resolve(); + }; + }); + }, + cancel() {}, + }; + return ( +
+ + setOpen(false)} + name="Day Planner" + speaker={speaker} + dictation={{ + prefer: "server", + rememberKey: null, + transcribe: async () => { + if (q.get("fail") === "mic") throw new Error("down"); + return heard; + }, + }} + onTurn={async (text) => { + window.__voice.turns.push(text); + await new Promise((r) => setTimeout(r, 150)); + return answer; + }} + /> +
+ ); +} + +export function mountVoiceFixture() { + const el = document.getElementById("voice-fixture"); + if (el) + createRoot(el).render( + + + , + ); +} diff --git a/dist/index.d.ts b/dist/index.d.ts index d72996f..48fe500 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -11,6 +11,7 @@ export * from "./attachments.js"; export * from "./image.js"; export * from "./replies.js"; export * from "./speech.js"; +export * from "./voice-mode.js"; export * from "./rich.js"; export * from "./review.js"; export * from "./conversations.js"; diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 3511f01..74ed27e 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 9502545..f513319 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11,6 +11,7 @@ export * from "./attachments.js"; export * from "./image.js"; export * from "./replies.js"; export * from "./speech.js"; +export * from "./voice-mode.js"; export * from "./rich.js"; export * from "./review.js"; export * from "./conversations.js"; diff --git a/dist/index.js.map b/dist/index.js.map index 67af813..41b3e35 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/react/VoiceMode.d.ts b/dist/react/VoiceMode.d.ts new file mode 100644 index 0000000..c6a5b1b --- /dev/null +++ b/dist/react/VoiceMode.d.ts @@ -0,0 +1,37 @@ +import type { DictationProblem } from "../dictation.js"; +import type { VoiceModeEnd } from "../voice-mode.js"; +import { type UseVoiceModeOptions } from "./use-voice-mode.js"; +export type VoiceModeLabels = { + title: string; + /** Under the button, per phase: what is happening and what a press does. */ + listening: string; + thinking: string; + speaking: string; + /** The big button's name for a screen reader, per phase. */ + pressListening: string; + pressSpeaking: string; + pressThinking: string; + end: string; + again: string; + /** Why the call is over. */ + ended: Record, string>; + dictation: Record; +}; +export declare const DEFAULT_VOICE_MODE_LABELS: VoiceModeLabels; +export type VoiceModeProps = UseVoiceModeOptions & { + open: boolean; + onClose: () => void; + /** Who is being talked to, shown above the button. */ + name?: string; + labels?: Partial; +}; +/** + * A spoken conversation, full screen: one big button, what was heard, what is + * being said back, and End. Open it from a tap (browsers open a microphone + * and a voice only inside one); closing it shuts both. + * + * The loop and its rules are `useVoiceMode` and `voiceModeReducer`. This is + * only the screen, so every chat that offers voice looks and behaves the same. + */ +export declare function VoiceMode({ open, onClose, name, labels: given, ...opts }: VoiceModeProps): import("react").JSX.Element; +//# sourceMappingURL=VoiceMode.d.ts.map \ No newline at end of file diff --git a/dist/react/VoiceMode.d.ts.map b/dist/react/VoiceMode.d.ts.map new file mode 100644 index 0000000..2b13b2c --- /dev/null +++ b/dist/react/VoiceMode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"VoiceMode.d.ts","sourceRoot":"","sources":["../../src/react/VoiceMode.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE7E,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IACtD,SAAS,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,eAgBvC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG;IACjD,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,cAAc,+BA0GxF"} \ No newline at end of file diff --git a/dist/react/VoiceMode.js b/dist/react/VoiceMode.js new file mode 100644 index 0000000..d588624 --- /dev/null +++ b/dist/react/VoiceMode.js @@ -0,0 +1,79 @@ +"use client"; +import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; +import { useEffect, useRef } from "react"; +import { plainTextForSpeech } from "../speech.js"; +import { IconX } from "./icons.js"; +import { DEFAULT_DICTATION_MESSAGES } from "../dictation.js"; +import { useVoiceMode } from "./use-voice-mode.js"; +export const DEFAULT_VOICE_MODE_LABELS = { + dictation: DEFAULT_DICTATION_MESSAGES, + title: "Talk", + listening: "Listening. Tap when you have finished.", + thinking: "Thinking…", + speaking: "Tap to cut in.", + pressListening: "I have finished speaking", + pressSpeaking: "Stop reading and listen to me", + pressThinking: "Waiting for the answer", + end: "End", + again: "Talk again", + ended: { + silence: "Nothing was heard, so the microphone is closed.", + microphone: "The microphone stopped.", + "no-answer": "No answer came. Your words are in the chat; try again there.", + }, +}; +/** + * A spoken conversation, full screen: one big button, what was heard, what is + * being said back, and End. Open it from a tap (browsers open a microphone + * and a voice only inside one); closing it shuts both. + * + * The loop and its rules are `useVoiceMode` and `voiceModeReducer`. This is + * only the screen, so every chat that offers voice looks and behaves the same. + */ +export function VoiceMode({ open, onClose, name, labels: given, ...opts }) { + const labels = { ...DEFAULT_VOICE_MODE_LABELS, ...given }; + const vm = useVoiceMode(opts); + const ref = useRef(null); + const { start, end, state } = vm; + useEffect(() => { + const d = ref.current; + if (!d) + return; + if (open && !d.open && typeof d.showModal === "function") { + d.showModal(); + start(); + } + else if (!open && d.open) { + end(); + d.close(); + } + }, [open, start, end]); + // Unmounting ends the call too: a microphone that outlives its screen is the worst bug a chat can have. + useEffect(() => () => end(), [end]); + const phase = state.phase; + const line = phase === "listening" + ? vm.dictation.liveText || labels.listening + : phase === "thinking" + ? state.said + : phase === "speaking" + ? plainTextForSpeech(state.answer) + : ""; + const reason = state.ended && state.ended !== "ended" + ? vm.dictation.problem + ? labels.dictation[vm.dictation.problem] + : labels.ended[state.ended] + : null; + return (_jsxs("dialog", { ref: ref, className: "ck-voicemode", "aria-label": name ? `${labels.title}: ${name}` : labels.title, onClose: () => { + end(); + onClose(); + }, children: [_jsxs("div", { className: "ck-voicemode-top", children: [_jsx("span", { className: "ck-voicemode-name", children: name ?? labels.title }), _jsx("button", { type: "button", className: "ck-icon-btn", "aria-label": labels.end, onClick: onClose, children: _jsx(IconX, {}) })] }), _jsx("div", { className: "ck-voicemode-body", "data-phase": phase, "data-mic": vm.dictation.status, children: phase === "off" ? (_jsxs(_Fragment, { children: [reason && (_jsx("p", { className: "ck-voicemode-reason", role: "status", children: reason })), _jsx("button", { type: "button", className: "ck-voicemode-again", onClick: start, children: labels.again })] })) : (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "ck-voicemode-orb", "data-phase": phase, disabled: phase === "thinking", "aria-label": phase === "listening" + ? labels.pressListening + : phase === "speaking" + ? labels.pressSpeaking + : labels.pressThinking, onClick: vm.press, children: _jsx("span", { className: "ck-voicemode-ring", "aria-hidden": "true" }) }), _jsx("p", { className: "ck-voicemode-status", role: "status", children: phase === "listening" + ? labels.listening + : phase === "thinking" + ? labels.thinking + : labels.speaking }), line && line !== labels.listening && (_jsx("p", { className: "ck-voicemode-line", "data-phase": phase, children: line }))] })) }), _jsx("div", { className: "ck-voicemode-foot", children: _jsx("button", { type: "button", className: "ck-voicemode-end", onClick: onClose, children: labels.end }) })] })); +} +//# sourceMappingURL=VoiceMode.js.map \ No newline at end of file diff --git a/dist/react/VoiceMode.js.map b/dist/react/VoiceMode.js.map new file mode 100644 index 0000000..715448c --- /dev/null +++ b/dist/react/VoiceMode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"VoiceMode.js","sourceRoot":"","sources":["../../src/react/VoiceMode.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAA4B,MAAM,qBAAqB,CAAC;AAmB7E,MAAM,CAAC,MAAM,yBAAyB,GAAoB;IACxD,SAAS,EAAE,0BAA0B;IACrC,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,wCAAwC;IACnD,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,gBAAgB;IAC1B,cAAc,EAAE,0BAA0B;IAC1C,aAAa,EAAE,+BAA+B;IAC9C,aAAa,EAAE,wBAAwB;IACvC,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE;QACL,OAAO,EAAE,iDAAiD;QAC1D,UAAU,EAAE,yBAAyB;QACrC,WAAW,EAAE,8DAA8D;KAC5E;CACF,CAAC;AAUF;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAA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b,SAAS,EAAC,kBAAkB,gBAChB,KAAK,EACjB,QAAQ,EAAE,KAAK,KAAK,UAAU,gBAE5B,KAAK,KAAK,WAAW;gCACnB,CAAC,CAAC,MAAM,CAAC,cAAc;gCACvB,CAAC,CAAC,KAAK,KAAK,UAAU;oCACpB,CAAC,CAAC,MAAM,CAAC,aAAa;oCACtB,CAAC,CAAC,MAAM,CAAC,aAAa,EAE5B,OAAO,EAAE,EAAE,CAAC,KAAK,YAEjB,eAAM,SAAS,EAAC,mBAAmB,iBAAa,MAAM,GAAG,GAClD,EACT,YAAG,SAAS,EAAC,qBAAqB,EAAC,IAAI,EAAC,QAAQ,YAC7C,KAAK,KAAK,WAAW;gCACpB,CAAC,CAAC,MAAM,CAAC,SAAS;gCAClB,CAAC,CAAC,KAAK,KAAK,UAAU;oCACpB,CAAC,CAAC,MAAM,CAAC,QAAQ;oCACjB,CAAC,CAAC,MAAM,CAAC,QAAQ,GACnB,EACH,IAAI,IAAI,IAAI,KAAK,MAAM,CAAC,SAAS,IAAI,CACpC,YAAG,SAAS,EAAC,mBAAmB,gBAAa,KAAK,YAC/C,IAAI,GACH,CACL,IACA,CACJ,GACG,EAEN,cAAK,SAAS,EAAC,mBAAmB,YAChC,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,kBAAkB,EAAC,OAAO,EAAE,OAAO,YAChE,MAAM,CAAC,GAAG,GACJ,GACL,IACC,CACV,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/react/index.d.ts b/dist/react/index.d.ts index c9dd629..0086fd7 100644 --- a/dist/react/index.d.ts +++ b/dist/react/index.d.ts @@ -20,6 +20,10 @@ export { Markdown, SourcesRow, defaultRenderLink, defaultRenderCitation } from " export { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS } from "./AnswerActions.js"; export type { AnswerActionsLabels } from "./AnswerActions.js"; export { useSpeech } from "./use-speech.js"; +export { useVoiceMode } from "./use-voice-mode.js"; +export type { UseVoiceModeOptions, VoiceModeController } from "./use-voice-mode.js"; +export { VoiceMode, DEFAULT_VOICE_MODE_LABELS } from "./VoiceMode.js"; +export type { VoiceModeProps, VoiceModeLabels } from "./VoiceMode.js"; export type { SpeechController } from "./use-speech.js"; export { Sheet, prefersSheet } from "./Sheet.js"; export type { CitationMap, RenderLink, RenderCitation, RenderSources } from "./Markdown.js"; diff --git a/dist/react/index.d.ts.map b/dist/react/index.d.ts.map index c0526b7..e42a9e7 100644 --- a/dist/react/index.d.ts.map +++ b/dist/react/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrF,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,aA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AAY,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9F,YAAY,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAClE,YAAY,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,aAAa,EACb,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrF,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,UAAU,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,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B,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACxE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9E,YAAY,EACV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC9F,YAAY,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/react/index.js b/dist/react/index.js index fe5f7d5..c6d2e36 100644 --- a/dist/react/index.js +++ b/dist/react/index.js @@ -15,6 +15,8 @@ export { ChatScreen } from "./Screen.js"; export { Markdown, SourcesRow, defaultRenderLink, defaultRenderCitation } from "./Markdown.js"; export { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS } from "./AnswerActions.js"; export { useSpeech } from "./use-speech.js"; +export { useVoiceMode } from "./use-voice-mode.js"; +export { VoiceMode, DEFAULT_VOICE_MODE_LABELS } from "./VoiceMode.js"; export { Sheet, prefersSheet } from "./Sheet.js"; export { useDictation } from "./use-dictation.js"; export { AttachMenu, DEFAULT_ATTACH_MENU_LABELS } from "./AttachMenu.js"; diff --git a/dist/react/index.js.map b/dist/react/index.js.map index 48a838c..117d70a 100644 --- a/dist/react/index.js.map +++ b/dist/react/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAQlE,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAarB,OAAO,EAAE,cAAc,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAOrF,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAO5B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,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AE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE/F,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAExE,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ9E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"} \ No newline at end of file diff --git a/dist/react/use-dictation.d.ts.map b/dist/react/use-dictation.d.ts.map index 8d2f01e..b73b2f8 100644 --- a/dist/react/use-dictation.d.ts.map +++ b/dist/react/use-dictation.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"use-dictation.d.ts","sourceRoot":"","sources":["../../src/react/use-dictation.ts"],"names":[],"mappings":"AAGA,OAAO,EAoBL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAC;AAoCzB,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,WAAW,GAAG,cAAc,CAAC;AAEpE,MAAM,MAAM,mBAAmB,GAAG;IAChC,wDAAwD;IACxD,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B;;0DAEsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;8EAG0E;IAC1E,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9D;;+CAE2C;IAC3C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;wCACoC;IACpC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,2EAA2E;IAC3E,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;IACxB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACjC;+EAC2E;IAC3E,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;gEAC4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;oEACgE;IAChE,iBAAiB,EAAE,OAAO,CAAC;IAC3B;;6EAEyE;IACzE,cAAc,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC;AA8CF;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,mBAAmB,CA6b3E"} \ No newline at end of file +{"version":3,"file":"use-dictation.d.ts","sourceRoot":"","sources":["../../src/react/use-dictation.ts"],"names":[],"mappings":"AAGA,OAAO,EAoBL,KAAK,mBAAmB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A8C;IAC9C,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;oEACgE;IAChE,iBAAiB,EAAE,OAAO,CAAC;IAC3B;;6EAEyE;IACzE,cAAc,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD,CAAC;AA8CF;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,mBAAmB,CA8c3E"} \ No newline at end of file diff --git a/dist/react/use-dictation.js b/dist/react/use-dictation.js index a47b80d..83e21c2 100644 --- a/dist/react/use-dictation.js +++ b/dist/react/use-dictation.js @@ -111,6 +111,8 @@ export function useDictation(opts) { const recorderRef = useRef(null); const streamRef = useRef(null); const cancelledRef = useRef(false); + /** True from the request for a microphone until the browser answers it. */ + const openingRef = useRef(false); const capTimer = useRef(null); const locale = useCallback(() => { const l = optsRef.current.lang ?? @@ -206,6 +208,14 @@ export function useDictation(opts) { setStatus("idle"); return; } + // One microphone at a time. `status` stays "idle" until the browser hands + // the microphone over, so a second start in that gap (a double tap, an + // effect that runs twice) used to open a second microphone and orphan the + // first: its track stayed live with nothing left to stop it. Found by + // voice mode's browser test, 2026-11-13. + if (openingRef.current) + return; + openingRef.current = true; setProblem(null); cancelledRef.current = false; let stream; @@ -213,10 +223,19 @@ export function useDictation(opts) { stream = await navigator.mediaDevices.getUserMedia({ audio: true }); } catch (e) { + openingRef.current = false; setProblem(problemForRecording(e)); setStatus("idle"); return; } + openingRef.current = false; + // Cancelled while the browser was still opening it: this microphone was + // never wanted, so it is closed here, where it arrives. + if (cancelledRef.current) { + for (const t of stream.getTracks()) + t.stop(); + return; + } streamRef.current = stream; let rec; try { diff --git a/dist/react/use-dictation.js.map b/dist/react/use-dictation.js.map index 484e318..6fe8c63 100644 --- a/dist/react/use-dictation.js.map +++ b/dist/react/use-dictation.js.map @@ -1 +1 @@ -{"version":3,"file":"use-dictation.js","sourceRoot":"","sources":["../../src/react/use-dictation.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACb,0BAA0B,EAC1B,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,yBAAyB,EACzB,UAAU,EACV,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,QAAQ,EACR,kBAAkB,GAInB,MAAM,iBAAiB,CAAC;AAiBzB,SAAS,UAAU;IACjB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,CAAC,GAAG,MAGT,CAAC;IACF,OAAO,CAAC,CAAC,iBAAiB,IAAI,CAAC,CAAC,uBAAuB,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,CACL,OAAO,MAAM,KAAK,WAAW;QAC7B,OAAO,aAAa,KAAK,WAAW;QACpC,CAAC,CAAC,SAAS,CAAC,YAAY,EAAE,YAAY,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;AAqEnC,MAAM,oBAAoB,GAAG,sCAAsC,CAAC;AAEpE,SAAS,QAAQ,CAAC,GAAkB;IAClC,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7C,OAAO,0BAA0B,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CA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AmE;IACnE,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,UAAU;QACZ,CAAC;QACD,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,UAAU;QACZ,CAAC;QACD,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC;QAC/B,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,KAAK,UAAU;YAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC7C,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL,SAAS;QACT,MAAM;QACN,SAAS;QACT,QAAQ;QACR,OAAO;QACP,aAAa;QACb,QAAQ;QACR,KAAK;QACL,YAAY,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QACpC,KAAK;QACL,IAAI;QACJ,MAAM;QACN,MAAM;QACN,iBAAiB,EAAE,SAAS;QAC5B,cAAc;KACf,CAAC;AACJ,CAAC"} \ No newline at end of file +{"version":3,"file":"use-dictation.js","sourceRoot":"","sources":["../../src/react/use-dictation.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACvF,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,yBAAyB,EACzB,gBAAgB,EAChB,aAAa,EACb,0BAA0B,EAC1B,YAAY,EACZ,iBAA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MAAM,KAAK,WAAW;YAAE,IAAI,EAAE,CAAC;;YAC9B,KAAK,EAAE,CAAC;IACf,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAE1B,mEAAmE;IACnE,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE;QACT,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,UAAU;QACZ,CAAC;QACD,IAAI,CAAC;YACH,UAAU,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,UAAU;QACZ,CAAC;QACD,MAAM,EAAE,GAAG,WAAW,CAAC,OAAO,CAAC;QAC/B,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,KAAK,UAAU;YAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC7C,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL,SAAS;QACT,MAAM;QACN,SAAS;QACT,QAAQ;QACR,OAAO;QACP,aAAa;QACb,QAAQ;QACR,KAAK;QACL,YAAY,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QACpC,KAAK;QACL,IAAI;QACJ,MAAM;QACN,MAAM;QACN,iBAAiB,EAAE,SAAS;QAC5B,cAAc;KACf,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/react/use-voice-mode.d.ts b/dist/react/use-voice-mode.d.ts new file mode 100644 index 0000000..35ed74e --- /dev/null +++ b/dist/react/use-voice-mode.d.ts @@ -0,0 +1,40 @@ +import { type VoiceModeState } from "../voice-mode.js"; +import type { Speaker } from "../speech.js"; +import { type DictationController, type UseDictationOptions } from "./use-dictation.js"; +export type UseVoiceModeOptions = { + /** + * Send the person's turn and resolve with the answer's words (markdown is + * fine; it is flattened before it is read). Resolve with "" or reject when + * no answer came: the call then ends and says so. + */ + onTurn: (text: string) => Promise; + /** The same options the composer's microphone takes (`transcribeUrl`, `lang`…). */ + dictation?: Omit; + /** A studio voice; the browser's own voice when omitted. */ + speaker?: Speaker | null; +}; +export type VoiceModeController = { + /** False where this device can neither listen nor speak. */ + supported: boolean; + state: VoiceModeState; + dictation: DictationController; + /** Open the call. Must run inside a tap: browsers open a microphone and a voice only then. */ + start: () => void; + end: () => void; + /** + * The one big button. Listening: "I have finished speaking". Speaking: cut + * in and listen again. Thinking: nothing to do. + */ + press: () => void; +}; +/** + * A spoken conversation over any chat: listen, send, read the answer aloud, + * listen again (`voiceModeReducer` holds the rules). Where the browser's own + * recogniser runs, a pause ends the person's turn by itself; everywhere else + * a press of the button does, which is also how a person takes their time. + * + * The microphone and the voice follow the phase and nothing else + * (`voiceModeWants`), and both are shut when the component unmounts. + */ +export declare function useVoiceMode(opts: UseVoiceModeOptions): VoiceModeController; +//# sourceMappingURL=use-voice-mode.d.ts.map \ No newline at end of file diff --git a/dist/react/use-voice-mode.d.ts.map b/dist/react/use-voice-mode.d.ts.map new file mode 100644 index 0000000..90d9841 --- /dev/null +++ b/dist/react/use-voice-mode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"use-voice-mode.d.ts","sourceRoot":"","sources":["../../src/react/use-voice-mode.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1C,mFAAmF;IACnF,SAAS,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,CAAC;IAChD,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,mBAAmB,CAAC;IAC/B,8FAA8F;IAC9F,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,mBAAmB,CA6G3E"} \ No newline at end of file diff --git a/dist/react/use-voice-mode.js b/dist/react/use-voice-mode.js new file mode 100644 index 0000000..1e7acc9 --- /dev/null +++ b/dist/react/use-voice-mode.js @@ -0,0 +1,131 @@ +"use client"; +import { useCallback, useEffect, useReducer, useRef } from "react"; +import { VOICE_MODE_OFF, voiceModeReducer, voiceModeWants, } from "../voice-mode.js"; +import { useDictation, } from "./use-dictation.js"; +import { useSpeech } from "./use-speech.js"; +/** + * A spoken conversation over any chat: listen, send, read the answer aloud, + * listen again (`voiceModeReducer` holds the rules). Where the browser's own + * recogniser runs, a pause ends the person's turn by itself; everywhere else + * a press of the button does, which is also how a person takes their time. + * + * The microphone and the voice follow the phase and nothing else + * (`voiceModeWants`), and both are shut when the component unmounts. + */ +export function useVoiceMode(opts) { + const [state, dispatch] = useReducer(voiceModeReducer, VOICE_MODE_OFF); + const onTurn = useRef(opts.onTurn); + useEffect(() => { + onTurn.current = opts.onTurn; + }, [opts.onTurn]); + /** Guards against an answer that arrives after the call moved on. */ + const turn = useRef(0); + const dictation = useDictation({ + // A pause should end the turn where the browser can hear one; a press + // ends it everywhere else. + prefer: "browser", + ...opts.dictation, + onText: (text) => dispatch({ type: "heard", text }), + }); + // The newest controller, for effects: set before any of them runs. + const dictationRef = useRef(dictation); + useEffect(() => { + dictationRef.current = dictation; + }); + const speech = useSpeech(opts.speaker); + const { microphone, voice } = voiceModeWants(state.phase); + // The microphone follows the phase. + const micStatus = dictation.status; + useEffect(() => { + const d = dictationRef.current; + // Listening and the microphone is free: open it. This runs again when a + // take that held nothing has been written down (status back to idle), so + // a second take follows an empty first one. + if (microphone && micStatus === "idle") + d.start(); + // Not the person's turn: a live take is thrown away. A take that is being + // written down is left alone; it is the turn on its way. + if (!microphone && micStatus === "listening") + d.cancel(); + }, [microphone, micStatus, state.silentTakes]); + // A microphone or transcription problem ends the call, with its reason on screen. + // "silence" is a take with nothing in it: the rules count those and close + // the microphone after two. Anything else is the microphone itself. + const problem = dictation.problem; + useEffect(() => { + if (!problem || state.phase === "off") + return; + if (problem === "silence") { + dictationRef.current.clearProblem(); + dispatch({ type: "heard", text: "" }); + } + else { + dispatch({ type: "problem" }); + } + }, [problem, state.phase]); + // The turn is sent once, when the phase becomes "thinking". + useEffect(() => { + if (state.phase !== "thinking") + return; + const mine = ++turn.current; + let live = true; + onTurn + .current(state.said) + .then((answer) => { + if (live && mine === turn.current) + dispatch({ type: "answer", text: answer ?? "" }); + }) + .catch(() => { + if (live && mine === turn.current) + dispatch({ type: "no-answer" }); + }); + return () => { + live = false; + }; + }, [state.phase, state.said]); + // The voice follows the phase; when the reading ends, the person's turn begins. + const speechRef = useRef(speech); + useEffect(() => { + speechRef.current = speech; + }); + const reading = useRef(false); + useEffect(() => { + if (voice && state.answer) { + reading.current = false; + speechRef.current.speak(state.answer); + } + else { + reading.current = false; + speechRef.current.stop(); + } + }, [voice, state.answer]); + useEffect(() => { + if (!voice) + return; + if (speech.speaking) + reading.current = true; + // Reading began and is over (or the device has no voice at all): listen. + else if (reading.current || !speech.supported) + dispatch({ type: "spoken" }); + }, [voice, speech.speaking, speech.supported]); + const start = useCallback(() => dispatch({ type: "start" }), []); + const end = useCallback(() => { + turn.current++; + dispatch({ type: "end" }); + }, []); + const press = useCallback(() => { + if (state.phase === "listening") + dictationRef.current.stop(); + else if (state.phase === "speaking") + dispatch({ type: "interrupt" }); + }, [state.phase]); + return { + supported: dictation.supported, + state, + dictation, + start, + end, + press, + }; +} +//# sourceMappingURL=use-voice-mode.js.map \ No newline at end of file diff --git a/dist/react/use-voice-mode.js.map b/dist/react/use-voice-mode.js.map new file mode 100644 index 0000000..9a2643a --- /dev/null +++ b/dist/react/use-voice-mode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"use-voice-mode.js","sourceRoot":"","sources":["../../src/react/use-voice-mode.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,GAEf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA8B5C;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,IAAyB;IACpD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;IACvE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClB,qEAAqE;IACrE,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAEvB,MAAM,SAAS,GAAG,YAA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C,KAAK,KAAK,WAAW;YAAE,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;aACxD,IAAI,KAAK,CAAC,KAAK,KAAK,UAAU;YAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IACvE,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAElB,OAAO;QACL,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,KAAK;QACL,SAAS;QACT,KAAK;QACL,GAAG;QACH,KAAK;KACN,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/dist/voice-mode.d.ts b/dist/voice-mode.d.ts new file mode 100644 index 0000000..95d49dd --- /dev/null +++ b/dist/voice-mode.d.ts @@ -0,0 +1,81 @@ +/** + * Voice mode: talking with a chat instead of typing into it. + * + * The whole conversation is four states and the rules between them, as one + * pure function, so the rules are tests that run in Node and every surface + * (a chat with a bot, the Cat, a widget) takes its turns the same way: + * + * listening the microphone is open; what is heard is the person's turn + * thinking the turn was sent; the answer is on its way + * speaking the answer is being read aloud + * off nothing is open + * + * The loop is listening → thinking → speaking → listening. A person can + * always cut in: speaking + "interrupt" goes straight back to listening. + * The microphone is never left open by accident: two takes in a row with + * nothing in them end the call, and so does any problem, with its reason. + */ +export type VoiceModePhase = "off" | "listening" | "thinking" | "speaking"; +export type VoiceModeEnd = +/** The person ended it. */ +"ended" +/** Nothing was heard, twice in a row. */ + | "silence" +/** The microphone or the transcription failed. */ + | "microphone" +/** The answer did not come. */ + | "no-answer"; +export type VoiceModeState = { + phase: VoiceModePhase; + /** Takes in a row with nothing in them. */ + silentTakes: number; + /** Why the call is over, when it is; null while it runs or before it starts. */ + ended: VoiceModeEnd | null; + /** What the person last said, shown while the answer is on its way. */ + said: string; + /** What is being read aloud. */ + answer: string; +}; +export type VoiceModeEvent = { + type: "start"; +} +/** A take ended; `text` is what was heard ("" for nothing). */ + | { + type: "heard"; + text: string; +} +/** The answer to the turn that was sent. */ + | { + type: "answer"; + text: string; +} +/** The answer did not come (the send failed, or it came back empty). */ + | { + type: "no-answer"; +} +/** The reading finished. */ + | { + type: "spoken"; +} +/** The person cut in while the answer was being read. */ + | { + type: "interrupt"; +} | { + type: "problem"; +} | { + type: "end"; +}; +/** Two empty takes in a row and the microphone closes. */ +export declare const VOICE_MODE_MAX_SILENT_TAKES = 2; +export declare const VOICE_MODE_OFF: VoiceModeState; +export declare function voiceModeReducer(state: VoiceModeState, event: VoiceModeEvent): VoiceModeState; +/** + * What each phase asks of the device. The hook does exactly this and nothing + * else, so the microphone and the voice can never both be open, and neither + * is open when the call is off. + */ +export declare function voiceModeWants(phase: VoiceModePhase): { + microphone: boolean; + voice: boolean; +}; +//# sourceMappingURL=voice-mode.d.ts.map \ No newline at end of file diff --git a/dist/voice-mode.d.ts.map b/dist/voice-mode.d.ts.map new file mode 100644 index 0000000..d3a9717 --- /dev/null +++ b/dist/voice-mode.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"voice-mode.d.ts","sourceRoot":"","sources":["../src/voice-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC;AAE3E,MAAM,MAAM,YAAY;AACtB,2BAA2B;AACzB,OAAO;AACT,yCAAyC;GACvC,SAAS;AACX,kDAAkD;GAChD,YAAY;AACd,+BAA+B;GAC7B,WAAW,CAAC;AAEhB,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,cAAc,CAAC;IACtB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE;AACnB,+DAA+D;GAC7D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AACjC,4CAA4C;GAC1C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAClC,wEAAwE;GACtE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE;AACvB,4BAA4B;GAC1B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE;AACpB,yDAAyD;GACvD;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GACrB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpB,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C,eAAO,MAAM,cAAc,EAAE,cAM5B,CAAC;AAIF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,cAAc,GAAG,cAAc,CA8B7F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG;IAAE,UAAU,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAE7F"} \ No newline at end of file diff --git a/dist/voice-mode.js b/dist/voice-mode.js new file mode 100644 index 0000000..7f4102d --- /dev/null +++ b/dist/voice-mode.js @@ -0,0 +1,71 @@ +/** + * Voice mode: talking with a chat instead of typing into it. + * + * The whole conversation is four states and the rules between them, as one + * pure function, so the rules are tests that run in Node and every surface + * (a chat with a bot, the Cat, a widget) takes its turns the same way: + * + * listening the microphone is open; what is heard is the person's turn + * thinking the turn was sent; the answer is on its way + * speaking the answer is being read aloud + * off nothing is open + * + * The loop is listening → thinking → speaking → listening. A person can + * always cut in: speaking + "interrupt" goes straight back to listening. + * The microphone is never left open by accident: two takes in a row with + * nothing in them end the call, and so does any problem, with its reason. + */ +/** Two empty takes in a row and the microphone closes. */ +export const VOICE_MODE_MAX_SILENT_TAKES = 2; +export const VOICE_MODE_OFF = { + phase: "off", + silentTakes: 0, + ended: null, + said: "", + answer: "", +}; +const over = (ended) => ({ ...VOICE_MODE_OFF, ended }); +export function voiceModeReducer(state, event) { + if (event.type === "start") { + return state.phase === "off" ? { ...VOICE_MODE_OFF, phase: "listening" } : state; + } + if (state.phase === "off") + return state; + switch (event.type) { + case "end": + return over("ended"); + case "problem": + return over("microphone"); + case "heard": { + if (state.phase !== "listening") + return state; + const text = event.text.trim(); + if (text) + return { ...state, phase: "thinking", silentTakes: 0, said: text, answer: "" }; + const silentTakes = state.silentTakes + 1; + return silentTakes >= VOICE_MODE_MAX_SILENT_TAKES + ? over("silence") + : { ...state, silentTakes }; + } + case "answer": { + if (state.phase !== "thinking") + return state; + const text = event.text.trim(); + return text ? { ...state, phase: "speaking", answer: text } : over("no-answer"); + } + case "no-answer": + return state.phase === "thinking" ? over("no-answer") : state; + case "spoken": + case "interrupt": + return state.phase === "speaking" ? { ...state, phase: "listening" } : state; + } +} +/** + * What each phase asks of the device. The hook does exactly this and nothing + * else, so the microphone and the voice can never both be open, and neither + * is open when the call is off. + */ +export function voiceModeWants(phase) { + return { microphone: phase === "listening", voice: phase === "speaking" }; +} +//# sourceMappingURL=voice-mode.js.map \ No newline at end of file diff --git a/dist/voice-mode.js.map b/dist/voice-mode.js.map new file mode 100644 index 0000000..14f8bb4 --- /dev/null +++ b/dist/voice-mode.js.map @@ -0,0 +1 @@ +{"version":3,"file":"voice-mode.js","sourceRoot":"","sources":["../src/voice-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAyCH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,KAAK,EAAE,KAAK;IACZ,WAAW,EAAE,CAAC;IACd,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,EAAE;IACR,MA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AAK,UAAU;gBAAE,OAAO,KAAK,CAAC;YAC7C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAClF,CAAC;QACD,KAAK,WAAW;YACd,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAChE,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW;YACd,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IACjF,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAqB;IAClD,OAAO,EAAE,UAAU,EAAE,KAAK,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,KAAK,UAAU,EAAE,CAAC;AAC5E,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 185003a..cbc109d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bitbaum/chatkit", - "version": "0.29.0", + "version": "0.30.0", "description": "One chat for every product: a composer with a microphone that always works, a thread that does not fight the reader, messages with copy and retry, LLM markdown, and a messenger for people and the agents among them \u2014 the fleet's chat standard as a package.", "license": "MIT", "author": "Cato", @@ -43,7 +43,8 @@ "bin", "styles.css", "styles/chat.css", - "styles/messenger.css" + "styles/messenger.css", + "styles/voice.css" ], "bin": { "chatkit-check-file-inputs": "./bin/chatkit-check-file-inputs.mjs", @@ -76,7 +77,8 @@ }, "./styles.css": "./styles.css", "./styles/chat.css": "./styles/chat.css", - "./styles/messenger.css": "./styles/messenger.css" + "./styles/messenger.css": "./styles/messenger.css", + "./styles/voice.css": "./styles/voice.css" }, "scripts": { "build": "node scripts/build-chat-css.mjs && rm -rf dist && tsc -p tsconfig.json", @@ -88,7 +90,7 @@ "format": "prettier --write .", "format:check": "prettier --check .", "demo": "esbuild demo/demo.tsx --bundle --jsx=automatic --format=iife --define:process.env.NODE_ENV='\"production\"' --outfile=demo/dist/demo.js --log-level=warning && esbuild demo/demo.tsx --bundle --jsx=automatic --format=iife --define:process.env.NODE_ENV='\"development\"' --outfile=demo/dist/demo-dev.js --log-level=warning", - "test:browser": "pnpm run demo && node test/browser.mjs && node test/browser-scroll.mjs && node test/browser-app.mjs && node test/browser-pdf.mjs && node test/browser-field.mjs && node test/browser-messenger.mjs" + "test:browser": "pnpm run demo && node test/browser.mjs && node test/browser-scroll.mjs && node test/browser-app.mjs && node test/browser-pdf.mjs && node test/browser-field.mjs && node test/browser-messenger.mjs && node test/browser-voice.mjs" }, "devDependencies": { "@bitbaum/design-tokens": "^1.5.2", diff --git a/scripts/build-chat-css.mjs b/scripts/build-chat-css.mjs index e42cf4a..4e5fb66 100644 --- a/scripts/build-chat-css.mjs +++ b/scripts/build-chat-css.mjs @@ -8,6 +8,8 @@ const outputPath = resolve(root, "styles/chat.css"); const messengerPath = resolve(root, "styles/messenger.css"); const appMarker = "/* ── ChatApp: the whole app"; const messengerMarker = "/* ── Messenger: people talking to people"; +const voiceMarker = "/* ── VoiceMode: a spoken conversation"; +const voicePath = resolve(root, "styles/voice.css"); const source = readFileSync(sourcePath, "utf8"); const boundary = source.indexOf(appMarker); const messenger = source.indexOf(messengerMarker); @@ -26,3 +28,11 @@ writeFileSync(outputPath, embedded); // the marks it shares with a chat) and the Messenger's own section, which is // last in styles.css so it runs to the end of the file. writeFileSync(messengerPath, embedded + "\n" + source.slice(messenger).trimEnd() + "\n"); + +// Voice mode alone, for an app that embeds only the chat sheet and offers a +// call: its section sits between ChatApp and the Messenger in styles.css. +const voice = source.indexOf(voiceMarker); +if (voice < boundary || voice > messenger) { + throw new Error(`Missing VoiceMode section between ChatApp and Messenger in ${sourcePath}`); +} +writeFileSync(voicePath, source.slice(voice, messenger).trimEnd() + "\n"); diff --git a/src/index.ts b/src/index.ts index 927619a..7306a0a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ export * from "./attachments.js"; export * from "./image.js"; export * from "./replies.js"; export * from "./speech.js"; +export * from "./voice-mode.js"; export * from "./rich.js"; export * from "./review.js"; export * from "./conversations.js"; diff --git a/src/react/VoiceMode.tsx b/src/react/VoiceMode.tsx new file mode 100644 index 0000000..f02400c --- /dev/null +++ b/src/react/VoiceMode.tsx @@ -0,0 +1,168 @@ +"use client"; + +import { useEffect, useRef } from "react"; +import type { DictationProblem } from "../dictation.js"; +import { plainTextForSpeech } from "../speech.js"; +import type { VoiceModeEnd, VoiceModePhase } from "../voice-mode.js"; +import { IconX } from "./icons.js"; +import { DEFAULT_DICTATION_MESSAGES } from "../dictation.js"; +import { useVoiceMode, type UseVoiceModeOptions } from "./use-voice-mode.js"; + +export type VoiceModeLabels = { + title: string; + /** Under the button, per phase: what is happening and what a press does. */ + listening: string; + thinking: string; + speaking: string; + /** The big button's name for a screen reader, per phase. */ + pressListening: string; + pressSpeaking: string; + pressThinking: string; + end: string; + again: string; + /** Why the call is over. */ + ended: Record, string>; + dictation: Record; +}; + +export const DEFAULT_VOICE_MODE_LABELS: VoiceModeLabels = { + dictation: DEFAULT_DICTATION_MESSAGES, + title: "Talk", + listening: "Listening. Tap when you have finished.", + thinking: "Thinking…", + speaking: "Tap to cut in.", + pressListening: "I have finished speaking", + pressSpeaking: "Stop reading and listen to me", + pressThinking: "Waiting for the answer", + end: "End", + again: "Talk again", + ended: { + silence: "Nothing was heard, so the microphone is closed.", + microphone: "The microphone stopped.", + "no-answer": "No answer came. Your words are in the chat; try again there.", + }, +}; + +export type VoiceModeProps = UseVoiceModeOptions & { + open: boolean; + onClose: () => void; + /** Who is being talked to, shown above the button. */ + name?: string; + labels?: Partial; +}; + +/** + * A spoken conversation, full screen: one big button, what was heard, what is + * being said back, and End. Open it from a tap (browsers open a microphone + * and a voice only inside one); closing it shuts both. + * + * The loop and its rules are `useVoiceMode` and `voiceModeReducer`. This is + * only the screen, so every chat that offers voice looks and behaves the same. + */ +export function VoiceMode({ open, onClose, name, labels: given, ...opts }: VoiceModeProps) { + const labels = { ...DEFAULT_VOICE_MODE_LABELS, ...given }; + const vm = useVoiceMode(opts); + const ref = useRef(null); + const { start, end, state } = vm; + + useEffect(() => { + const d = ref.current; + if (!d) return; + if (open && !d.open && typeof d.showModal === "function") { + d.showModal(); + start(); + } else if (!open && d.open) { + end(); + d.close(); + } + }, [open, start, end]); + // Unmounting ends the call too: a microphone that outlives its screen is the worst bug a chat can have. + useEffect(() => () => end(), [end]); + + const phase: VoiceModePhase = state.phase; + const line = + phase === "listening" + ? vm.dictation.liveText || labels.listening + : phase === "thinking" + ? state.said + : phase === "speaking" + ? plainTextForSpeech(state.answer) + : ""; + const reason = + state.ended && state.ended !== "ended" + ? vm.dictation.problem + ? labels.dictation[vm.dictation.problem] + : labels.ended[state.ended] + : null; + + return ( + { + end(); + onClose(); + }} + > +
+ {name ?? labels.title} + +
+ +
+ {phase === "off" ? ( + <> + {reason && ( +

+ {reason} +

+ )} + + + ) : ( + <> + +

+ {phase === "listening" + ? labels.listening + : phase === "thinking" + ? labels.thinking + : labels.speaking} +

+ {line && line !== labels.listening && ( +

+ {line} +

+ )} + + )} +
+ +
+ +
+
+ ); +} diff --git a/src/react/index.ts b/src/react/index.ts index 014906f..7d6c15c 100644 --- a/src/react/index.ts +++ b/src/react/index.ts @@ -61,6 +61,10 @@ export { Markdown, SourcesRow, defaultRenderLink, defaultRenderCitation } from " export { AnswerActions, DEFAULT_ANSWER_ACTIONS_LABELS } from "./AnswerActions.js"; export type { AnswerActionsLabels } from "./AnswerActions.js"; export { useSpeech } from "./use-speech.js"; +export { useVoiceMode } from "./use-voice-mode.js"; +export type { UseVoiceModeOptions, VoiceModeController } from "./use-voice-mode.js"; +export { VoiceMode, DEFAULT_VOICE_MODE_LABELS } from "./VoiceMode.js"; +export type { VoiceModeProps, VoiceModeLabels } from "./VoiceMode.js"; export type { SpeechController } from "./use-speech.js"; export { Sheet, prefersSheet } from "./Sheet.js"; export type { CitationMap, RenderLink, RenderCitation, RenderSources } from "./Markdown.js"; diff --git a/src/react/use-dictation.ts b/src/react/use-dictation.ts index 66afee3..ed23083 100644 --- a/src/react/use-dictation.ts +++ b/src/react/use-dictation.ts @@ -238,6 +238,8 @@ export function useDictation(opts: UseDictationOptions): DictationController { const recorderRef = useRef(null); const streamRef = useRef(null); const cancelledRef = useRef(false); + /** True from the request for a microphone until the browser answers it. */ + const openingRef = useRef(false); const capTimer = useRef | null>(null); const locale = useCallback(() => { @@ -333,16 +335,31 @@ export function useDictation(opts: UseDictationOptions): DictationController { setStatus("idle"); return; } + // One microphone at a time. `status` stays "idle" until the browser hands + // the microphone over, so a second start in that gap (a double tap, an + // effect that runs twice) used to open a second microphone and orphan the + // first: its track stayed live with nothing left to stop it. Found by + // voice mode's browser test, 2026-11-13. + if (openingRef.current) return; + openingRef.current = true; setProblem(null); cancelledRef.current = false; let stream: MediaStream; try { stream = await navigator.mediaDevices.getUserMedia({ audio: true }); } catch (e) { + openingRef.current = false; setProblem(problemForRecording(e)); setStatus("idle"); return; } + openingRef.current = false; + // Cancelled while the browser was still opening it: this microphone was + // never wanted, so it is closed here, where it arrives. + if (cancelledRef.current) { + for (const t of stream.getTracks()) t.stop(); + return; + } streamRef.current = stream; let rec: MediaRecorder; try { diff --git a/src/react/use-voice-mode.ts b/src/react/use-voice-mode.ts new file mode 100644 index 0000000..04bd4d6 --- /dev/null +++ b/src/react/use-voice-mode.ts @@ -0,0 +1,164 @@ +"use client"; + +import { useCallback, useEffect, useReducer, useRef } from "react"; +import { + VOICE_MODE_OFF, + voiceModeReducer, + voiceModeWants, + type VoiceModeState, +} from "../voice-mode.js"; +import type { Speaker } from "../speech.js"; +import { + useDictation, + type DictationController, + type UseDictationOptions, +} from "./use-dictation.js"; +import { useSpeech } from "./use-speech.js"; + +export type UseVoiceModeOptions = { + /** + * Send the person's turn and resolve with the answer's words (markdown is + * fine; it is flattened before it is read). Resolve with "" or reject when + * no answer came: the call then ends and says so. + */ + onTurn: (text: string) => Promise; + /** The same options the composer's microphone takes (`transcribeUrl`, `lang`…). */ + dictation?: Omit; + /** A studio voice; the browser's own voice when omitted. */ + speaker?: Speaker | null; +}; + +export type VoiceModeController = { + /** False where this device can neither listen nor speak. */ + supported: boolean; + state: VoiceModeState; + dictation: DictationController; + /** Open the call. Must run inside a tap: browsers open a microphone and a voice only then. */ + start: () => void; + end: () => void; + /** + * The one big button. Listening: "I have finished speaking". Speaking: cut + * in and listen again. Thinking: nothing to do. + */ + press: () => void; +}; + +/** + * A spoken conversation over any chat: listen, send, read the answer aloud, + * listen again (`voiceModeReducer` holds the rules). Where the browser's own + * recogniser runs, a pause ends the person's turn by itself; everywhere else + * a press of the button does, which is also how a person takes their time. + * + * The microphone and the voice follow the phase and nothing else + * (`voiceModeWants`), and both are shut when the component unmounts. + */ +export function useVoiceMode(opts: UseVoiceModeOptions): VoiceModeController { + const [state, dispatch] = useReducer(voiceModeReducer, VOICE_MODE_OFF); + const onTurn = useRef(opts.onTurn); + useEffect(() => { + onTurn.current = opts.onTurn; + }, [opts.onTurn]); + /** Guards against an answer that arrives after the call moved on. */ + const turn = useRef(0); + + const dictation = useDictation({ + // A pause should end the turn where the browser can hear one; a press + // ends it everywhere else. + prefer: "browser", + ...opts.dictation, + onText: (text) => dispatch({ type: "heard", text }), + }); + // The newest controller, for effects: set before any of them runs. + const dictationRef = useRef(dictation); + useEffect(() => { + dictationRef.current = dictation; + }); + const speech = useSpeech(opts.speaker); + const { microphone, voice } = voiceModeWants(state.phase); + + // The microphone follows the phase. + const micStatus = dictation.status; + useEffect(() => { + const d = dictationRef.current; + // Listening and the microphone is free: open it. This runs again when a + // take that held nothing has been written down (status back to idle), so + // a second take follows an empty first one. + if (microphone && micStatus === "idle") d.start(); + // Not the person's turn: a live take is thrown away. A take that is being + // written down is left alone; it is the turn on its way. + if (!microphone && micStatus === "listening") d.cancel(); + }, [microphone, micStatus, state.silentTakes]); + + // A microphone or transcription problem ends the call, with its reason on screen. + // "silence" is a take with nothing in it: the rules count those and close + // the microphone after two. Anything else is the microphone itself. + const problem = dictation.problem; + useEffect(() => { + if (!problem || state.phase === "off") return; + if (problem === "silence") { + dictationRef.current.clearProblem(); + dispatch({ type: "heard", text: "" }); + } else { + dispatch({ type: "problem" }); + } + }, [problem, state.phase]); + + // The turn is sent once, when the phase becomes "thinking". + useEffect(() => { + if (state.phase !== "thinking") return; + const mine = ++turn.current; + let live = true; + onTurn + .current(state.said) + .then((answer) => { + if (live && mine === turn.current) dispatch({ type: "answer", text: answer ?? "" }); + }) + .catch(() => { + if (live && mine === turn.current) dispatch({ type: "no-answer" }); + }); + return () => { + live = false; + }; + }, [state.phase, state.said]); + + // The voice follows the phase; when the reading ends, the person's turn begins. + const speechRef = useRef(speech); + useEffect(() => { + speechRef.current = speech; + }); + const reading = useRef(false); + useEffect(() => { + if (voice && state.answer) { + reading.current = false; + speechRef.current.speak(state.answer); + } else { + reading.current = false; + speechRef.current.stop(); + } + }, [voice, state.answer]); + useEffect(() => { + if (!voice) return; + if (speech.speaking) reading.current = true; + // Reading began and is over (or the device has no voice at all): listen. + else if (reading.current || !speech.supported) dispatch({ type: "spoken" }); + }, [voice, speech.speaking, speech.supported]); + + const start = useCallback(() => dispatch({ type: "start" }), []); + const end = useCallback(() => { + turn.current++; + dispatch({ type: "end" }); + }, []); + const press = useCallback(() => { + if (state.phase === "listening") dictationRef.current.stop(); + else if (state.phase === "speaking") dispatch({ type: "interrupt" }); + }, [state.phase]); + + return { + supported: dictation.supported, + state, + dictation, + start, + end, + press, + }; +} diff --git a/src/voice-mode.ts b/src/voice-mode.ts new file mode 100644 index 0000000..cd04b4c --- /dev/null +++ b/src/voice-mode.ts @@ -0,0 +1,110 @@ +/** + * Voice mode: talking with a chat instead of typing into it. + * + * The whole conversation is four states and the rules between them, as one + * pure function, so the rules are tests that run in Node and every surface + * (a chat with a bot, the Cat, a widget) takes its turns the same way: + * + * listening the microphone is open; what is heard is the person's turn + * thinking the turn was sent; the answer is on its way + * speaking the answer is being read aloud + * off nothing is open + * + * The loop is listening → thinking → speaking → listening. A person can + * always cut in: speaking + "interrupt" goes straight back to listening. + * The microphone is never left open by accident: two takes in a row with + * nothing in them end the call, and so does any problem, with its reason. + */ + +export type VoiceModePhase = "off" | "listening" | "thinking" | "speaking"; + +export type VoiceModeEnd = + /** The person ended it. */ + | "ended" + /** Nothing was heard, twice in a row. */ + | "silence" + /** The microphone or the transcription failed. */ + | "microphone" + /** The answer did not come. */ + | "no-answer"; + +export type VoiceModeState = { + phase: VoiceModePhase; + /** Takes in a row with nothing in them. */ + silentTakes: number; + /** Why the call is over, when it is; null while it runs or before it starts. */ + ended: VoiceModeEnd | null; + /** What the person last said, shown while the answer is on its way. */ + said: string; + /** What is being read aloud. */ + answer: string; +}; + +export type VoiceModeEvent = + | { type: "start" } + /** A take ended; `text` is what was heard ("" for nothing). */ + | { type: "heard"; text: string } + /** The answer to the turn that was sent. */ + | { type: "answer"; text: string } + /** The answer did not come (the send failed, or it came back empty). */ + | { type: "no-answer" } + /** The reading finished. */ + | { type: "spoken" } + /** The person cut in while the answer was being read. */ + | { type: "interrupt" } + | { type: "problem" } + | { type: "end" }; + +/** Two empty takes in a row and the microphone closes. */ +export const VOICE_MODE_MAX_SILENT_TAKES = 2; + +export const VOICE_MODE_OFF: VoiceModeState = { + phase: "off", + silentTakes: 0, + ended: null, + said: "", + answer: "", +}; + +const over = (ended: VoiceModeEnd): VoiceModeState => ({ ...VOICE_MODE_OFF, ended }); + +export function voiceModeReducer(state: VoiceModeState, event: VoiceModeEvent): VoiceModeState { + if (event.type === "start") { + return state.phase === "off" ? { ...VOICE_MODE_OFF, phase: "listening" } : state; + } + if (state.phase === "off") return state; + switch (event.type) { + case "end": + return over("ended"); + case "problem": + return over("microphone"); + case "heard": { + if (state.phase !== "listening") return state; + const text = event.text.trim(); + if (text) return { ...state, phase: "thinking", silentTakes: 0, said: text, answer: "" }; + const silentTakes = state.silentTakes + 1; + return silentTakes >= VOICE_MODE_MAX_SILENT_TAKES + ? over("silence") + : { ...state, silentTakes }; + } + case "answer": { + if (state.phase !== "thinking") return state; + const text = event.text.trim(); + return text ? { ...state, phase: "speaking", answer: text } : over("no-answer"); + } + case "no-answer": + return state.phase === "thinking" ? over("no-answer") : state; + case "spoken": + case "interrupt": + return state.phase === "speaking" ? { ...state, phase: "listening" } : state; + } +} + +/** + * What each phase asks of the device. The hook does exactly this and nothing + * else, so the microphone and the voice can never both be open, and neither + * is open when the call is off. + */ +export function voiceModeWants(phase: VoiceModePhase): { microphone: boolean; voice: boolean } { + return { microphone: phase === "listening", voice: phase === "speaking" }; +} diff --git a/styles.css b/styles.css index da0bd7c..ed809f8 100644 --- a/styles.css +++ b/styles.css @@ -2727,6 +2727,161 @@ a.ck-turn-chip:hover { } } +/* ── VoiceMode: a spoken conversation ───────────────────────────────────── + Its own section (and styles/voice.css) so a widget that embeds only the + chat sheet does not carry a full-screen call it never opens. */ +/* One big button whose look is + the phase (listening pulses, thinking waits, speaking is filled), the words + under it, and End. A native , so it is in the top layer everywhere. */ +.ck-voicemode { + position: fixed; + inset: 0; + width: 100%; + max-width: 100%; + height: 100%; + max-height: 100%; + margin: 0; + padding: 0; + border: 0; + background: var(--ck-bg); + color: var(--ck-fg); +} +.ck-voicemode[open] { + display: flex; + flex-direction: column; +} +.ck-voicemode::backdrop { + background: var(--ck-bg); +} +.ck-voicemode-top { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.75rem; +} +.ck-voicemode-name { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 1.0625rem; + font-weight: 600; +} +.ck-voicemode-body { + display: flex; + flex: 1; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 1.25rem; + min-height: 0; + padding: 1rem 1.5rem; + text-align: center; +} +.ck-voicemode-orb { + position: relative; + display: grid; + width: 9rem; + height: 9rem; + flex-shrink: 0; + place-items: center; + border: 2px solid var(--ck-accent); + border-radius: 999px; + background: var(--ck-accent-soft); + cursor: pointer; +} +.ck-voicemode-orb:disabled { + cursor: default; + border-color: var(--ck-line-2); + background: var(--ck-bg); +} +.ck-voicemode-orb[data-phase="speaking"] { + background: var(--ck-accent); +} +.ck-voicemode-orb:focus-visible { + outline: 2px solid var(--ck-accent); + outline-offset: 4px; +} +.ck-voicemode-ring { + position: absolute; + inset: -0.75rem; + border: 2px solid var(--ck-accent); + border-radius: 999px; + opacity: 0; +} +.ck-voicemode-orb[data-phase="listening"] .ck-voicemode-ring { + animation: ck-voicemode-ring 1.6s ease-out infinite; +} +.ck-voicemode-orb[data-phase="thinking"] .ck-voicemode-ring { + inset: 0.5rem; + border-color: var(--ck-fg-3); + border-top-color: transparent; + opacity: 1; + animation: ck-spin 1s linear infinite; +} +@keyframes ck-voicemode-ring { + from { + transform: scale(0.85); + opacity: 0.7; + } + to { + transform: scale(1.15); + opacity: 0; + } +} +.ck-voicemode-status { + margin: 0; + font-size: 0.9375rem; + color: var(--ck-fg-2); +} +.ck-voicemode-line { + max-width: 34rem; + max-height: 34vh; + margin: 0; + overflow-y: auto; + font-size: 1.125rem; + line-height: 1.5; + color: var(--ck-fg); +} +.ck-voicemode-line[data-phase="thinking"] { + color: var(--ck-fg-2); +} +.ck-voicemode-reason { + max-width: 28rem; + margin: 0; + font-size: 1rem; + line-height: 1.5; + color: var(--ck-fg); +} +.ck-voicemode-foot { + display: flex; + justify-content: center; + padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); +} +.ck-voicemode-end, +.ck-voicemode-again { + min-width: 8rem; + min-height: 2.75rem; + padding: 0 1.25rem; + border: 1px solid var(--ck-line-2); + border-radius: 999px; + background: var(--ck-bg); + color: var(--ck-fg); + font: inherit; + font-weight: 600; + cursor: pointer; +} +.ck-voicemode-again { + border-color: var(--ck-accent); +} +@media (prefers-reduced-motion: reduce) { + .ck-voicemode-orb .ck-voicemode-ring { + animation: none; + opacity: 0.6; + } +} + /* ── Messenger: people talking to people ─────────────────────────────────── After the ChatApp boundary, so the embedded styles/chat.css keeps its budget. styles/messenger.css is that embedded sheet plus this section: the diff --git a/styles/voice.css b/styles/voice.css new file mode 100644 index 0000000..4bc5889 --- /dev/null +++ b/styles/voice.css @@ -0,0 +1,154 @@ +/* ── VoiceMode: a spoken conversation ───────────────────────────────────── + Its own section (and styles/voice.css) so a widget that embeds only the + chat sheet does not carry a full-screen call it never opens. */ +/* One big button whose look is + the phase (listening pulses, thinking waits, speaking is filled), the words + under it, and End. A native , so it is in the top layer everywhere. */ +.ck-voicemode { + position: fixed; + inset: 0; + width: 100%; + max-width: 100%; + height: 100%; + max-height: 100%; + margin: 0; + padding: 0; + border: 0; + background: var(--ck-bg); + color: var(--ck-fg); +} +.ck-voicemode[open] { + display: flex; + flex-direction: column; +} +.ck-voicemode::backdrop { + background: var(--ck-bg); +} +.ck-voicemode-top { + display: flex; + align-items: center; + justify-content: space-between; + gap: 0.75rem; + padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 1rem 0.75rem; +} +.ck-voicemode-name { + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 1.0625rem; + font-weight: 600; +} +.ck-voicemode-body { + display: flex; + flex: 1; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 1.25rem; + min-height: 0; + padding: 1rem 1.5rem; + text-align: center; +} +.ck-voicemode-orb { + position: relative; + display: grid; + width: 9rem; + height: 9rem; + flex-shrink: 0; + place-items: center; + border: 2px solid var(--ck-accent); + border-radius: 999px; + background: var(--ck-accent-soft); + cursor: pointer; +} +.ck-voicemode-orb:disabled { + cursor: default; + border-color: var(--ck-line-2); + background: var(--ck-bg); +} +.ck-voicemode-orb[data-phase="speaking"] { + background: var(--ck-accent); +} +.ck-voicemode-orb:focus-visible { + outline: 2px solid var(--ck-accent); + outline-offset: 4px; +} +.ck-voicemode-ring { + position: absolute; + inset: -0.75rem; + border: 2px solid var(--ck-accent); + border-radius: 999px; + opacity: 0; +} +.ck-voicemode-orb[data-phase="listening"] .ck-voicemode-ring { + animation: ck-voicemode-ring 1.6s ease-out infinite; +} +.ck-voicemode-orb[data-phase="thinking"] .ck-voicemode-ring { + inset: 0.5rem; + border-color: var(--ck-fg-3); + border-top-color: transparent; + opacity: 1; + animation: ck-spin 1s linear infinite; +} +@keyframes ck-voicemode-ring { + from { + transform: scale(0.85); + opacity: 0.7; + } + to { + transform: scale(1.15); + opacity: 0; + } +} +.ck-voicemode-status { + margin: 0; + font-size: 0.9375rem; + color: var(--ck-fg-2); +} +.ck-voicemode-line { + max-width: 34rem; + max-height: 34vh; + margin: 0; + overflow-y: auto; + font-size: 1.125rem; + line-height: 1.5; + color: var(--ck-fg); +} +.ck-voicemode-line[data-phase="thinking"] { + color: var(--ck-fg-2); +} +.ck-voicemode-reason { + max-width: 28rem; + margin: 0; + font-size: 1rem; + line-height: 1.5; + color: var(--ck-fg); +} +.ck-voicemode-foot { + display: flex; + justify-content: center; + padding: 0.75rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px)); +} +.ck-voicemode-end, +.ck-voicemode-again { + min-width: 8rem; + min-height: 2.75rem; + padding: 0 1.25rem; + border: 1px solid var(--ck-line-2); + border-radius: 999px; + background: var(--ck-bg); + color: var(--ck-fg); + font: inherit; + font-weight: 600; + cursor: pointer; +} +.ck-voicemode-again { + border-color: var(--ck-accent); +} +@media (prefers-reduced-motion: reduce) { + .ck-voicemode-orb .ck-voicemode-ring { + animation: none; + opacity: 0.6; + } +} diff --git a/test/browser-voice.mjs b/test/browser-voice.mjs new file mode 100644 index 0000000..454007c --- /dev/null +++ b/test/browser-voice.mjs @@ -0,0 +1,205 @@ +// Voice mode, driven in a real browser with a real (fake-device) microphone. +// +// pnpm run demo && node test/browser-voice.mjs +// +// What each check is for: the call must open listening from a tap, a press +// must end the person's turn and send what was heard, the answer must be read +// (as prose, not markdown) and the floor handed back, a press while it reads +// must cut in, End must close the microphone and the voice, and every way a +// call can fail (nothing heard, no answer, a dead transcription) must end it +// with words on screen, never a silent open microphone. +import { createServer } from "node:http"; +import { readFile } from "node:fs/promises"; +import { extname, join, normalize } from "node:path"; +import { fileURLToPath } from "node:url"; +import { chromium } from "playwright"; + +const root = fileURLToPath(new URL("..", import.meta.url)); +const types = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css" }; +const server = createServer(async (req, res) => { + const path = normalize(join(root, decodeURIComponent(new URL(req.url, "http://x").pathname))); + if (!path.startsWith(root)) return res.writeHead(403).end(); + try { + const body = await readFile(path); + res + .writeHead(200, { "content-type": types[extname(path)] ?? "application/octet-stream" }) + .end(body); + } catch { + res.writeHead(404).end(); + } +}).listen(0); +const base = `http://localhost:${server.address().port}/demo/voice.html`; + +let failures = 0; +const check = (ok, what) => { + console.log(`${ok ? "PASS" : "FAIL"} ${what}`); + if (!ok) failures++; +}; + +const browser = await chromium.launch({ + ...(process.env.CHROMIUM_PATH ? { executablePath: process.env.CHROMIUM_PATH } : {}), + args: ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"], +}); + +/** A page with every microphone track it ever opened counted, so "closed" is a fact. */ +async function open(query, width = 390) { + const context = await browser.newContext({ + viewport: { width, height: 800 }, + permissions: ["microphone"], + }); + const page = await context.newPage(); + await page.addInitScript(() => { + window.__tracks = []; + const real = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices); + navigator.mediaDevices.getUserMedia = async (c) => { + const s = await real(c); + window.__tracks.push(...s.getTracks()); + return s; + }; + }); + await page.goto(`${base}?${query}`); + await page.click("#open-voice"); + return { context, page }; +} +const phase = (page) => + page.locator(".ck-voicemode-body").getAttribute("data-phase", { timeout: 5000 }); +const until = (page, want, ms = 8000) => + page.waitForSelector(`.ck-voicemode-body[data-phase="${want}"]`, { timeout: ms }); +const liveTracks = (page) => + page.evaluate(() => window.__tracks.filter((t) => t.readyState === "live").length); + +try { + // ── the loop ──────────────────────────────────────────────────────────── + { + const { context, page } = await open("voiceMs=1200"); + await until(page, "listening"); + check((await phase(page)) === "listening", "the call opens listening, from a tap"); + await page.waitForFunction(() => window.__tracks.length > 0); + check((await liveTracks(page)) > 0, "the microphone is open while listening"); + const orb = page.locator(".ck-voicemode-orb"); + const box = await orb.boundingBox(); + check(box && box.width >= 88 && box.height >= 88, "the button is a thumb's size and more"); + await page.waitForTimeout(700); + await orb.click(); + await until(page, "thinking"); + check( + (await page.locator(".ck-voicemode-line").innerText()).includes("what is next today"), + "what was heard is shown while the answer is on its way", + ); + check((await liveTracks(page)) === 0, "the microphone is closed while thinking"); + await until(page, "speaking"); + const line = await page.locator(".ck-voicemode-line").innerText(); + check( + line.includes("The report, at five.") && !line.includes("**"), + "the answer is shown as prose, not markdown", + ); + const spoken = await page.evaluate(() => window.__voice.spoken.at(-1)); + check(spoken === "The report, at five.", "and read aloud as prose"); + check((await liveTracks(page)) === 0, "the microphone is closed while the answer is read"); + await until(page, "listening"); + check( + (await page.evaluate(() => window.__voice.turns.length)) === 1, + "one turn was sent, once", + ); + check(true, "the floor goes back to the person when the reading ends"); + + // cut in + await page.waitForTimeout(700); + await orb.click(); + await until(page, "speaking"); + await orb.click(); + await until(page, "listening", 2000); + check( + (await page.evaluate(() => window.__voice.speaking)) === false, + "a press while it reads cuts in: the voice stops and it listens", + ); + + // end + await page.waitForFunction(() => window.__tracks.some((t) => t.readyState === "live")); + await page.locator(".ck-voicemode-end").click(); + await page.waitForFunction(() => !document.querySelector(".ck-voicemode")?.open); + await page.waitForTimeout(300); + check((await liveTracks(page)) === 0, "End closes the microphone"); + check((await page.evaluate(() => window.__voice.speaking)) === false, "and the voice"); + const overflow = await page.evaluate( + () => document.documentElement.scrollWidth > window.innerWidth + 1, + ); + check(!overflow, "nothing scrolls sideways at 390px"); + await context.close(); + } + + // ── nothing heard, twice ──────────────────────────────────────────────── + { + const { context, page } = await open("heard="); + const orb = page.locator(".ck-voicemode-orb"); + for (let i = 0; i < 2; i++) { + await until(page, "listening"); + await page.waitForTimeout(700); + await orb.click(); + await page.waitForTimeout(600); + } + await until(page, "off"); + check( + (await page.locator(".ck-voicemode-reason").innerText()).includes("Nothing was heard"), + "two empty takes close the call, and say why", + ); + const closed = await page + .waitForFunction(() => window.__tracks.every((t) => t.readyState !== "live"), null, { + timeout: 4000, + }) + .then(() => true) + .catch(() => false); + check(closed, "with the microphone closed"); + check( + (await page.evaluate(() => window.__voice.turns.length)) === 0, + "and nothing was sent for silence", + ); + await page.locator(".ck-voicemode-again").click(); + await until(page, "listening"); + check(true, "Talk again reopens it"); + await context.close(); + } + + // ── no answer ─────────────────────────────────────────────────────────── + { + const { context, page } = await open("answer="); + await until(page, "listening"); + await page.waitForTimeout(700); + await page.locator(".ck-voicemode-orb").click(); + await until(page, "off"); + check( + (await page.locator(".ck-voicemode-reason").innerText()).includes("No answer came"), + "an answer that never comes ends the call, and says so", + ); + await context.close(); + } + + // ── a dead transcription ──────────────────────────────────────────────── + { + const { context, page } = await open("fail=mic", 320); + await until(page, "listening"); + await page.waitForTimeout(700); + await page.locator(".ck-voicemode-orb").click(); + await until(page, "off"); + const reason = await page.locator(".ck-voicemode-reason").innerText(); + check( + reason.trim().length > 10, + `a failed transcription ends the call in words ("${reason.trim().slice(0, 60)}")`, + ); + await page.waitForTimeout(300); + check((await liveTracks(page)) === 0, "with the microphone closed"); + const overflow = await page.evaluate( + () => document.documentElement.scrollWidth > window.innerWidth + 1, + ); + check(!overflow, "nothing scrolls sideways at 320px"); + await context.close(); + } +} finally { + await browser.close(); + server.close(); +} +if (failures) { + console.error(`${failures} check(s) failed`); + process.exit(1); +} +console.log("voice mode: all checks passed"); diff --git a/test/voice-mode.test.js b/test/voice-mode.test.js new file mode 100644 index 0000000..a88d535 --- /dev/null +++ b/test/voice-mode.test.js @@ -0,0 +1,99 @@ +// Voice mode's rules: who has the floor, and when the microphone closes. +// The loop is listening → thinking → speaking → listening; a person can cut +// in; two empty takes or any problem end the call with its reason; and the +// microphone and the voice are never both open. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { + VOICE_MODE_MAX_SILENT_TAKES, + VOICE_MODE_OFF, + voiceModeReducer, + voiceModeWants, +} from "../dist/index.js"; + +const run = (events, from = VOICE_MODE_OFF) => events.reduce(voiceModeReducer, from); + +test("a call opens listening, and only from off", () => { + const s = run([{ type: "start" }]); + assert.equal(s.phase, "listening"); + assert.equal(run([{ type: "start" }], { ...s, phase: "speaking" }).phase, "speaking"); +}); + +test("what is heard is sent; the answer is read; then the person has the floor again", () => { + let s = run([{ type: "start" }, { type: "heard", text: " what is next? " }]); + assert.equal(s.phase, "thinking"); + assert.equal(s.said, "what is next?"); + s = run([{ type: "answer", text: "The report, at five." }], s); + assert.equal(s.phase, "speaking"); + assert.equal(s.answer, "The report, at five."); + s = run([{ type: "spoken" }], s); + assert.equal(s.phase, "listening"); +}); + +test("a person can cut in while the answer is read", () => { + const speaking = run([ + { type: "start" }, + { type: "heard", text: "hello" }, + { type: "answer", text: "A very long answer." }, + ]); + assert.equal(run([{ type: "interrupt" }], speaking).phase, "listening"); + // …but not while it is still thinking: there is nothing to cut into. + const thinking = run([{ type: "start" }, { type: "heard", text: "hello" }]); + assert.equal(run([{ type: "interrupt" }], thinking).phase, "thinking"); +}); + +test("empty takes in a row close the microphone, and say why", () => { + let s = run([{ type: "start" }]); + for (let i = 1; i < VOICE_MODE_MAX_SILENT_TAKES; i++) { + s = run([{ type: "heard", text: " " }], s); + assert.equal(s.phase, "listening", `still listening after ${i}`); + } + s = run([{ type: "heard", text: "" }], s); + assert.equal(s.phase, "off"); + assert.equal(s.ended, "silence"); +}); + +test("a take with words in it clears the count of empty ones", () => { + const s = run([ + { type: "start" }, + { type: "heard", text: "" }, + { type: "heard", text: "hello" }, + { type: "answer", text: "Hi." }, + { type: "spoken" }, + { type: "heard", text: "" }, + ]); + assert.equal(s.phase, "listening"); + assert.equal(s.silentTakes, 1); +}); + +test("no answer, an empty answer and a microphone problem each end the call with their reason", () => { + const thinking = run([{ type: "start" }, { type: "heard", text: "hello" }]); + assert.equal(run([{ type: "no-answer" }], thinking).ended, "no-answer"); + assert.equal(run([{ type: "answer", text: " " }], thinking).ended, "no-answer"); + assert.equal(run([{ type: "problem" }], thinking).ended, "microphone"); + assert.equal(run([{ type: "end" }], thinking).ended, "ended"); + for (const s of [run([{ type: "no-answer" }], thinking), run([{ type: "problem" }], thinking)]) { + assert.equal(s.phase, "off"); + } +}); + +test("events that belong to another phase change nothing", () => { + const listening = run([{ type: "start" }]); + assert.deepEqual(run([{ type: "answer", text: "late" }], listening), listening); + assert.deepEqual(run([{ type: "spoken" }], listening), listening); + const off = VOICE_MODE_OFF; + for (const e of [{ type: "heard", text: "x" }, { type: "answer", text: "x" }, { type: "end" }]) { + assert.deepEqual(run([e], off), off); + } +}); + +test("the microphone and the voice are never both open, and neither when the call is off", () => { + for (const phase of ["off", "listening", "thinking", "speaking"]) { + const w = voiceModeWants(phase); + assert.equal(w.microphone && w.voice, false, phase); + } + assert.deepEqual(voiceModeWants("off"), { microphone: false, voice: false }); + assert.deepEqual(voiceModeWants("thinking"), { microphone: false, voice: false }); + assert.deepEqual(voiceModeWants("listening"), { microphone: true, voice: false }); + assert.deepEqual(voiceModeWants("speaking"), { microphone: false, voice: true }); +});