Javascript Coding | XM Community
Skip to main content

Hello,
I had someone help me come up with a code in order to read the text in my surveys. However, when I put the code into javascript for my survey, the synthetic voice reads the questions twice and I only need it to be read once. The code is below if anyone can show me how to change the code so it only reads the questions once that would be great.
Qualtrics.SurveyEngine.addOnReady(function () {
// Find the HTML element containing the question.
const questionTextContainer = this.getQuestionTextContainer();

// Parse for the question from the HTML element.
const questionText = questionTextContainer.innerText;

// Construct an object used to speak the question.
const utterance = new SpeechSynthesisUtterance(questionText);

// Adjust the rate at which speech is outputted, where 1 = default rate, <1 is slower and >1 is faster.
utterance.rate = 2.00; 

// Output the speech.
window.speechSynthesis.speak(utterance);
});

window.onbeforeunload = function () {
window.speechSynthesis.cancel();
}

If you are testing it in the preview mode then once the code is run for mobile view and another for desktop view, try to test it using the annonymous survey link.


Leave a Reply