@bitrix24/b24ui-nuxt
Version:
Bitrix24 UI-Kit for developing web applications REST API for NUXT & VUE
123 lines (122 loc) • 5.23 kB
TypeScript
import type { Ref, DeepReadonly } from 'vue';
/**
* Speech recognition Web API types
* @see /bitrix/js/im/v2/component/textarea/src/components/audio-input/classes/audio-manager.js
*/
export type SpeechRecognitionErrorCode = 'aborted' | 'audio-capture' | 'bad-grammar' | 'language-not-supported' | 'network' | 'no-speech' | 'not-allowed' | 'service-not-allowed';
interface SpeechGrammar {
src: string;
weight: number;
}
interface SpeechGrammarList {
readonly length: number;
addFromString: (string: string, weight?: number) => void;
addFromURI: (src: string, weight?: number) => void;
item: (index: number) => SpeechGrammar;
[index: number]: SpeechGrammar;
}
export interface SpeechRecognitionErrorEvent extends Event {
readonly error: SpeechRecognitionErrorCode;
readonly message: string;
}
interface SpeechRecognitionEvent extends Event {
readonly resultIndex: number;
readonly results: SpeechRecognitionResultList;
}
interface SpeechRecognitionEventMap {
audioend: Event;
audiostart: Event;
end: Event;
error: SpeechRecognitionErrorEvent;
nomatch: SpeechRecognitionEvent;
result: SpeechRecognitionEvent;
soundend: Event;
soundstart: Event;
speechend: Event;
speechstart: Event;
start: Event;
}
export interface SpeechRecognition extends EventTarget {
continuous: boolean;
grammars: SpeechGrammarList;
interimResults: boolean;
lang: string;
maxAlternatives: number;
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
onerror: ((this: SpeechRecognition, ev: SpeechRecognitionErrorEvent) => any) | null;
onnomatch: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
onresult: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null;
onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null;
onspeechend: ((this: SpeechRecognition, ev: Event) => any) | null;
onspeechstart: ((this: SpeechRecognition, ev: Event) => any) | null;
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
abort: () => void;
start: () => void;
stop: () => void;
addEventListener: (<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void);
removeEventListener: (<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | EventListenerOptions) => void) & ((type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void);
}
export interface SpeechRecognitionOptions {
/** Recognition language (default: 'en-US') */
lang?: string;
/** Continuous recognition (default: true) */
continuous?: boolean;
/** Interim results (default: true) */
interimResults?: boolean;
/** Максимальное количество альтернатив (по умолчанию: 1) */
maxAlternatives?: number;
}
export interface SpeechRecognitionResult {
/** Recognized text */
text: string;
}
export interface SpeechRecognitionState {
/** Whether speech recognition is available in the browser */
isAvailable: boolean;
/** Whether recognition is currently active */
isListening: boolean;
/** All recognized text (accumulated if continuous mode) */
lastRecognizedText: string;
}
export interface SpeechRecognitionControls {
/** Start recognition */
start: () => Promise<boolean>;
/** Stop recognition */
stop: () => Promise<boolean>;
/** Toggle recognition state */
toggle: () => Promise<boolean>;
/** Set recognition language */
setLanguage: (lang: string) => boolean;
}
export interface SpeechRecognitionEvents {
/** Called when recognition starts */
onStart?: () => void;
/** Called when recognition ends */
onEnd?: () => void;
/** Called on error */
onError?: (error: string) => void;
/** Called when a result is received */
onResult?: (result: SpeechRecognitionResult) => void;
}
/**
* Universal composable for speech recognition
* Can be used with any input components (Input, Textarea, etc.)
*/
export declare function useSpeechRecognition(options?: SpeechRecognitionOptions, events?: SpeechRecognitionEvents): {
state: DeepReadonly<Ref<SpeechRecognitionState>>;
isAvailable: import("vue").ComputedRef<boolean>;
isListening: import("vue").ComputedRef<boolean>;
start: () => Promise<boolean>;
stop: () => Promise<boolean>;
toggle: () => Promise<boolean>;
setLanguage: (lang: string) => boolean;
recognizer: SpeechRecognition | undefined;
};
/**
* Return type of useSpeechRecognition
*/
export type UseSpeechRecognitionReturn = ReturnType<typeof useSpeechRecognition>;
export {};