{"ast":null,"code":"var _s = $RefreshSig$();\nimport { useState } from 'react';\n\n/**\n * Custom hook for recording audio using the browser's MediaRecorder API.\n * @returns An object containing functions to start and stop recording, as well as the URL of the recorded audio.\n */\nconst useAudioRecorder = () => {\n  _s();\n  const [audioStream, setAudioStream] = useState(null);\n  const [mediaRecorder, setMediaRecorder] = useState(null);\n  const [recordedAudioURL, setRecordedAudioURL] = useState(null);\n\n  /**\n   * Starts recording audio using the browser's MediaRecorder API.\n   * @throws {Error} If there is an error accessing the microphone.\n   */\n  const startRecording = async () => {\n    try {\n      const stream = await navigator.mediaDevices.getUserMedia({\n        audio: true\n      });\n      const recorder = new MediaRecorder(stream);\n      setAudioStream(stream);\n      setMediaRecorder(recorder);\n      const chunks = [];\n      recorder.ondataavailable = e => chunks.push(e.data);\n      recorder.onstop = () => {\n        const blob = new Blob(chunks, {\n          type: 'audio/webm'\n        });\n        const url = URL.createObjectURL(blob);\n        setRecordedAudioURL(url);\n      };\n      recorder.start();\n    } catch (error) {\n      console.error('Error accessing microphone:', error);\n    }\n  };\n\n  /**\n   * Stops recording audio and releases the microphone.\n   */\n  const stopRecording = () => {\n    if (mediaRecorder && audioStream) {\n      mediaRecorder.stop();\n      audioStream.getTracks().forEach(track => track.stop());\n    }\n  };\n  return {\n    startRecording,\n    stopRecording,\n    recordedAudioURL // URL of the recorded audio to play the recording\n  };\n};\n_s(useAudioRecorder, \"TaVi3FCZ6KTpA0y0/6LfCqpDYjc=\");\nexport default useAudioRecorder;","map":{"version":3,"names":["useState","useAudioRecorder","_s","audioStream","setAudioStream","mediaRecorder","setMediaRecorder","recordedAudioURL","setRecordedAudioURL","startRecording","stream","navigator","mediaDevices","getUserMedia","audio","recorder","MediaRecorder","chunks","ondataavailable","e","push","data","onstop","blob","Blob","type","url","URL","createObjectURL","start","error","console","stopRecording","stop","getTracks","forEach","track"],"sources":["/Users/chrishaack/UC_Trains_Voice/react-demo/src/function/AudioRecorder.ts"],"sourcesContent":["import React, { useState } from 'react';\n\n/**\n * Custom hook for recording audio using the browser's MediaRecorder API.\n * @returns An object containing functions to start and stop recording, as well as the URL of the recorded audio.\n */\nconst useAudioRecorder = () => {\n    const [audioStream, setAudioStream] = useState<MediaStream | null>(null);\n    const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder | null>(null);\n    const [recordedAudioURL, setRecordedAudioURL] = useState<string | null>(null);\n    \n    /**\n     * Starts recording audio using the browser's MediaRecorder API.\n     * @throws {Error} If there is an error accessing the microphone.\n     */\n    const startRecording = async () => {\n      try {\n        const stream = await navigator.mediaDevices.getUserMedia({ audio: true });\n        const recorder = new MediaRecorder(stream);\n  \n        setAudioStream(stream);\n        setMediaRecorder(recorder);\n  \n        const chunks: Blob[] = [];\n        recorder.ondataavailable = (e) => chunks.push(e.data as Blob);\n        recorder.onstop = () => {\n          const blob = new Blob(chunks, { type: 'audio/webm' });\n          const url = URL.createObjectURL(blob);\n          setRecordedAudioURL(url);\n        };\n  \n        recorder.start();\n      } catch (error) {\n        console.error('Error accessing microphone:', error);\n      }\n    };\n    \n    /**\n     * Stops recording audio and releases the microphone.\n     */\n    const stopRecording = () => {\n      if (mediaRecorder && audioStream) {\n        mediaRecorder.stop();\n        audioStream.getTracks().forEach(track => track.stop());\n      }\n    };\n  \n    return {\n      startRecording,\n      stopRecording,\n      recordedAudioURL // URL of the recorded audio to play the recording\n    };\n  };\n  \n  export default useAudioRecorder;\n  "],"mappings":";AAAA,SAAgBA,QAAQ,QAAQ,OAAO;;AAEvC;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;EAAAC,EAAA;EAC3B,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGJ,QAAQ,CAAqB,IAAI,CAAC;EACxE,MAAM,CAACK,aAAa,EAAEC,gBAAgB,CAAC,GAAGN,QAAQ,CAAuB,IAAI,CAAC;EAC9E,MAAM,CAACO,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGR,QAAQ,CAAgB,IAAI,CAAC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