From 151020aeb52336255ed011222cf709d2d582ae47 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 29 Jun 2023 15:02:10 -0700 Subject: [PATCH] Update speechSynthesis.js Adding selection of the voice based on the language,since most voices have the same name but different languages on Webkit/iOS --- src/speechSynthesis.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/speechSynthesis.js b/src/speechSynthesis.js index a9788b1..779d54f 100644 --- a/src/speechSynthesis.js +++ b/src/speechSynthesis.js @@ -1,7 +1,7 @@ export default class SpeechSynthesis { constructor(props) { this.utterance = new window.SpeechSynthesisUtterance(); - this.selected = SpeechSynthesis.getVoice(props.voice); + this.selected = SpeechSynthesis.getVoice(props.voice, props.lang || 'en-GB'); this.utterance.voice = this.selected; this.utterance.text = props.text.replace(/\n/g, ''); this.utterance.lang = props.lang || 'en-GB'; @@ -14,9 +14,9 @@ export default class SpeechSynthesis { return window.speechSynthesis; } - static getVoice(selected) { + static getVoice(name, lang) { const voices = window.speechSynthesis.getVoices(); - const voice = voices.find(voice => voice.name === selected); + const voice = voices.find(voice => voice.name === name && voice.lang===lang); return voice !== undefined ? voice : voices[0]; }