MCPcopy Create free account
hub / github.com/adobe/react-spectrum / requestMicrophone

Function requestMicrophone

packages/@react-spectrum/ai/src/useVoiceInput.ts:126–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

124 * SpeechRecognition opens its own.
125 */
126const 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. */
141const readTranscript = (event: SpeechRecognitionEvent): {interim: string; final: string} => {

Callers 1

useVoiceInputFunction · 0.85

Calls 2

mapMediaErrorFunction · 0.85
stopMethod · 0.65

Tested by

no test coverage detected