Skip to content

Commit

Permalink
Task #223069 & #223071 Fuzzball js integration done and added new fie…
Browse files Browse the repository at this point in the history
…lds in API for offline call
  • Loading branch information
sudeeppr1998 committed Jul 19, 2024
1 parent 4f744df commit d19176b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"eslint-plugin-react": "^7.33.1",
"faker": "^5.5.3",
"ffmpeg": "^0.0.4",
"fuzzball": "^2.1.2",
"homophones": "^1.0.1",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
Expand Down
39 changes: 33 additions & 6 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import config from "./urlConstants.json";
import { filterBadWords } from "./Badwords";
import { fetchFile } from "@ffmpeg/ffmpeg";
import useFFmpeg from "./useFFmpeg";
import * as fuzz from "fuzzball";
// import S3Client from '../config/awsS3';
/* eslint-disable */

Expand Down Expand Up @@ -75,6 +76,11 @@ function VoiceAnalyser(props) {
const [isAudioPreprocessing, setIsAudioPreprocessing] = useState(
process.env.REACT_APP_IS_AUDIOPREPROCESSING === "true"
);
const [nonDenoisedText, setNonDenoisedText] = useState("");
const [denoisedText, setDenoisedText] = useState("");
const [isOfflineModel, setIsOfflineModel] = useState(
localStorage.getItem("isOfflineModel") === "true"
);

const { ffmpeg, loading } = useFFmpeg();

Expand Down Expand Up @@ -104,8 +110,10 @@ function VoiceAnalyser(props) {

if (callUpdateLearner) {
try {
let nonDenoisedText = await getResponseText(nondenoisedBlob);
console.log("non denoised output -- ", nonDenoisedText);
let nonDenoisedRes = await getResponseText(nondenoisedBlob);
setNonDenoisedText(nonDenoisedRes);
console.log("non denoised output -- ", nonDenoisedRes);
console.log(fuzz.ratio(props.originalText, nonDenoisedRes));
} catch (error) {
console.error("Error getting non denoised text:", error);
}
Expand Down Expand Up @@ -137,8 +145,10 @@ function VoiceAnalyser(props) {

if (callUpdateLearner) {
try {
let denoisedText = await getResponseText(denoisedBlob);
console.log("denoised output -- ", denoisedText);
let denoisedRes = await getResponseText(denoisedBlob);
setDenoisedText(denoisedRes);
console.log("denoised output -- ", denoisedRes);
console.log(fuzz.ratio(props.originalText, denoisedRes));
} catch (error) {
console.error("Error getting denoised text:", error);
}
Expand Down Expand Up @@ -270,6 +280,7 @@ function VoiceAnalyser(props) {
);

setRecordedPauseCount(silenceStartCount);
console.log("silenceStartCount", silenceStartCount);
} catch (error) {
console.error("Error processing audio for pause count:", error);
} finally {
Expand Down Expand Up @@ -471,12 +482,28 @@ function VoiceAnalyser(props) {
let newThresholdPercentage = 0;
let data = {};

let response_text = "";
let mode = isOfflineModel ? "offline" : "online";
let pause_count = recordedPauseCount;

if (
fuzz.ratio(originalText, nonDenoisedText) >=
fuzz.ratio(originalText, denoisedText)
) {
response_text = nonDenoisedText;
} else {
response_text = denoisedText;
}

if (callUpdateLearner) {
const { data: updateLearnerData } = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.UPDATE_LEARNER_PROFILE}/${lang}`,
{
original_text: originalText,
audio: base64Data,
response_text: response_text,
mode: mode,
pause_count: pause_count,
audio: mode === "offline" ? "" : base64Data,
user_id: virtualId,
session_id: sessionId,
language: lang,
Expand All @@ -489,7 +516,7 @@ function VoiceAnalyser(props) {
data = updateLearnerData;
responseText = data.responseText;
profanityWord = await filterBadWords(data.responseText);
if (profanityWord !== data.responseText) {
if (profanityWord.includes("**")) {
props?.setOpenMessageDialog({
message: "Please avoid using inappropriate language.",
isError: true,
Expand Down

0 comments on commit d19176b

Please sign in to comment.