Skip to content

Commit

Permalink
Task #223068 added rnnoise model in const js and error handling added…
Browse files Browse the repository at this point in the history
… for ffmpeg FS
  • Loading branch information
sudeeppr1998 committed Jul 18, 2024
1 parent b8c60ce commit 0c99dcc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
compareArrays,
getLocalData,
replaceAll,
rnnoiseModelPath,
} from "./constants";
import config from "./urlConstants.json";
import { filterBadWords } from "./Badwords";
Expand Down Expand Up @@ -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",
});
Expand All @@ -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",
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0c99dcc

Please sign in to comment.