From 0c99dcc505c7b6d4ee8de4419d8432abdc4999bc Mon Sep 17 00:00:00 2001 From: Sudeep Ratnaparkhe Date: Thu, 18 Jul 2024 20:05:06 +0530 Subject: [PATCH] Task #223068 added rnnoise model in const js and error handling added for ffmpeg FS --- src/utils/VoiceAnalyser.js | 23 +++++++++++++++++++---- src/utils/constants.js | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/utils/VoiceAnalyser.js b/src/utils/VoiceAnalyser.js index fcddad8a..f418fd65 100644 --- a/src/utils/VoiceAnalyser.js +++ b/src/utils/VoiceAnalyser.js @@ -27,6 +27,7 @@ import { compareArrays, getLocalData, replaceAll, + rnnoiseModelPath, } from "./constants"; import config from "./urlConstants.json"; import { filterBadWords } from "./Badwords"; @@ -90,7 +91,13 @@ function VoiceAnalyser(props) { await fetchFile(recordedBlob) ); - const nondenoiseddata = ffmpeg.FS("readFile", "recorded.webm"); + let nondenoiseddata; + try { + nondenoiseddata = ffmpeg.FS("readFile", "recorded.webm"); + } catch (error) { + console.error("Error reading recorded file:", error); + return; + } const nondenoisedBlob = new Blob([nondenoiseddata.buffer], { type: "audio/webm", }); @@ -104,7 +111,6 @@ function VoiceAnalyser(props) { } } - const rnnoiseModelPath = "models/cb.rnnn"; // Ensure this path is correct and accessible await ffmpeg.FS( "writeFile", "cb.rnnn", @@ -119,7 +125,13 @@ function VoiceAnalyser(props) { "output.wav" ); - const data = ffmpeg.FS("readFile", "output.wav"); + let data; + try { + data = ffmpeg.FS("readFile", "output.wav"); + } catch (error) { + console.error("Error reading output file:", error); + return; + } const denoisedBlob = new Blob([data.buffer], { type: "audio/wav" }); const newDenoisedUrl = URL.createObjectURL(denoisedBlob); @@ -208,13 +220,16 @@ function VoiceAnalyser(props) { const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); - while (1) { + let checkWhisperStatus = true; + + while (checkWhisperStatus) { whisperStatus = window.whisperModule.get_status(); if (whisperStatus === "running whisper ...") { isWhisperRunning = true; } if (isWhisperRunning && whisperStatus === "waiting for audio ...") { denoised_response_text = window.whisperModule.get_transcribed(); + checkWhisperStatus = false; break; } await delay(100); diff --git a/src/utils/constants.js b/src/utils/constants.js index 354ac634..bffd145c 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -3550,3 +3550,5 @@ export const randomizeArray = (arr) => { } return wordsArr; }; + +export const rnnoiseModelPath = "models/cb.rnnn";