Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: voicerecorder implementation" #169

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading