Skip to content

Commit

Permalink
Working for English and Spanish
Browse files Browse the repository at this point in the history
  • Loading branch information
lauratbg committed Apr 16, 2024
1 parent ab067d2 commit 07fc99c
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions webapp/src/components/questionView/QuestionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,52 @@ function QuestionView(){
return (
<div className="question-view-container">
{numQuestion >= 0 ?
<QuestionComponent t={t} questions={questions} numQuestion={numQuestion} handleClick={handleClick} points={points} audio = {audio}/> :
<QuestionComponent t={t} questions={questions} numQuestion={numQuestion} handleClick={handleClick} points={points} audio = {audio} language={i18n.language}/> :
<h1>{t("questionView.no_questions_message")}</h1> }
</div>);
}

function QuestionComponent({questions, numQuestion, handleClick, t, points, audio}){
function QuestionComponent({questions, numQuestion, handleClick, t, points, audio, language}){


const speakQuestion = () => {
const speech = new SpeechSynthesisUtterance();
speech.text = questions[numQuestion].getQuestion();
window.speechSynthesis.speak(speech);
speech.lang = language;
console.log(language);
getVoicesForLanguage(language)
.then(voices => {
const voice = voices.find(voice => voice.lang === language);
// speech.voice = voice || voices[0]; // If there is no voice for the lang, choose the first one
window.speechSynthesis.speak(speech);
})
.catch(error => {
console.error("Error al obtener las voces para el idioma:", error);
});
};

// Función para obtener las voces disponibles para un idioma
const getVoicesForLanguage = (language) => {
return new Promise((resolve, reject) => {
const speech = new SpeechSynthesisUtterance();
speech.text = questions[numQuestion].getQuestion();
speech.lang = language;

speech.addEventListener("error", reject);

speech.addEventListener("end", () => {
const voices = window.speechSynthesis.getVoices();
if (voices.length > 0) {
resolve(voices);
} else {
reject("No se encontraron voces disponibles.");
}
});

window.speechSynthesis.speak(speech);
});
};



const renderer = ({seconds, completed }) => {
if (completed) {
Expand Down

0 comments on commit 07fc99c

Please sign in to comment.