Skip to content

Commit 1f859dd

Browse files
saschanazsandersn
authored andcommitted
Update Web Speech types (#764)
1 parent 7d1216f commit 1f859dd

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

baselines/dom.generated.d.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,18 @@ interface ShadowRootInit {
16841684
mode: ShadowRootMode;
16851685
}
16861686

1687+
interface SpeechSynthesisErrorEventInit extends SpeechSynthesisEventInit {
1688+
error: SpeechSynthesisErrorCode;
1689+
}
1690+
1691+
interface SpeechSynthesisEventInit extends EventInit {
1692+
charIndex?: number;
1693+
charLength?: number;
1694+
elapsedTime?: number;
1695+
name?: string;
1696+
utterance: SpeechSynthesisUtterance;
1697+
}
1698+
16871699
interface StaticRangeInit {
16881700
endContainer: Node;
16891701
endOffset: number;
@@ -4831,7 +4843,6 @@ interface Document extends Node, DocumentAndElementEventHandlers, DocumentOrShad
48314843
createEvent(eventInterface: "SVGZoomEvents"): SVGZoomEvent;
48324844
createEvent(eventInterface: "SecurityPolicyViolationEvent"): SecurityPolicyViolationEvent;
48334845
createEvent(eventInterface: "ServiceWorkerMessageEvent"): ServiceWorkerMessageEvent;
4834-
createEvent(eventInterface: "SpeechRecognitionError"): SpeechRecognitionError;
48354846
createEvent(eventInterface: "SpeechRecognitionEvent"): SpeechRecognitionEvent;
48364847
createEvent(eventInterface: "SpeechSynthesisErrorEvent"): SpeechSynthesisErrorEvent;
48374848
createEvent(eventInterface: "SpeechSynthesisEvent"): SpeechSynthesisEvent;
@@ -5081,7 +5092,6 @@ interface DocumentEvent {
50815092
createEvent(eventInterface: "SVGZoomEvents"): SVGZoomEvent;
50825093
createEvent(eventInterface: "SecurityPolicyViolationEvent"): SecurityPolicyViolationEvent;
50835094
createEvent(eventInterface: "ServiceWorkerMessageEvent"): ServiceWorkerMessageEvent;
5084-
createEvent(eventInterface: "SpeechRecognitionError"): SpeechRecognitionError;
50855095
createEvent(eventInterface: "SpeechRecognitionEvent"): SpeechRecognitionEvent;
50865096
createEvent(eventInterface: "SpeechSynthesisErrorEvent"): SpeechSynthesisErrorEvent;
50875097
createEvent(eventInterface: "SpeechSynthesisEvent"): SpeechSynthesisEvent;
@@ -15250,7 +15260,7 @@ interface SpeechRecognitionEventMap {
1525015260
"audioend": Event;
1525115261
"audiostart": Event;
1525215262
"end": Event;
15253-
"error": SpeechRecognitionError;
15263+
"error": Event;
1525415264
"nomatch": SpeechRecognitionEvent;
1525515265
"result": SpeechRecognitionEvent;
1525615266
"soundend": Event;
@@ -15269,15 +15279,14 @@ interface SpeechRecognition extends EventTarget {
1526915279
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
1527015280
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
1527115281
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
15272-
onerror: ((this: SpeechRecognition, ev: SpeechRecognitionError) => any) | null;
15282+
onerror: ((this: SpeechRecognition, ev: Event) => any) | null;
1527315283
onnomatch: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
1527415284
onresult: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
1527515285
onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null;
1527615286
onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null;
1527715287
onspeechend: ((this: SpeechRecognition, ev: Event) => any) | null;
1527815288
onspeechstart: ((this: SpeechRecognition, ev: Event) => any) | null;
1527915289
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
15280-
serviceURI: string;
1528115290
abort(): void;
1528215291
start(): void;
1528315292
stop(): void;
@@ -15302,19 +15311,7 @@ declare var SpeechRecognitionAlternative: {
1530215311
new(): SpeechRecognitionAlternative;
1530315312
};
1530415313

15305-
interface SpeechRecognitionError extends Event {
15306-
readonly error: SpeechRecognitionErrorCode;
15307-
readonly message: string;
15308-
}
15309-
15310-
declare var SpeechRecognitionError: {
15311-
prototype: SpeechRecognitionError;
15312-
new(): SpeechRecognitionError;
15313-
};
15314-
1531515314
interface SpeechRecognitionEvent extends Event {
15316-
readonly emma: Document | null;
15317-
readonly interpretation: any;
1531815315
readonly resultIndex: number;
1531915316
readonly results: SpeechRecognitionResultList;
1532015317
}
@@ -15379,20 +15376,21 @@ interface SpeechSynthesisErrorEvent extends SpeechSynthesisEvent {
1537915376

1538015377
declare var SpeechSynthesisErrorEvent: {
1538115378
prototype: SpeechSynthesisErrorEvent;
15382-
new(): SpeechSynthesisErrorEvent;
15379+
new(type: string, eventInitDict: SpeechSynthesisErrorEventInit): SpeechSynthesisErrorEvent;
1538315380
};
1538415381

1538515382
/** This Web Speech API interface contains information about the current state of SpeechSynthesisUtterance objects that have been processed in the speech service. */
1538615383
interface SpeechSynthesisEvent extends Event {
1538715384
readonly charIndex: number;
15385+
readonly charLength: number;
1538815386
readonly elapsedTime: number;
1538915387
readonly name: string;
1539015388
readonly utterance: SpeechSynthesisUtterance;
1539115389
}
1539215390

1539315391
declare var SpeechSynthesisEvent: {
1539415392
prototype: SpeechSynthesisEvent;
15395-
new(): SpeechSynthesisEvent;
15393+
new(type: string, eventInitDict: SpeechSynthesisEventInit): SpeechSynthesisEvent;
1539615394
};
1539715395

1539815396
interface SpeechSynthesisUtteranceEventMap {
@@ -15418,7 +15416,7 @@ interface SpeechSynthesisUtterance extends EventTarget {
1541815416
pitch: number;
1541915417
rate: number;
1542015418
text: string;
15421-
voice: SpeechSynthesisVoice;
15419+
voice: SpeechSynthesisVoice | null;
1542215420
volume: number;
1542315421
addEventListener<K extends keyof SpeechSynthesisUtteranceEventMap>(type: K, listener: (this: SpeechSynthesisUtterance, ev: SpeechSynthesisUtteranceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
1542415422
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
@@ -15428,8 +15426,7 @@ interface SpeechSynthesisUtterance extends EventTarget {
1542815426

1542915427
declare var SpeechSynthesisUtterance: {
1543015428
prototype: SpeechSynthesisUtterance;
15431-
new(): SpeechSynthesisUtterance;
15432-
new(text: string): SpeechSynthesisUtterance;
15429+
new(text?: string): SpeechSynthesisUtterance;
1543315430
};
1543415431

1543515432
/** This Web Speech API interface represents a voice that the system supports. Every SpeechSynthesisVoice has its own relative speech service including information about language, name and URI. */
@@ -20150,8 +20147,7 @@ type SelectionMode = "end" | "preserve" | "select" | "start";
2015020147
type ServiceWorkerState = "activated" | "activating" | "installed" | "installing" | "parsed" | "redundant";
2015120148
type ServiceWorkerUpdateViaCache = "all" | "imports" | "none";
2015220149
type ShadowRootMode = "closed" | "open";
20153-
type SpeechRecognitionErrorCode = "aborted" | "audio-capture" | "bad-grammar" | "language-not-supported" | "network" | "no-speech" | "not-allowed" | "service-not-allowed";
20154-
type SpeechSynthesisErrorCode = "audio-busy" | "audio-hardware" | "canceled" | "interrupted" | "invalid-argument" | "language-unavailable" | "network" | "synthesis-failed" | "synthesis-unavailable" | "text-too-long" | "voice-unavailable";
20150+
type SpeechSynthesisErrorCode = "audio-busy" | "audio-hardware" | "canceled" | "interrupted" | "invalid-argument" | "language-unavailable" | "network" | "not-allowed" | "synthesis-failed" | "synthesis-unavailable" | "text-too-long" | "voice-unavailable";
2015520151
type SupportedType = "application/xhtml+xml" | "application/xml" | "image/svg+xml" | "text/html" | "text/xml";
2015620152
type TextTrackKind = "captions" | "chapters" | "descriptions" | "metadata" | "subtitles";
2015720153
type TextTrackMode = "disabled" | "hidden" | "showing";

inputfiles/addedTypes.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@
10181018
},
10191019
{
10201020
"name": "error",
1021-
"type": "SpeechRecognitionError"
1021+
"type": "Event"
10221022
},
10231023
{
10241024
"name": "end",

inputfiles/idl/Web Speech API.widl

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
[Exposed=Window, Constructor]
1+
[Exposed=Window]
22
interface SpeechRecognition : EventTarget {
3+
constructor();
4+
35
// recognition parameters
46
attribute SpeechGrammarList grammars;
57
attribute DOMString lang;
68
attribute boolean continuous;
79
attribute boolean interimResults;
810
attribute unsigned long maxAlternatives;
9-
attribute DOMString serviceURI;
1011

1112
// methods to drive the speech interaction
1213
void start();
@@ -39,11 +40,17 @@ enum SpeechRecognitionErrorCode {
3940
};
4041

4142
[Exposed=Window]
42-
interface SpeechRecognitionError : Event {
43+
interface SpeechRecognitionErrorEvent : Event {
44+
constructor(DOMString type, SpeechRecognitionErrorEventInit eventInitDict);
4345
readonly attribute SpeechRecognitionErrorCode error;
4446
readonly attribute DOMString message;
4547
};
4648

49+
dictionary SpeechRecognitionErrorEventInit : EventInit {
50+
required SpeechRecognitionErrorCode error;
51+
DOMString message = "";
52+
};
53+
4754
// Item in N-best list
4855
[Exposed=Window]
4956
interface SpeechRecognitionAlternative {
@@ -69,28 +76,33 @@ interface SpeechRecognitionResultList {
6976
// A full response, which could be interim or final, part of a continuous response or not
7077
[Exposed=Window]
7178
interface SpeechRecognitionEvent : Event {
79+
constructor(DOMString type, SpeechRecognitionEventInit eventInitDict);
7280
readonly attribute unsigned long resultIndex;
7381
readonly attribute SpeechRecognitionResultList results;
74-
readonly attribute any interpretation;
75-
readonly attribute Document? emma;
82+
};
83+
84+
dictionary SpeechRecognitionEventInit : EventInit {
85+
unsigned long resultIndex = 0;
86+
required SpeechRecognitionResultList results;
7687
};
7788

7889
// The object representing a speech grammar
79-
[Exposed=Window, Constructor]
90+
[Exposed=Window]
8091
interface SpeechGrammar {
8192
attribute DOMString src;
8293
attribute float weight;
8394
};
8495

8596
// The object representing a speech grammar collection
86-
[Exposed=Window, Constructor]
97+
[Exposed=Window]
8798
interface SpeechGrammarList {
99+
constructor();
88100
readonly attribute unsigned long length;
89101
getter SpeechGrammar item(unsigned long index);
90102
void addFromURI(DOMString src,
91-
optional float weight);
103+
optional float weight = 1.0);
92104
void addFromString(DOMString string,
93-
optional float weight);
105+
optional float weight = 1.0);
94106
};
95107

96108
[Exposed=Window]
@@ -112,13 +124,13 @@ partial interface Window {
112124
[SameObject] readonly attribute SpeechSynthesis speechSynthesis;
113125
};
114126

115-
[Exposed=Window,
116-
Constructor,
117-
Constructor(DOMString text)]
127+
[Exposed=Window]
118128
interface SpeechSynthesisUtterance : EventTarget {
129+
constructor(optional DOMString text);
130+
119131
attribute DOMString text;
120132
attribute DOMString lang;
121-
attribute SpeechSynthesisVoice voice;
133+
attribute SpeechSynthesisVoice? voice;
122134
attribute float volume;
123135
attribute float rate;
124136
attribute float pitch;
@@ -134,12 +146,22 @@ interface SpeechSynthesisUtterance : EventTarget {
134146

135147
[Exposed=Window]
136148
interface SpeechSynthesisEvent : Event {
149+
constructor(DOMString type, SpeechSynthesisEventInit eventInitDict);
137150
readonly attribute SpeechSynthesisUtterance utterance;
138151
readonly attribute unsigned long charIndex;
152+
readonly attribute unsigned long charLength;
139153
readonly attribute float elapsedTime;
140154
readonly attribute DOMString name;
141155
};
142156

157+
dictionary SpeechSynthesisEventInit : EventInit {
158+
required SpeechSynthesisUtterance utterance;
159+
unsigned long charIndex = 0;
160+
unsigned long charLength = 0;
161+
float elapsedTime = 0;
162+
DOMString name = "";
163+
};
164+
143165
enum SpeechSynthesisErrorCode {
144166
"canceled",
145167
"interrupted",
@@ -152,13 +174,19 @@ enum SpeechSynthesisErrorCode {
152174
"voice-unavailable",
153175
"text-too-long",
154176
"invalid-argument",
177+
"not-allowed",
155178
};
156179

157180
[Exposed=Window]
158181
interface SpeechSynthesisErrorEvent : SpeechSynthesisEvent {
182+
constructor(DOMString type, SpeechSynthesisErrorEventInit eventInitDict);
159183
readonly attribute SpeechSynthesisErrorCode error;
160184
};
161185

186+
dictionary SpeechSynthesisErrorEventInit : SpeechSynthesisEventInit {
187+
required SpeechSynthesisErrorCode error;
188+
};
189+
162190
[Exposed=Window]
163191
interface SpeechSynthesisVoice {
164192
readonly attribute DOMString voiceURI;

inputfiles/removedTypes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@
238238
}
239239
}
240240
},
241+
"SpeechRecognitionEvent": {
242+
"constructor": null
243+
},
244+
"SpeechRecognitionErrorEvent": null,
241245
"StorageEvent": {
242246
"methods": {
243247
"method": {

0 commit comments

Comments
 (0)