You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"use client";import{Button}from"@/components/ui/button";importReact,{useEffect}from"react";import{useVoiceVisualizer,VoiceVisualizer}from"react-voice-visualizer";exportdefaultfunctionVoiceRecorder(){constrecorderControls=useVoiceVisualizer();const{ saveAudioFile, recordedBlob, error }=recorderControls;// Get the recorded audio blobuseEffect(()=>{if(!recordedBlob)return;console.log(recordedBlob);},[recordedBlob,error]);// Get the error when it occursuseEffect(()=>{if(!error)return;console.error(error);},[error]);return(<><VoiceVisualizercontrols={recorderControls}mainBarColor="#FFFFFF"secondaryBarColor="#5e5e5e"width={"100%"}height={200}speed={3}barWidth={2}gap={1}rounded={5}isControlPanelShown={true}isDownloadAudioButtonShown={true}fullscreen={false}onlyRecording={false}animateCurrentPick={true}isDefaultUIShown={true}isProgressIndicatorShown={true}isProgressIndicatorTimeShown={true}isProgressIndicatorOnHoverShown={true}isProgressIndicatorTimeOnHoverShown={true}/><ButtononClick={saveAudioFile}>Save Audio</Button></>);}
Import the component as dynamic for avoiding SSR issues:
ReferenceError: window is not defined
at It (.../node_modules/react-voice-visualizer/dist/react-voice-visualizer.js:351:106)
Most likely, this component relies on browser-specific context, so it won't work with SSR frameworks like Remix or Nest.Js. I have tried to wrap this component into something like this:
constClientOnly=({ children }: {children: React.ReactNode})=>{const[isMounted,setIsMounted]=useState(false);useEffect(()=>{setIsMounted(true);},[]);returnisMounted ? children : null;};
But still, it doesn't seem to be functioning properly, although it renders, which is kind of a win.
UPD: I found a way to make it work!
const[isMounted,setIsMounted]=useState(false);useEffect(()=>{setIsMounted(true);},[]);// in your render...{isMounted&&(<VoiceVisualizercontrols={recorderControls}/>)}
That will ensure that your window context is accessible.
Visualization is not working while recording on NextJS. I have tried with the example from this repo 👉🏻 https://github.com/YZarytskyi/react-audio-visualization
To Reproduce
Steps to reproduce the behavior:
Expected behavior
It should be working as given demo of the library.
The text was updated successfully, but these errors were encountered: