()
| 124 | * SpeechRecognition opens its own. |
| 125 | */ |
| 126 | const requestMicrophone = async (): Promise<VoiceInputErrorCode | null> => { |
| 127 | const media = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined; |
| 128 | if (!media?.getUserMedia) { |
| 129 | return null; |
| 130 | } |
| 131 | try { |
| 132 | const stream = await media.getUserMedia({audio: true}); |
| 133 | stream.getTracks().forEach(track => track.stop()); |
| 134 | return null; |
| 135 | } catch (err) { |
| 136 | return mapMediaError(err); |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | /** Accumulates interim vs final transcripts from a recognition result event. */ |
| 141 | const readTranscript = (event: SpeechRecognitionEvent): {interim: string; final: string} => { |
no test coverage detected