Help with Speech to Text Custom Code with Pause, Play, Stop etc., buttons | XM Community
Skip to main content

Hi all,
I am having some difficulties with a code that is not functioning. The HTML code is allowing for the buttons to appear correctly, however the Java script I have is not working. The speech to text is not being read and thus the buttons are not functional. Can anyone let me know what I have done wrong?
Thank you so so much!]

HTML Code:






Survey Question/ answer text goes here



Java Script Code:
Qualtrics.SurveyEngine.addOnReady(function()
 { var txtInput = document.querySelector('#Questions');
 const removediv = document.querySelector('#Q_lang');
 removediv.remove();
 var btnSpeak = document.querySelector('#btnSpeak');
 var pausebtn = document.querySelector('#pausebtn');
 var resumebtn = document.querySelector('#resumebtn');
 var stopbtn = document.querySelector('#stopbtn');
 var NextButton = document.querySelector('#NextButton');
 var BackButton = document.querySelector('#PreviousButton');
 var synth = window.speechSynthesis;
 var voices = r];
 var textToSpeak = txtInput.textContent + NextButton.value;

 PopulateVoices();

 if(speechSynthesis !== undefined){
  speechSynthesis.onvoiceschanged = PopulateVoices;
 }

 //start//
 btnSpeak.addEventListener('click', ()=> {   
  var toSpeak = new SpeechSynthesisUtterance(textToSpeak);
  toSpeak.volume = 1;
  toSpeak.pitch = 1;
  toSpeak.rate = 1;
  toSpeak.voice = voices;0]; 
  synth.speak(toSpeak);
 });

 //pause//
 pausebtn.addEventListener('click', ()=> {
  synth.pause();
 });

 //resume//
 resumebtn.addEventListener('click', ()=> {
  synth.resume();
 });

 //stop//
 stopbtn.addEventListener('click', ()=> {
  synth.cancel();
 });

 //stop//
 NextButton.addEventListener('click', ()=> {
  synth.cancel();
 });

 //stop//
 BackButton.addEventListener('click', ()=> {
  synth.cancel();
 });

 function PopulateVoices(){
  voices = synth.getVoices();
  voices.forEach((item, index) => console.log(item.name, index));
 }

});

gracedemerling
Tried this thread's code?


Deepak yes I did; that thread is where I got the majority of the code from but it's not working in tandem with the html code


https://community.qualtrics.com/XMcommunity/discussion/comment/54737#Comment_54737That did work for me idk where you faced issue


Deepak what html code did you pair with the post you referenced? Maybe that is where I am facing issues then?


I used an Image in button something like this; created 4 buttons of the same.

Leave a Reply