-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f52613d
commit 6ed1a75
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.sound__interval { | ||
background: none; | ||
color: white; | ||
border: none; | ||
font: inherit; | ||
cursor: pointer; | ||
outline: inherit; | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
width: 50px; | ||
height: 50px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import './SoundInterval.css'; | ||
import VolumeUpIcon from '@mui/icons-material/VolumeUp'; | ||
import { useState, useEffect } from 'react'; | ||
|
||
let myCounter = 0; | ||
let timeout = null; | ||
|
||
const SoundInterval = ({ onWord, onIndexWord, currentLanguage }) => { | ||
const [counter, setCounter] = useState(0); | ||
const [togle, setTogle] = useState(false); | ||
console.log(onWord.length); | ||
// console.log(onWord); | ||
useEffect(() => { | ||
return () => clearInterval(timeout); | ||
}, []); | ||
|
||
myCounter = counter; | ||
const startInterval = () => { | ||
setTogle(prev => !prev); | ||
|
||
timeout = setInterval(() => { | ||
handleClickSound(myCounter); | ||
setCounter(counter => counter + 1); | ||
|
||
console.log('counter: ', myCounter); // counter always return 0 but myCounter the updated value | ||
if (myCounter === onWord.length) clearInterval(timeout); | ||
}, 5000); | ||
}; | ||
// логіка кнопки озвучування | ||
const handleClickSound = c => { | ||
// setTogle(prev => !prev); | ||
// console.log(c); | ||
// e.preventDefault(); | ||
let soundWordIndex = onWord.filter((el, idx) => idx === c); | ||
|
||
const synth = window.speechSynthesis; | ||
// зупинемо все, що вже синтезується раніше | ||
synth.cancel(); | ||
console.log('hallo', soundWordIndex); | ||
// читання тексту | ||
const utterance = new SpeechSynthesisUtterance(soundWordIndex[0].en); | ||
if (currentLanguage === 'en') { | ||
utterance.lang = 'en-US'; | ||
} else { | ||
utterance.lang = 'de'; | ||
} | ||
|
||
synth.speak(utterance); | ||
}; | ||
|
||
const handleClickButton = e => { | ||
e.stopPropagation(); | ||
}; | ||
|
||
const endOfSound = e => { | ||
clearInterval(timeout); | ||
setTogle(prev => !prev); | ||
}; | ||
|
||
return ( | ||
<button className="sound__interval" onClick={handleClickButton}> | ||
{!togle ? ( | ||
<VolumeUpIcon sx={{ color: 'green' }} onClick={startInterval}> | ||
Sound text | ||
</VolumeUpIcon> | ||
) : ( | ||
<VolumeUpIcon sx={{ color: 'red' }} onClick={endOfSound}> | ||
Sound text | ||
</VolumeUpIcon> | ||
)} | ||
{/* <VolumeUpIcon sx={{ color: 'green' }} onClick={startInterval}> | ||
Sound text | ||
</VolumeUpIcon> */} | ||
</button> | ||
); | ||
}; | ||
|
||
export default SoundInterval; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './SoundInterval'; |