Skip to content

Commit c36e2f1

Browse files
committed
fix(chat): speech to text interface declaration
1 parent 6265c5d commit c36e2f1

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/components/chat/chat-input.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ export default class IgcChatInputComponent extends LitElement {
201201
// console.error('No STT service configured');
202202
}
203203

204+
if (!this._sttClient) {
205+
return;
206+
}
207+
204208
await this._sttClient.start(this._state.options?.speechToText?.lang);
205209
this.isRecording = true;
206210
this.isStopInProgress = false;

src/components/chat/extras/stt-client-webspeech.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,40 @@ export class WebSpeechSttClient extends BaseSttClient {
6060
this.restartGracePeriod();
6161
}
6262
}
63+
64+
//Fix. Add own interface declaration for SpeechRecognition
65+
declare global {
66+
interface Window {
67+
SpeechRecognition: typeof SpeechRecognition;
68+
webkitSpeechRecognition: typeof SpeechRecognition;
69+
}
70+
71+
// The browser’s Web Speech API type (simplified)
72+
var SpeechRecognition: {
73+
new (): SpeechRecognition;
74+
};
75+
76+
interface SpeechRecognition extends EventTarget {
77+
continuous: boolean;
78+
interimResults: boolean;
79+
lang: string;
80+
start(): void;
81+
stop(): void;
82+
abort(): void;
83+
onaudioend?: (this: SpeechRecognition, ev: Event) => any;
84+
onaudiostart?: (this: SpeechRecognition, ev: Event) => any;
85+
onend?: (this: SpeechRecognition, ev: Event) => any;
86+
onerror?: (this: SpeechRecognition, ev: Event) => any;
87+
onnomatch?: (this: SpeechRecognition, ev: Event) => any;
88+
onresult?: (this: SpeechRecognition, ev: SpeechRecognitionEvent) => any;
89+
onsoundend?: (this: SpeechRecognition, ev: Event) => any;
90+
onsoundstart?: (this: SpeechRecognition, ev: Event) => any;
91+
onspeechend?: (this: SpeechRecognition, ev: Event) => any;
92+
onspeechstart?: (this: SpeechRecognition, ev: Event) => any;
93+
onstart?: (this: SpeechRecognition, ev: Event) => any;
94+
}
95+
96+
interface SpeechRecognitionEvent extends Event {
97+
results: SpeechRecognitionResultList;
98+
}
99+
}

0 commit comments

Comments
 (0)