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

Function requestMicrophone

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

Source from the content-addressed store, hash-verified

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