Skip to content

Commit

Permalink
Revert "feat: voicerecorder implementation"
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitmlesmagico authored Jul 31, 2024
1 parent a4e92c8 commit 2fa49f2
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions packages/molecules/src/voice-recorder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@ interface VoiceRecorder {
setInputMsg: (msg: string) => void;
tapToSpeak: boolean;
includeDiv?: boolean;
showVoiceRecorder?: boolean;
delayBetweenDialogs?: number;
handleVoiceRecorder?: () => void;
styles?: object;
}

const VoiceRecorder: React.FC<VoiceRecorder> = ({
setInputMsg,
tapToSpeak,
includeDiv = false,
showVoiceRecorder = true,
delayBetweenDialogs,
handleVoiceRecorder,
styles: customStyles,
}) => {
const config = useUiConfig('component', 'voiceRecorder');

Expand All @@ -31,15 +23,14 @@ const VoiceRecorder: React.FC<VoiceRecorder> = ({
const [recorderStatus, setRecorderStatus] = useState('idle');

const voiceMinDecibels: number = config.voiceMinDecibels;
const actualDelayBetweenDialogs: number = delayBetweenDialogs || config.delayBetweenDialogs;
const delayBetweenDialogs: number = config.delayBetweenDialogs;
const dialogMaxLength: number = config.dialogMaxLength;
const [isRecording, setIsRecording] = useState(config.isRecording);

const startRecording = () => {
if (!isRecording) {
setIsRecording(true);
record();
if (handleVoiceRecorder) handleVoiceRecorder();
}
};

Expand Down Expand Up @@ -86,16 +77,19 @@ const VoiceRecorder: React.FC<VoiceRecorder> = ({

time = new Date();
const currentTime = time.getTime();

//time out:
if (currentTime > startTime + dialogMaxLength) {
recorder.stop();
return;
}

//a dialog detected:
if (anySoundDetected === true && currentTime > lastDetectedTime + actualDelayBetweenDialogs) {
if (anySoundDetected === true && currentTime > lastDetectedTime + delayBetweenDialogs) {
recorder.stop();
return;
}

//check for detection:
analyser.getByteFrequencyData(domainData);
for (let i = 0; i < bufferLength; i++)
Expand All @@ -104,10 +98,12 @@ const VoiceRecorder: React.FC<VoiceRecorder> = ({
time = new Date();
lastDetectedTime = time.getTime();
}

//continue the loop:
window?.requestAnimationFrame(detectSound);
};
window?.requestAnimationFrame(detectSound);

//stop event:
recorder.addEventListener('stop', () => {
//stop all the tracks:
Expand All @@ -120,7 +116,6 @@ const VoiceRecorder: React.FC<VoiceRecorder> = ({
});
});
}

const makeComputeAPICall = async (blob: Blob) => {
try {
setRecorderStatus('processing');
Expand All @@ -145,8 +140,6 @@ const VoiceRecorder: React.FC<VoiceRecorder> = ({
}
};

if (!showVoiceRecorder) return null;

return (
<div>
<div>
Expand Down

0 comments on commit 2fa49f2

Please sign in to comment.