tom-s / speak-tts

76 stars 19 forks source link

setVoice doesn't work on iOS #17

Closed willnix86 closed 4 years ago

willnix86 commented 5 years ago

I've found that the same code that changes all voices correctly on my laptop, doesn't do the same on my iPhone.

On the iPhone, it'll change to the default voice for any language (ie. if i choose a voice listed for that language, it'll set a new voice), but if I try to change the voice to another from that language, I have no luck - it just stays the same. For e.g: there are 3 voices that show up for en-US but even if I change to another of the 3, the voice doesn't change from the default en-US voice.

Below is my code. The "voice" being passed to it is just a string ie. "Alex" or "Daniel" which should set the new voice as needed (as I said, it certainly does on my laptop). Any thoughts?

I know the 'speech' object I call setVoice on works because whatever happens, it speaks "Hello, I'm xxx' as I've told it to

componentDidUpdate(prevProps) {

const { speech, language, voice } = this.props;

if (prevProps.language !== language) {
    speech.setLanguage(language)
}

if (voice !== prevProps.voice) {
    speech.setVoice(voice);
    speech.cancel();
    speech.speak({
    text: `Hello, I'm ${this.props.voice}`
    })
}

}

willnix86 commented 5 years ago

I should say, I don't get an error saying "can't set voice" like your code dictates I would if the action fails - it's very strange!!

tom-s commented 5 years ago

Hi,

Could you please please provide an example (jsfiddle or codesandbox) that reproduces the issue ?

tom-s commented 5 years ago

Also have you checked that the voice you are providing exist in the list of available voices returned at init time ? Same question for the language. The fact that it works on your desktop it not a proof that it should work on your iphone, each device/os has different voices and languages.

willnix86 commented 5 years ago

Hi @tom-s - yeah I've checked that the voices that show up on iPhone are the iPhone specific ones.

Here's a codesandbox with the issue replicated: https://codesandbox.io/s/5wpqlyv25l

Looking forward to hearing your thoughts!

willnix86 commented 5 years ago

Any ideas, @tom-s?

tom-s commented 5 years ago

Looks like a bug on ios 12, is it what you are using? -> https://stackoverflow.com/questions/53114919/speechsynthesis-cannot-set-voice-on-ios-devices