diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index c25f9ccab..0da777b12 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1430,14 +1430,6 @@ interface ServiceWorkerMessageEventInit extends EventInit { source?: ServiceWorker | MessagePort | null; } -interface SpeechSynthesisEventInit extends EventInit { - charIndex?: number; - charLength?: number; - elapsedTime?: number; - name?: string; - utterance?: SpeechSynthesisUtterance | null; -} - interface StereoPannerOptions extends AudioNodeOptions { pan?: number; } @@ -4463,6 +4455,9 @@ interface DocumentEvent { createEvent(eventInterface: "SVGZoomEvents"): SVGZoomEvent; createEvent(eventInterface: "SecurityPolicyViolationEvent"): SecurityPolicyViolationEvent; createEvent(eventInterface: "ServiceWorkerMessageEvent"): ServiceWorkerMessageEvent; + createEvent(eventInterface: "SpeechRecognitionError"): SpeechRecognitionError; + createEvent(eventInterface: "SpeechRecognitionEvent"): SpeechRecognitionEvent; + createEvent(eventInterface: "SpeechSynthesisErrorEvent"): SpeechSynthesisErrorEvent; createEvent(eventInterface: "SpeechSynthesisEvent"): SpeechSynthesisEvent; createEvent(eventInterface: "StorageEvent"): StorageEvent; createEvent(eventInterface: "TextEvent"): TextEvent; @@ -13669,6 +13664,130 @@ declare var SourceBufferList: { new(): SourceBufferList; }; +interface SpeechGrammar { + src: string; + weight: number; +} + +declare var SpeechGrammar: { + prototype: SpeechGrammar; + new(): SpeechGrammar; +}; + +interface SpeechGrammarList { + readonly length: number; + addFromString(string: string, weight?: number): void; + addFromURI(src: string, weight?: number): void; + item(index: number): SpeechGrammar; + [index: number]: SpeechGrammar; +} + +declare var SpeechGrammarList: { + prototype: SpeechGrammarList; + new(): SpeechGrammarList; +}; + +interface SpeechRecognitionEventMap { + "audioend": Event; + "audiostart": Event; + "end": Event; + "error": SpeechRecognitionError; + "nomatch": SpeechRecognitionEvent; + "result": SpeechRecognitionEvent; + "soundend": Event; + "soundstart": Event; + "speechend": Event; + "speechstart": Event; + "start": Event; +} + +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: SpeechRecognitionError) => 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; + serviceURI: string; + abort(): void; + start(): void; + stop(): void; + addEventListener(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; + removeEventListener(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; +} + +declare var SpeechRecognition: { + prototype: SpeechRecognition; + new(): SpeechRecognition; +}; + +interface SpeechRecognitionAlternative { + readonly confidence: number; + readonly transcript: string; +} + +declare var SpeechRecognitionAlternative: { + prototype: SpeechRecognitionAlternative; + new(): SpeechRecognitionAlternative; +}; + +interface SpeechRecognitionError extends Event { + readonly error: SpeechRecognitionErrorCode; + readonly message: string; +} + +declare var SpeechRecognitionError: { + prototype: SpeechRecognitionError; + new(): SpeechRecognitionError; +}; + +interface SpeechRecognitionEvent extends Event { + readonly emma: Document | null; + readonly interpretation: any; + readonly resultIndex: number; + readonly results: SpeechRecognitionResultList; +} + +declare var SpeechRecognitionEvent: { + prototype: SpeechRecognitionEvent; + new(): SpeechRecognitionEvent; +}; + +interface SpeechRecognitionResult { + readonly isFinal: boolean; + readonly length: number; + item(index: number): SpeechRecognitionAlternative; + [index: number]: SpeechRecognitionAlternative; +} + +declare var SpeechRecognitionResult: { + prototype: SpeechRecognitionResult; + new(): SpeechRecognitionResult; +}; + +interface SpeechRecognitionResultList { + readonly length: number; + item(index: number): SpeechRecognitionResult; + [index: number]: SpeechRecognitionResult; +} + +declare var SpeechRecognitionResultList: { + prototype: SpeechRecognitionResultList; + new(): SpeechRecognitionResultList; +}; + interface SpeechSynthesisEventMap { "voiceschanged": Event; } @@ -13694,9 +13813,17 @@ declare var SpeechSynthesis: { new(): SpeechSynthesis; }; +interface SpeechSynthesisErrorEvent extends SpeechSynthesisEvent { + readonly error: SpeechSynthesisErrorCode; +} + +declare var SpeechSynthesisErrorEvent: { + prototype: SpeechSynthesisErrorEvent; + new(): SpeechSynthesisErrorEvent; +}; + interface SpeechSynthesisEvent extends Event { readonly charIndex: number; - readonly charLength: number; readonly elapsedTime: number; readonly name: string; readonly utterance: SpeechSynthesisUtterance; @@ -13704,28 +13831,28 @@ interface SpeechSynthesisEvent extends Event { declare var SpeechSynthesisEvent: { prototype: SpeechSynthesisEvent; - new(type: string, eventInitDict?: SpeechSynthesisEventInit): SpeechSynthesisEvent; + new(): SpeechSynthesisEvent; }; interface SpeechSynthesisUtteranceEventMap { - "boundary": Event; - "end": Event; - "error": Event; - "mark": Event; - "pause": Event; - "resume": Event; - "start": Event; + "boundary": SpeechSynthesisEvent; + "end": SpeechSynthesisEvent; + "error": SpeechSynthesisErrorEvent; + "mark": SpeechSynthesisEvent; + "pause": SpeechSynthesisEvent; + "resume": SpeechSynthesisEvent; + "start": SpeechSynthesisEvent; } interface SpeechSynthesisUtterance extends EventTarget { lang: string; - onboundary: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onend: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onerror: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onmark: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onpause: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onresume: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; - onstart: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null; + onboundary: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; + onend: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; + onerror: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisErrorEvent) => any) | null; + onmark: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; + onpause: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; + onresume: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; + onstart: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null; pitch: number; rate: number; text: string; @@ -16968,6 +17095,8 @@ type ScrollSetting = "" | "up"; type SelectionMode = "select" | "start" | "end" | "preserve"; type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant"; type ServiceWorkerUpdateViaCache = "imports" | "all" | "none"; +type SpeechRecognitionErrorCode = "no-speech" | "aborted" | "audio-capture" | "network" | "not-allowed" | "service-not-allowed" | "bad-grammar" | "language-not-supported"; +type SpeechSynthesisErrorCode = "canceled" | "interrupted" | "audio-busy" | "audio-hardware" | "network" | "synthesis-unavailable" | "synthesis-failed" | "language-unavailable" | "voice-unavailable" | "text-too-long" | "invalid-argument"; type TextTrackKind = "subtitles" | "captions" | "descriptions" | "chapters" | "metadata"; type TextTrackMode = "disabled" | "hidden" | "showing"; type TouchType = "direct" | "stylus"; diff --git a/baselines/dom.iterable.generated.d.ts b/baselines/dom.iterable.generated.d.ts index b22be97c1..b4df662c0 100644 --- a/baselines/dom.iterable.generated.d.ts +++ b/baselines/dom.iterable.generated.d.ts @@ -152,6 +152,18 @@ interface SourceBufferList { [Symbol.iterator](): IterableIterator; } +interface SpeechGrammarList { + [Symbol.iterator](): IterableIterator; +} + +interface SpeechRecognitionResult { + [Symbol.iterator](): IterableIterator; +} + +interface SpeechRecognitionResultList { + [Symbol.iterator](): IterableIterator; +} + interface StyleSheetList { [Symbol.iterator](): IterableIterator; } diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index ad2493bed..38869680c 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -1076,6 +1076,62 @@ }, "no-interface-object": "1" }, + "SpeechRecognition": { + "events": { + "event": [ + { + "name": "result", + "type": "SpeechRecognitionEvent" + }, + { + "name": "nomatch", + "type": "SpeechRecognitionEvent" + }, + { + "name": "error", + "type": "SpeechRecognitionError" + }, + { + "name": "end", + "type": "Event" + } + ] + } + }, + "SpeechSynthesisUtterance": { + "events": { + "event": [ + { + "name": "start", + "type": "SpeechSynthesisEvent" + }, + { + "name": "end", + "type": "SpeechSynthesisEvent" + }, + { + "name": "error", + "type": "SpeechSynthesisErrorEvent" + }, + { + "name": "pause", + "type": "SpeechSynthesisEvent" + }, + { + "name": "resume", + "type": "SpeechSynthesisEvent" + }, + { + "name": "mark", + "type": "SpeechSynthesisEvent" + }, + { + "name": "boundary", + "type": "SpeechSynthesisEvent" + } + ] + } + }, "SVGElement": { "implements": ["GlobalEventHandlers", "DocumentAndElementEventHandlers"] }, diff --git a/inputfiles/idl/Web Speech API.widl b/inputfiles/idl/Web Speech API.widl new file mode 100644 index 000000000..c14edc323 --- /dev/null +++ b/inputfiles/idl/Web Speech API.widl @@ -0,0 +1,169 @@ +[Exposed=Window, Constructor] +interface SpeechRecognition : EventTarget { + // recognition parameters + attribute SpeechGrammarList grammars; + attribute DOMString lang; + attribute boolean continuous; + attribute boolean interimResults; + attribute unsigned long maxAlternatives; + attribute DOMString serviceURI; + + // methods to drive the speech interaction + void start(); + void stop(); + void abort(); + + // event methods + attribute EventHandler onaudiostart; + attribute EventHandler onsoundstart; + attribute EventHandler onspeechstart; + attribute EventHandler onspeechend; + attribute EventHandler onsoundend; + attribute EventHandler onaudioend; + attribute EventHandler onresult; + attribute EventHandler onnomatch; + attribute EventHandler onerror; + attribute EventHandler onstart; + attribute EventHandler onend; +}; + +enum SpeechRecognitionErrorCode { + "no-speech", + "aborted", + "audio-capture", + "network", + "not-allowed", + "service-not-allowed", + "bad-grammar", + "language-not-supported" +}; + +[Exposed=Window] +interface SpeechRecognitionError : Event { + readonly attribute SpeechRecognitionErrorCode error; + readonly attribute DOMString message; +}; + +// Item in N-best list +[Exposed=Window] +interface SpeechRecognitionAlternative { + readonly attribute DOMString transcript; + readonly attribute float confidence; +}; + +// A complete one-shot simple response +[Exposed=Window] +interface SpeechRecognitionResult { + readonly attribute unsigned long length; + getter SpeechRecognitionAlternative item(unsigned long index); + readonly attribute boolean isFinal; +}; + +// A collection of responses (used in continuous mode) +[Exposed=Window] +interface SpeechRecognitionResultList { + readonly attribute unsigned long length; + getter SpeechRecognitionResult item(unsigned long index); +}; + +// A full response, which could be interim or final, part of a continuous response or not +[Exposed=Window] +interface SpeechRecognitionEvent : Event { + readonly attribute unsigned long resultIndex; + readonly attribute SpeechRecognitionResultList results; + readonly attribute any interpretation; + readonly attribute Document? emma; +}; + +// The object representing a speech grammar +[Exposed=Window, Constructor] +interface SpeechGrammar { + attribute DOMString src; + attribute float weight; +}; + +// The object representing a speech grammar collection +[Exposed=Window, Constructor] +interface SpeechGrammarList { + readonly attribute unsigned long length; + getter SpeechGrammar item(unsigned long index); + void addFromURI(DOMString src, + optional float weight); + void addFromString(DOMString string, + optional float weight); +}; + +[Exposed=Window] +interface SpeechSynthesis : EventTarget { + readonly attribute boolean pending; + readonly attribute boolean speaking; + readonly attribute boolean paused; + + attribute EventHandler onvoiceschanged; + + void speak(SpeechSynthesisUtterance utterance); + void cancel(); + void pause(); + void resume(); + sequence getVoices(); +}; + +partial interface Window { + [SameObject] readonly attribute SpeechSynthesis speechSynthesis; +}; + +[Exposed=Window, + Constructor, + Constructor(DOMString text)] +interface SpeechSynthesisUtterance : EventTarget { + attribute DOMString text; + attribute DOMString lang; + attribute SpeechSynthesisVoice voice; + attribute float volume; + attribute float rate; + attribute float pitch; + + attribute EventHandler onstart; + attribute EventHandler onend; + attribute EventHandler onerror; + attribute EventHandler onpause; + attribute EventHandler onresume; + attribute EventHandler onmark; + attribute EventHandler onboundary; +}; + +[Exposed=Window] +interface SpeechSynthesisEvent : Event { + readonly attribute SpeechSynthesisUtterance utterance; + readonly attribute unsigned long charIndex; + readonly attribute float elapsedTime; + readonly attribute DOMString name; +}; + +enum SpeechSynthesisErrorCode { + "canceled", + "interrupted", + "audio-busy", + "audio-hardware", + "network", + "synthesis-unavailable", + "synthesis-failed", + "language-unavailable", + "voice-unavailable", + "text-too-long", + "invalid-argument", +}; + +[Exposed=Window] +interface SpeechSynthesisErrorEvent : SpeechSynthesisEvent { + readonly attribute SpeechSynthesisErrorCode error; +}; + +[Exposed=Window] +interface SpeechSynthesisVoice { + readonly attribute DOMString voiceURI; + readonly attribute DOMString name; + readonly attribute DOMString lang; + readonly attribute boolean localService; + readonly attribute boolean default; +}; diff --git a/inputfiles/idlSources.json b/inputfiles/idlSources.json index ad4f81787..ae713275f 100644 --- a/inputfiles/idlSources.json +++ b/inputfiles/idlSources.json @@ -230,6 +230,10 @@ "url": "https://w3c.github.io/webrtc-pc/", "title": "WebRTC" }, + { + "url": "https://w3c.github.io/speech-api/", + "title": "Web Speech API" + }, { "url": "https://www.w3.org/TR/webvtt1/", "title": "WebVTT"