@@ -43,9 +43,9 @@ interface SpeechRecognitionErrorEvent extends Event {
4343 message : string ;
4444}
4545
46- interface SpeechRecognition {
46+ declare const SpeechRecognition : {
4747 new ( ) : SpeechRecognition ;
48- }
48+ } ;
4949
5050interface SymptomFormProps {
5151 onSubmit : ( symptoms : string ) => void ;
@@ -65,11 +65,11 @@ const SymptomForm: React.FC<SymptomFormProps> = ({
6565 const [ error , setError ] = useState ( '' ) ;
6666 const [ speechSupported , setSpeechSupported ] = useState ( true ) ;
6767 const [ recognition , setRecognition ] = useState < SpeechRecognition | null > ( null ) ;
68- const [ demoExamples , setDemoExamples ] = useState < string [ ] > ( [
68+ const demoExamples = [
6969 "I've had a persistent cough and sore throat for the past 3 days, with mild fever in the evenings." ,
7070 "I have severe headache in the front of my head and sensitivity to light for the last 6 hours." ,
7171 "My lower back has been hurting for two weeks, especially when I bend over or sit for long periods."
72- ] ) ;
72+ ] ;
7373
7474
7575 useEffect ( ( ) => {
@@ -78,20 +78,21 @@ const SymptomForm: React.FC<SymptomFormProps> = ({
7878
7979
8080 useEffect ( ( ) => {
81- const SpeechRecognition =
82- ( window as any ) . SpeechRecognition || ( window as any ) . webkitSpeechRecognition ;
81+ const SpeechRecognitionAPI =
82+ ( window as unknown as { SpeechRecognition ?: typeof SpeechRecognition ; webkitSpeechRecognition ?: typeof SpeechRecognition } ) . SpeechRecognition ||
83+ ( window as unknown as { SpeechRecognition ?: typeof SpeechRecognition ; webkitSpeechRecognition ?: typeof SpeechRecognition } ) . webkitSpeechRecognition ;
8384
84- if ( ! SpeechRecognition ) {
85+ if ( ! SpeechRecognitionAPI ) {
8586 setSpeechSupported ( false ) ;
8687 return ;
8788 }
8889
89- const recognitionInstance = new SpeechRecognition ( ) ;
90+ const recognitionInstance = new SpeechRecognitionAPI ( ) ;
9091 recognitionInstance . continuous = true ;
9192 recognitionInstance . interimResults = true ;
9293 recognitionInstance . lang = 'en-US' ;
9394
94- recognitionInstance . onresult = ( event : any ) => {
95+ recognitionInstance . onresult = ( event : SpeechRecognitionEvent ) => {
9596 let transcript = '' ;
9697 for ( let i = event . resultIndex ; i < event . results . length ; i ++ ) {
9798 if ( event . results [ i ] . isFinal ) {
@@ -103,7 +104,7 @@ const SymptomForm: React.FC<SymptomFormProps> = ({
103104 }
104105 } ;
105106
106- recognitionInstance . onerror = ( event : any ) => {
107+ recognitionInstance . onerror = ( event : SpeechRecognitionErrorEvent ) => {
107108 console . error ( 'Speech recognition error:' , event . error ) ;
108109 setError ( `Speech recognition error: ${ event . error } ` ) ;
109110 setIsRecording ( false ) ;
0 commit comments