UNPKG

@stacksjs/stx

Version:

A performant UI Framework. Powered by Bun.

117 lines 3.42 kB
/** * Check if Speech Recognition is supported */ export declare function isSpeechRecognitionSupported(): boolean; /** * Create a speech recognition composable */ export declare function useSpeechRecognition(options?: SpeechRecognitionOptions): SpeechRecognitionRef; /** * Check if Speech Synthesis is supported */ export declare function isSpeechSynthesisSupported(): boolean; /** * Create a speech synthesis composable */ export declare function useSpeechSynthesis(defaultOptions?: SpeechSynthesisOptions): SpeechSynthesisRef; /** * Simple speak function */ export declare function speak(text: string, options?: SpeechSynthesisOptions): void; /** * Stop all speech */ export declare function stopSpeaking(): void; /** * Get available voices */ export declare function getVoices(): SpeechSynthesisVoice[]; /** * useSpeech - Web Speech API wrappers * * Speech recognition and synthesis for voice-enabled applications. * * @example * ```ts * // Speech Recognition * const recognition = useSpeechRecognition({ * continuous: false, * interimResults: true, * lang: 'en-US' * }) * * recognition.subscribe(state => { * console.log('Transcript:', state.transcript) * console.log('Is listening:', state.isListening) * }) * * recognition.start() * * // Speech Synthesis * const speech = useSpeechSynthesis() * speech.speak('Hello, world!') * ``` */ // ============================================================================ // Speech Recognition // ============================================================================ export declare interface SpeechRecognitionOptions { continuous?: boolean interimResults?: boolean lang?: string maxAlternatives?: number grammars?: SpeechGrammarList } export declare interface SpeechRecognitionState { isListening: boolean transcript: string finalTranscript: string interimTranscript: string confidence: number isSupported: boolean error: string | null } export declare interface SpeechRecognitionResult { transcript: string confidence: number isFinal: boolean } export declare interface SpeechRecognitionRef { get: () => SpeechRecognitionState subscribe: (fn: (state: SpeechRecognitionState) => void) => () => void start: () => void stop: () => void abort: () => void toggle: () => void isSupported: () => boolean on: (event: 'result' | 'error' | 'start' | 'end', callback: (data?: any) => void) => () => void } // ============================================================================ // Speech Synthesis // ============================================================================ export declare interface SpeechSynthesisOptions { voice?: string | number rate?: number pitch?: number volume?: number lang?: string } export declare interface SpeechSynthesisState { isSpeaking: boolean isPaused: boolean isSupported: boolean voices: SpeechSynthesisVoice[] currentText: string } export declare interface SpeechSynthesisRef { get: () => SpeechSynthesisState subscribe: (fn: (state: SpeechSynthesisState) => void) => () => void speak: (text: string, options?: SpeechSynthesisOptions) => void stop: () => void pause: () => void resume: () => void toggle: () => void getVoices: () => SpeechSynthesisVoice[] isSupported: () => boolean on: (event: 'start' | 'end' | 'pause' | 'resume' | 'error', callback: (data?: any) => void) => () => void }