Skip to content

Commit

Permalink
#0000 audio detection feature enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyapandetekdi committed Oct 21, 2024
2 parents aede8c2 + c61afe6 commit ec2ae74
Show file tree
Hide file tree
Showing 14 changed files with 31,170 additions and 23,595 deletions.
46,023 changes: 26,265 additions & 19,758 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"ajv": "^8.17.1",
"axios": "^1.6.5",
"canvas-confetti": "^1.9.2",
"character-error-rate": "^1.1.4",
Expand Down
4 changes: 4 additions & 0 deletions src/assets/correct.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions src/assets/turtle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/wrong.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
281 changes: 240 additions & 41 deletions src/components/Layouts.jsx/MainLayout.jsx

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion src/components/Mechanism/WordsOrImage.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, CardContent, Typography, CircularProgress } from "@mui/material";
import { createRef, useState } from "react";
import { createRef, useState, useEffect } from "react";
import v11 from "../../assets/audio/V10.mp3";
import VoiceAnalyser from "../../utils/VoiceAnalyser";
import { PlayAudioButton, StopAudioButton } from "../../utils/constants";
Expand Down Expand Up @@ -53,6 +53,29 @@ const WordsOrImage = ({
const [isReady, setIsReady] = useState(false);

const [isPlaying, setIsPlaying] = useState(false);
const [storedData, setStoredData] = useState([]);

//console.log('wordsORimage', words, storedData);

const updateStoredData = (audio, isCorrect) => {
if (audio && words) {
const newEntry = {
selectedAnswer: words,
audioUrl: audio,
correctAnswer: isCorrect,
};

setStoredData((prevData) => [...prevData, newEntry]);
}
};

const resetStoredData = () => {
setStoredData([]);
};

useEffect(() => {
updateStoredData();
}, [handleNext]);

const togglePlayPause = () => {
if (isPlaying) {
Expand All @@ -72,6 +95,9 @@ const WordsOrImage = ({
enableNext={enableNext}
showTimer={showTimer}
points={points}
storedData={storedData}
resetStoredData={resetStoredData}
pageName={"wordsorimage"}
{...{
steps,
currentStep,
Expand Down Expand Up @@ -237,7 +263,9 @@ const WordsOrImage = ({
)}
<Box sx={{ display: "flex", justifyContent: "center" }}>
<VoiceAnalyser
pageName={"wordsorimage"}
setVoiceText={setVoiceText}
updateStoredData={updateStoredData}
setRecordedAudio={setRecordedAudio}
setVoiceAnimate={setVoiceAnimate}
storyLine={storyLine}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Practice/Mechanics3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const Mechanics2 = ({
const lang = getLocalData("lang");
let wordToCheck = type === "audio" ? parentWords : wordToFill;

//console.log('Mechanics3', answer);

useEffect(() => {
const initializeFillInTheBlank = async () => {
if (type === "fillInTheBlank" && parentWords?.length) {
Expand Down Expand Up @@ -238,6 +240,7 @@ const Mechanics2 = ({
enableNext={getEnableButton()}
showTimer={showTimer}
points={points}
pageName={"m3"}
{...{
steps,
currentStep,
Expand Down Expand Up @@ -540,6 +543,7 @@ const Mechanics2 = ({
<Box sx={{ display: "flex", justifyContent: "center" }}>
<VoiceAnalyser
setVoiceText={setVoiceText}
pageName={"m3"}
setRecordedAudio={setRecordedAudio}
setVoiceAnimate={setVoiceAnimate}
storyLine={storyLine}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Practice/Mechanics4.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const Mechanics4 = ({
return words;
}

//console.log('Mechanics4');

useEffect(() => {
let wordsArr = jumbleSentence(parentWords);
if (parentWords) {
Expand Down Expand Up @@ -154,6 +156,7 @@ const Mechanics4 = ({
enableNext={enableNext}
showTimer={showTimer}
points={points}
pageName={"m4"}
{...{
steps,
currentStep,
Expand Down Expand Up @@ -314,6 +317,7 @@ const Mechanics4 = ({
{
<Box sx={{ display: "flex", justifyContent: "center" }}>
<VoiceAnalyser
pageName={"m4"}
setVoiceText={setVoiceText}
setRecordedAudio={setRecordedAudio}
setVoiceAnimate={setVoiceAnimate}
Expand Down
44 changes: 40 additions & 4 deletions src/components/Practice/Mechanics5.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Mechanics5 = ({
isDiscover,
header,
parentWords,
options,
options = {},
image,
question_audio,
handleNext,
Expand Down Expand Up @@ -58,6 +58,29 @@ const Mechanics5 = ({
const [playingIndex, setPlayingIndex] = useState(null);
const [selectedOption, setSelectedOption] = useState(null); // Add state to track selected radio button

const [storedData, setStoredData] = useState([]);

const updateStoredData = (audios, isCorrect) => {
if (audios) {
const newEntry = {
selectedAnswer:
options && options.length > 0 && options[selectedOption]?.text,
audioUrl: audios,
correctAnswer: isCorrect,
};

setStoredData((prevData) => [...prevData, newEntry]);
}
};

const resetStoredData = () => {
setStoredData([]);
};

useEffect(() => {
updateStoredData();
}, [handleNext]);

useEffect(() => {
// Ensure that audio stops playing when options change
audiosRef.current.forEach((ref) => {
Expand Down Expand Up @@ -95,12 +118,17 @@ const Mechanics5 = ({
}
};

//console.log('Mechanics5' , storedData, options);

const handleOptionChange = (event, i) => {
setSelectedOption(i); // Set the selected option index
};

return (
<MainLayout
pageName={"m5"}
storedData={storedData}
resetStoredData={resetStoredData}
background={background}
handleNext={handleNext}
enableNext={enableNext}
Expand Down Expand Up @@ -191,7 +219,7 @@ const Mechanics5 = ({
</span>
</Box>

{options.length &&
{options && options.length > 0 ? (
options.map((option, i) => (
<Box
key={option.audio_url}
Expand Down Expand Up @@ -235,21 +263,29 @@ const Mechanics5 = ({
marginLeft: "10px",
}}
>
{option.text}
{option?.text || "Text is missing"}
</span>
</Box>
))}
))
) : (
<div>No options available</div>
)}
</Grid>
</Grid>

<Box paddingTop={1} sx={{ display: "flex", justifyContent: "center" }}>
<VoiceAnalyser
pageName={"m5"}
updateStoredData={updateStoredData}
setVoiceText={setVoiceText}
setRecordedAudio={setRecordedAudio}
setVoiceAnimate={setVoiceAnimate}
storyLine={storyLine}
dontShowListen={type === "image" || isDiscover}
isShowCase={isShowCase || isDiscover}
originalText={
options &&
options.length > 0 &&
options.find((option) => option.isAns === true).text
? options.find((option) => option.isAns === true).text
: parentWords
Expand Down
4 changes: 4 additions & 0 deletions src/components/Practice/Mechanics6.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ const Mechanics2 = ({
initializeAudio();
}, [contentId, parentWords]);

//console.log('Mechanics6');

const getSimilarWords = async (wordForFindingHomophones) => {
const lang = getLocalData("lang");
// const isFillInTheBlanks = type === "fillInTheBlank";
Expand Down Expand Up @@ -186,6 +188,7 @@ const Mechanics2 = ({

return (
<MainLayout
pageName={"m6"}
background={background}
handleNext={handleNext}
enableNext={enableNext}
Expand Down Expand Up @@ -470,6 +473,7 @@ const Mechanics2 = ({
{
<Box sx={{ display: "flex", justifyContent: "center" }}>
<VoiceAnalyser
pageName={"m6"}
setVoiceText={setVoiceText}
setRecordedAudio={setRecordedAudio}
setVoiceAnimate={setVoiceAnimate}
Expand Down
21 changes: 21 additions & 0 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ function VoiceAnalyser(props) {
const [isAudioPreprocessing, setIsAudioPreprocessing] = useState(
process.env.REACT_APP_IS_AUDIOPREPROCESSING === "true"
);
const [isMatching, setIsMatching] = useState(false);

//console.log('audio', recordedAudio, isMatching);

useEffect(() => {
if (!props.enableNext) {
Expand Down Expand Up @@ -348,6 +351,14 @@ function VoiceAnalyser(props) {
}
}

if (responseText.toLowerCase() === originalText.toLowerCase()) {
setIsMatching(true);
} else {
setIsMatching(false);
}

//console.log('textss', recordedAudio, isMatching, responseText, originalText);

const responseEndTime = new Date().getTime();
const responseDuration = Math.round(
(responseEndTime - responseStartTime) / 1000
Expand Down Expand Up @@ -602,6 +613,8 @@ function VoiceAnalyser(props) {
});
};

//console.log('textss', recordedAudio, isMatching);

return (
<div>
{loader ? (
Expand Down Expand Up @@ -663,6 +676,12 @@ function VoiceAnalyser(props) {
<Box
sx={{ cursor: "pointer" }}
onClick={() => {
if (
props.pageName === "wordsorimage" ||
props.pageName === "m5"
) {
props.updateStoredData(recordedAudio, isMatching);
}
if (props.setIsNextButtonCalled) {
props.setIsNextButtonCalled(true);
} else {
Expand Down Expand Up @@ -696,6 +715,8 @@ VoiceAnalyser.propTypes = {
setVoiceText: PropTypes.func.isRequired,
livesData: PropTypes.object,
contentId: PropTypes.string,
updateStoredData: PropTypes.func.isRequired,
pageName: PropTypes.string,
};

export default VoiceAnalyser;
21 changes: 12 additions & 9 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Practice = () => {
const [level, setLevel] = useState("");
const [isShowCase, setIsShowCase] = useState(false);
const [startShowCase, setStartShowCase] = useState(false);
const limit = 6;
const limit = 5;
const [disableScreen, setDisableScreen] = useState(false);
const [mechanism, setMechanism] = useState("");

Expand Down Expand Up @@ -215,6 +215,10 @@ const Practice = () => {
let newQuestionIndex =
currentQuestion === questions.length - 1 ? 0 : currentQuestion + 1;

const currentGetContent = levelGetContent?.[level]?.find(
(elem) => elem.title === practiceSteps?.[newPracticeStep]?.name
);

if (currentQuestion === questions.length - 1 || isGameOver) {
// navigate or setNextPracticeLevel
let currentPracticeStep =
Expand All @@ -233,7 +237,10 @@ const Practice = () => {
user_id: virtualId,
totalSyllableCount: totalSyllableCount,
language: localStorage.getItem("lang"),
is_mechanics: currentGetContent?.mechanism?.id ? true : false,
is_mechanics:
currentGetContent && currentGetContent?.mechanism?.id
? true
: false,
}
);
const { data: getSetData } = getSetResultRes;
Expand Down Expand Up @@ -284,10 +291,6 @@ const Practice = () => {
currentPracticeProgress = 0;
}

const currentGetContent = levelGetContent?.[level]?.find(
(elem) => elem.title === practiceSteps?.[newPracticeStep].name
);

await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
Expand Down Expand Up @@ -828,7 +831,7 @@ const Practice = () => {
setOpenMessageDialog,
options: questions[currentQuestion]?.mechanics_data
? questions[currentQuestion]?.mechanics_data[0]?.options
: null,
: [],
}}
/>
);
Expand Down Expand Up @@ -878,7 +881,7 @@ const Practice = () => {
} else if (mechanism.name === "readTheImage") {
const options = questions[currentQuestion]?.mechanics_data
? questions[currentQuestion]?.mechanics_data[0]?.options
: null;
: [];
const audioLink =
options && options.length > 0
? options.find((option) => option.isAns === true)?.audio_url || null
Expand Down Expand Up @@ -1056,7 +1059,7 @@ const Practice = () => {
setOpenMessageDialog,
options: questions[currentQuestion]?.mechanics_data
? questions[currentQuestion]?.mechanics_data[0]?.options
: null,
: [],
}}
/>
);
Expand Down
Loading

0 comments on commit ec2ae74

Please sign in to comment.