File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -633,9 +633,23 @@ export default class Agent {
633633 utterance . rate = this . _tts . rate ;
634634 utterance . pitch = this . _tts . pitch ;
635635 const voices = speechSynthesis . getVoices ( ) ;
636- const match = voices . find ( ( v ) => v . name . includes ( this . _tts ! . voice ) ) ;
637- if ( match ) utterance . voice = match ;
638- speechSynthesis . speak ( utterance ) ;
636+ if ( voices . length > 0 ) {
637+ const match = voices . find ( ( v ) => v . name . includes ( this . _tts ! . voice ) ) ;
638+ if ( match ) utterance . voice = match ;
639+ speechSynthesis . speak ( utterance ) ;
640+ } else {
641+ // Voices not loaded yet (first page load) — wait for them
642+ speechSynthesis . addEventListener (
643+ "voiceschanged" ,
644+ ( ) => {
645+ const v = speechSynthesis . getVoices ( ) ;
646+ const match = v . find ( ( voice ) => voice . name . includes ( this . _tts ! . voice ) ) ;
647+ if ( match ) utterance . voice = match ;
648+ speechSynthesis . speak ( utterance ) ;
649+ } ,
650+ { once : true } ,
651+ ) ;
652+ }
639653 }
640654
641655 dispose ( ) {
You can’t perform that action at this time.
0 commit comments