Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

Drop on-device speech: asking Chrome about it crashed the tab

Yousseff1613e9a0681
diff --git a/src/app/privacy/page.tsx b/src/app/privacy/page.tsx
index fc37826..60bb39b 100644
--- a/src/app/privacy/page.tsx
+++ b/src/app/privacy/page.tsx
@@ -51,7 +51,7 @@ export default function Privacy() {
.
</li>
<li>
- <b>Your browser&apos;s speech service</b>, only when you turn on the voice and say &ldquo;next&rdquo;. Bygga never receives the audio, but your browser may send it to its maker to turn it into text: Google in Chrome, Apple in Safari. Where Chrome can listen on the device itself, Bygga asks it to.
+ <b>Your browser&apos;s speech service</b>, only when you turn on the voice and say &ldquo;next&rdquo;. Bygga never receives the audio, but your browser may send it to its maker to turn it into text: Google in Chrome, Apple in Safari.
</li>
</ul>
diff --git a/src/components/guide/hooks.ts b/src/components/guide/hooks.ts
index 6538890..8880c65 100644
--- a/src/components/guide/hooks.ts
+++ b/src/components/guide/hooks.ts
@@ -33,8 +33,6 @@ interface SR {
continuous: boolean;
interimResults: boolean;
lang: string;
- /** Chrome: recognise on the device instead of sending the audio to Google. */
- processLocally?: boolean;
start(): void;
stop(): void;
abort(): void;
@@ -67,15 +65,11 @@ export function useListener(enabled: boolean, onPhrase: (text: string, final: bo
useEffect(() => {
if (!enabled) return;
- type Avail = (o: { langs: string[]; processLocally: boolean }) => Promise<string>;
- const w = window as unknown as { SpeechRecognition?: (new () => SR) & { available?: Avail }; webkitSpeechRecognition?: new () => SR };
+ // on-device recognition (SpeechRecognition.available, processLocally) is left out on purpose:
+ // asking the browser whether it has a local model crashed the whole tab in Chromium
+ const w = window as unknown as { SpeechRecognition?: new () => SR; webkitSpeechRecognition?: new () => SR };
const Ctor = w.SpeechRecognition || w.webkitSpeechRecognition;
if (!Ctor) return;
- // where the browser already has an English model on the device, the audio never leaves it
- let local = false;
- w.SpeechRecognition?.available?.({ langs: ["en-US"], processLocally: true })
- .then((a) => void (local = a === "available"))
- .catch(() => {});
let stop = false;
let rec: SR | null = null;
let fails = 0;
@@ -89,7 +83,6 @@ export function useListener(enabled: boolean, onPhrase: (text: string, final: bo
rec.continuous = true;
rec.interimResults = true;
rec.lang = "en-US";
- if (local) rec.processLocally = true;
rec.onstart = () => {
fails = 0;
setMic("on");
@@ -115,8 +108,6 @@ export function useListener(enabled: boolean, onPhrase: (text: string, final: bo
timer = setTimeout(start, Math.min(4000, 250 * 2 ** fails));
};
rec.onerror = (e) => {
- // on-device recognition that trips up hands over to the browser's usual service on the next start
- if (local && rec?.processLocally && !["no-speech", "aborted", "not-allowed", "service-not-allowed"].includes(e.error)) local = false;
// a busy mic (a call, another app) is temporary: only a refusal, or a mic that stays busy, ends listening
if (e.error === "not-allowed" || e.error === "service-not-allowed" || (e.error === "audio-capture" && fails >= 4)) {
stop = true;