Skip to content

Commit cbb2914

Browse files
authored
🤖 Merge PR DefinitelyTyped#74783 Update dom-speech-recognition with on-device changes by @tonyherre
1 parent 7136632 commit cbb2914

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎types/dom-speech-recognition/dom-speech-recognition-tests.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const speechRecognition2: SpeechRecognition = {
3636
interimResults: false,
3737
lang: "eng",
3838
maxAlternatives: 2,
39+
processLocally: true,
3940
onaudioend: null,
4041
onaudiostart: null,
4142
onend: null,
@@ -84,3 +85,13 @@ const speechRecognitionErrorEventInit: SpeechRecognitionErrorEventInit = {
8485
message: "abcde",
8586
};
8687
const speechRecognitionErrorEvent = new SpeechRecognitionErrorEvent("type", speechRecognitionErrorEventInit);
88+
89+
const speechRecognitionOptions: SpeechRecognitionOptions = {
90+
langs: ["en-GB"],
91+
processLocally: true,
92+
};
93+
94+
(async () => {
95+
const availability: AvailabilityStatus = await SpeechRecognition.available(speechRecognitionOptions);
96+
const installOutcome: boolean = await SpeechRecognition.install(speechRecognitionOptions);
97+
});

‎types/dom-speech-recognition/index.d.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface SpeechRecognition extends EventTarget {
2020
interimResults: boolean;
2121
lang: string;
2222
maxAlternatives: number;
23+
processLocally: boolean;
2324
onaudioend: ((this: SpeechRecognition, ev: Event) => any) | null;
2425
onaudiostart: ((this: SpeechRecognition, ev: Event) => any) | null;
2526
onend: ((this: SpeechRecognition, ev: Event) => any) | null;
@@ -56,7 +57,25 @@ interface SpeechRecognition extends EventTarget {
5657
): void;
5758
}
5859

59-
declare var SpeechRecognition: { prototype: SpeechRecognition; new(): SpeechRecognition };
60+
// https://wicg.github.io/speech-api/#dictdef-speechrecognitionoptions
61+
interface SpeechRecognitionOptions {
62+
langs: string[];
63+
processLocally: boolean;
64+
}
65+
66+
type AvailabilityStatus =
67+
| "unavailable"
68+
| "downloadable"
69+
| "downloading"
70+
| "available";
71+
72+
// https://webaudio.github.io/web-speech-api/#speechrecognition
73+
declare var SpeechRecognition: {
74+
prototype: SpeechRecognition;
75+
new(): SpeechRecognition;
76+
available(options: SpeechRecognitionOptions): Promise<AvailabilityStatus>;
77+
install(options: SpeechRecognitionOptions): Promise<boolean>;
78+
};
6079

6180
// https://wicg.github.io/speech-api/#speechrecognitionevent
6281
interface SpeechRecognitionEventInit extends EventInit {

0 commit comments

Comments
 (0)