| 139 | |
| 140 | /** Accumulates interim vs final transcripts from a recognition result event. */ |
| 141 | const readTranscript = (event: SpeechRecognitionEvent): {interim: string; final: string} => { |
| 142 | let interim = ''; |
| 143 | let final = ''; |
| 144 | for (let i = event.resultIndex; i < event.results.length; i++) { |
| 145 | const result = event.results[i]; |
| 146 | const alternative = result?.[0]; |
| 147 | if (result && alternative) { |
| 148 | if (result.isFinal) { |
| 149 | final += alternative.transcript; |
| 150 | } else { |
| 151 | interim += alternative.transcript; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | return {interim, final}; |
| 156 | }; |
| 157 | |
| 158 | interface RecognizerSetup { |
| 159 | recognitionRef: RefObject<SpeechRecognition | null>; |