Skip to content

Commit 4ad375d

Browse files
authored
Merge pull request #526 from saschanaz/speechapi
Add Web Speech types
2 parents 6f47ced + 658f948 commit 4ad375d

File tree

5 files changed

+394
-24
lines changed

5 files changed

+394
-24
lines changed

baselines/dom.generated.d.ts

Lines changed: 153 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,14 +1430,6 @@ interface ServiceWorkerMessageEventInit extends EventInit {
14301430
source?: ServiceWorker | MessagePort | null;
14311431
}
14321432

1433-
interface SpeechSynthesisEventInit extends EventInit {
1434-
charIndex?: number;
1435-
charLength?: number;
1436-
elapsedTime?: number;
1437-
name?: string;
1438-
utterance?: SpeechSynthesisUtterance | null;
1439-
}
1440-
14411433
interface StereoPannerOptions extends AudioNodeOptions {
14421434
pan?: number;
14431435
}
@@ -4463,6 +4455,9 @@ interface DocumentEvent {
44634455
createEvent(eventInterface: "SVGZoomEvents"): SVGZoomEvent;
44644456
createEvent(eventInterface: "SecurityPolicyViolationEvent"): SecurityPolicyViolationEvent;
44654457
createEvent(eventInterface: "ServiceWorkerMessageEvent"): ServiceWorkerMessageEvent;
4458+
createEvent(eventInterface: "SpeechRecognitionError"): SpeechRecognitionError;
4459+
createEvent(eventInterface: "SpeechRecognitionEvent"): SpeechRecognitionEvent;
4460+
createEvent(eventInterface: "SpeechSynthesisErrorEvent"): SpeechSynthesisErrorEvent;
44664461
createEvent(eventInterface: "SpeechSynthesisEvent"): SpeechSynthesisEvent;
44674462
createEvent(eventInterface: "StorageEvent"): StorageEvent;
44684463
createEvent(eventInterface: "TextEvent"): TextEvent;
@@ -13669,6 +13664,130 @@ declare var SourceBufferList: {
1366913664
new(): SourceBufferList;
1367013665
};
1367113666

13667+
interface SpeechGrammar {
13668+
src: string;
13669+
weight: number;
13670+
}
13671+
13672+
declare var SpeechGrammar: {
13673+
prototype: SpeechGrammar;
13674+
new(): SpeechGrammar;
13675+
};
13676+
13677+
interface SpeechGrammarList {
13678+
readonly length: number;
13679+
addFromString(string: string, weight?: number): void;
13680+
addFromURI(src: string, weight?: number): void;
13681+
item(index: number): SpeechGrammar;
13682+
[index: number]: SpeechGrammar;
13683+
}
13684+
13685+
declare var SpeechGrammarList: {
13686+
prototype: SpeechGrammarList;
13687+
new(): SpeechGrammarList;
13688+
};
13689+
13690+
interface SpeechRecognitionEventMap {
13691+
"audioend": Event;
13692+
"audiostart": Event;
13693+
"end": Event;
13694+
"error": SpeechRecognitionError;
13695+
"nomatch": SpeechRecognitionEvent;
13696+
"result": SpeechRecognitionEvent;
13697+
"soundend": Event;
13698+
"soundstart": Event;
13699+
"speechend": Event;
13700+
"speechstart": Event;
13701+
"start": Event;
13702+
}
13703+
13704+
interface SpeechRecognition extends EventTarget {
13705+
continuous: boolean;
13706+
grammars: SpeechGrammarList;
13707+
interimResults: boolean;
13708+
lang: string;
13709+
maxAlternatives: number;
13710+
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
13711+
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
13712+
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
13713+
onerror: ((this: SpeechRecognition, ev: SpeechRecognitionError) => any) | null;
13714+
onnomatch: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
13715+
onresult: ((this: SpeechRecognition, ev: SpeechRecognitionEvent) => any) | null;
13716+
onsoundend: ((this: SpeechRecognition, ev: Event) => any) | null;
13717+
onsoundstart: ((this: SpeechRecognition, ev: Event) => any) | null;
13718+
onspeechend: ((this: SpeechRecognition, ev: Event) => any) | null;
13719+
onspeechstart: ((this: SpeechRecognition, ev: Event) => any) | null;
13720+
onstart: ((this: SpeechRecognition, ev: Event) => any) | null;
13721+
serviceURI: string;
13722+
abort(): void;
13723+
start(): void;
13724+
stop(): void;
13725+
addEventListener<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
13726+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
13727+
removeEventListener<K extends keyof SpeechRecognitionEventMap>(type: K, listener: (this: SpeechRecognition, ev: SpeechRecognitionEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
13728+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
13729+
}
13730+
13731+
declare var SpeechRecognition: {
13732+
prototype: SpeechRecognition;
13733+
new(): SpeechRecognition;
13734+
};
13735+
13736+
interface SpeechRecognitionAlternative {
13737+
readonly confidence: number;
13738+
readonly transcript: string;
13739+
}
13740+
13741+
declare var SpeechRecognitionAlternative: {
13742+
prototype: SpeechRecognitionAlternative;
13743+
new(): SpeechRecognitionAlternative;
13744+
};
13745+
13746+
interface SpeechRecognitionError extends Event {
13747+
readonly error: SpeechRecognitionErrorCode;
13748+
readonly message: string;
13749+
}
13750+
13751+
declare var SpeechRecognitionError: {
13752+
prototype: SpeechRecognitionError;
13753+
new(): SpeechRecognitionError;
13754+
};
13755+
13756+
interface SpeechRecognitionEvent extends Event {
13757+
readonly emma: Document | null;
13758+
readonly interpretation: any;
13759+
readonly resultIndex: number;
13760+
readonly results: SpeechRecognitionResultList;
13761+
}
13762+
13763+
declare var SpeechRecognitionEvent: {
13764+
prototype: SpeechRecognitionEvent;
13765+
new(): SpeechRecognitionEvent;
13766+
};
13767+
13768+
interface SpeechRecognitionResult {
13769+
readonly isFinal: boolean;
13770+
readonly length: number;
13771+
item(index: number): SpeechRecognitionAlternative;
13772+
[index: number]: SpeechRecognitionAlternative;
13773+
}
13774+
13775+
declare var SpeechRecognitionResult: {
13776+
prototype: SpeechRecognitionResult;
13777+
new(): SpeechRecognitionResult;
13778+
};
13779+
13780+
interface SpeechRecognitionResultList {
13781+
readonly length: number;
13782+
item(index: number): SpeechRecognitionResult;
13783+
[index: number]: SpeechRecognitionResult;
13784+
}
13785+
13786+
declare var SpeechRecognitionResultList: {
13787+
prototype: SpeechRecognitionResultList;
13788+
new(): SpeechRecognitionResultList;
13789+
};
13790+
1367213791
interface SpeechSynthesisEventMap {
1367313792
"voiceschanged": Event;
1367413793
}
@@ -13694,38 +13813,46 @@ declare var SpeechSynthesis: {
1369413813
new(): SpeechSynthesis;
1369513814
};
1369613815

13816+
interface SpeechSynthesisErrorEvent extends SpeechSynthesisEvent {
13817+
readonly error: SpeechSynthesisErrorCode;
13818+
}
13819+
13820+
declare var SpeechSynthesisErrorEvent: {
13821+
prototype: SpeechSynthesisErrorEvent;
13822+
new(): SpeechSynthesisErrorEvent;
13823+
};
13824+
1369713825
interface SpeechSynthesisEvent extends Event {
1369813826
readonly charIndex: number;
13699-
readonly charLength: number;
1370013827
readonly elapsedTime: number;
1370113828
readonly name: string;
1370213829
readonly utterance: SpeechSynthesisUtterance;
1370313830
}
1370413831

1370513832
declare var SpeechSynthesisEvent: {
1370613833
prototype: SpeechSynthesisEvent;
13707-
new(type: string, eventInitDict?: SpeechSynthesisEventInit): SpeechSynthesisEvent;
13834+
new(): SpeechSynthesisEvent;
1370813835
};
1370913836

1371013837
interface SpeechSynthesisUtteranceEventMap {
13711-
"boundary": Event;
13712-
"end": Event;
13713-
"error": Event;
13714-
"mark": Event;
13715-
"pause": Event;
13716-
"resume": Event;
13717-
"start": Event;
13838+
"boundary": SpeechSynthesisEvent;
13839+
"end": SpeechSynthesisEvent;
13840+
"error": SpeechSynthesisErrorEvent;
13841+
"mark": SpeechSynthesisEvent;
13842+
"pause": SpeechSynthesisEvent;
13843+
"resume": SpeechSynthesisEvent;
13844+
"start": SpeechSynthesisEvent;
1371813845
}
1371913846

1372013847
interface SpeechSynthesisUtterance extends EventTarget {
1372113848
lang: string;
13722-
onboundary: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13723-
onend: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13724-
onerror: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13725-
onmark: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13726-
onpause: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13727-
onresume: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13728-
onstart: ((this: SpeechSynthesisUtterance, ev: Event) => any) | null;
13849+
onboundary: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
13850+
onend: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
13851+
onerror: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisErrorEvent) => any) | null;
13852+
onmark: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
13853+
onpause: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
13854+
onresume: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
13855+
onstart: ((this: SpeechSynthesisUtterance, ev: SpeechSynthesisEvent) => any) | null;
1372913856
pitch: number;
1373013857
rate: number;
1373113858
text: string;
@@ -16968,6 +17095,8 @@ type ScrollSetting = "" | "up";
1696817095
type SelectionMode = "select" | "start" | "end" | "preserve";
1696917096
type ServiceWorkerState = "installing" | "installed" | "activating" | "activated" | "redundant";
1697017097
type ServiceWorkerUpdateViaCache = "imports" | "all" | "none";
17098+
type SpeechRecognitionErrorCode = "no-speech" | "aborted" | "audio-capture" | "network" | "not-allowed" | "service-not-allowed" | "bad-grammar" | "language-not-supported";
17099+
type SpeechSynthesisErrorCode = "canceled" | "interrupted" | "audio-busy" | "audio-hardware" | "network" | "synthesis-unavailable" | "synthesis-failed" | "language-unavailable" | "voice-unavailable" | "text-too-long" | "invalid-argument";
1697117100
type TextTrackKind = "subtitles" | "captions" | "descriptions" | "chapters" | "metadata";
1697217101
type TextTrackMode = "disabled" | "hidden" | "showing";
1697317102
type TouchType = "direct" | "stylus";

baselines/dom.iterable.generated.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ interface SourceBufferList {
152152
[Symbol.iterator](): IterableIterator<SourceBuffer>;
153153
}
154154

155+
interface SpeechGrammarList {
156+
[Symbol.iterator](): IterableIterator<SpeechGrammar>;
157+
}
158+
159+
interface SpeechRecognitionResult {
160+
[Symbol.iterator](): IterableIterator<SpeechRecognitionAlternative>;
161+
}
162+
163+
interface SpeechRecognitionResultList {
164+
[Symbol.iterator](): IterableIterator<SpeechRecognitionResult>;
165+
}
166+
155167
interface StyleSheetList {
156168
[Symbol.iterator](): IterableIterator<StyleSheet>;
157169
}

inputfiles/addedTypes.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,62 @@
10761076
},
10771077
"no-interface-object": "1"
10781078
},
1079+
"SpeechRecognition": {
1080+
"events": {
1081+
"event": [
1082+
{
1083+
"name": "result",
1084+
"type": "SpeechRecognitionEvent"
1085+
},
1086+
{
1087+
"name": "nomatch",
1088+
"type": "SpeechRecognitionEvent"
1089+
},
1090+
{
1091+
"name": "error",
1092+
"type": "SpeechRecognitionError"
1093+
},
1094+
{
1095+
"name": "end",
1096+
"type": "Event"
1097+
}
1098+
]
1099+
}
1100+
},
1101+
"SpeechSynthesisUtterance": {
1102+
"events": {
1103+
"event": [
1104+
{
1105+
"name": "start",
1106+
"type": "SpeechSynthesisEvent"
1107+
},
1108+
{
1109+
"name": "end",
1110+
"type": "SpeechSynthesisEvent"
1111+
},
1112+
{
1113+
"name": "error",
1114+
"type": "SpeechSynthesisErrorEvent"
1115+
},
1116+
{
1117+
"name": "pause",
1118+
"type": "SpeechSynthesisEvent"
1119+
},
1120+
{
1121+
"name": "resume",
1122+
"type": "SpeechSynthesisEvent"
1123+
},
1124+
{
1125+
"name": "mark",
1126+
"type": "SpeechSynthesisEvent"
1127+
},
1128+
{
1129+
"name": "boundary",
1130+
"type": "SpeechSynthesisEvent"
1131+
}
1132+
]
1133+
}
1134+
},
10791135
"SVGElement": {
10801136
"implements": ["GlobalEventHandlers", "DocumentAndElementEventHandlers"]
10811137
},

0 commit comments

Comments
 (0)