angular - Why is my SpeechSynthesis onboundary event not firing - Stack Overflow

admin2025-04-28  2

The function onboundaryHandler doesn't get called.

export class TextToSpeechComponent {
   public textToSpeak = '';
   private synth = window.speechSynthesis;
   public voices: SpeechSynthesisVoice[] = this.synth.getVoices();

   public play = () => {
     let utterance = new SpeechSynthesisUtterance(this.textToSpeak);
     utterance.lang = 'en-US';
     utterance.onboundary = this.onboundaryHandler;
     speechSynthesis.speak(utterance);
   }


   onboundaryHandler(event: any) {
     console.log('onboundaryHandler called *************')
   }

}

html:

<div>
    <button class="btn btn-primary btn-sm" type="button" (click)="play()">
</div>
转载请注明原文地址:http://anycun.com/QandA/1745779880a91186.html