mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-25 12:16:00 +08:00
Switches the voice proxy to the OpenAI audio API (/v1/audio/transcriptions and /v1/audio/speech) so it works with OpenAI, Groq, or a local server. Adds a Settings -> Voice tab (base URL, API key, models, voice) plus a Quick Settings toggle, and removes the bundled Python sidecar. Review fixes: stop mic tracks on unmount, clear the global TTS stop handler and revoke leaked blob URLs, add fetch timeouts in the proxy, surface mic errors in the button, trim before appending transcripts, and drop the repo-wide wav ignore.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
// Voice UI is gated on the `voiceEnabled` UI preference (toggled in Quick Settings /
|
|
// the Settings modal). This is a lightweight read-only view of that preference so the
|
|
// mic/speak controls can hide themselves, kept in sync via the same events
|
|
// useUiPreferences emits. No server probe.
|
|
const STORAGE_KEY = 'uiPreferences';
|
|
const SYNC_EVENT = 'ui-preferences:sync';
|
|
|
|
function readVoiceEnabled(): boolean {
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
if (!raw) return false;
|
|
const parsed = JSON.parse(raw);
|
|
return parsed?.voiceEnabled === true || parsed?.voiceEnabled === 'true';
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function useVoiceAvailable(): boolean {
|
|
const [enabled, setEnabled] = useState<boolean>(() =>
|
|
typeof window === 'undefined' ? false : readVoiceEnabled(),
|
|
);
|
|
|
|
useEffect(() => {
|
|
const update = () => setEnabled(readVoiceEnabled());
|
|
window.addEventListener('storage', update);
|
|
window.addEventListener(SYNC_EVENT, update as EventListener);
|
|
return () => {
|
|
window.removeEventListener('storage', update);
|
|
window.removeEventListener(SYNC_EVENT, update as EventListener);
|
|
};
|
|
}, []);
|
|
|
|
return enabled;
|
|
}
|