New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[web][speech] Improve expo speech for web. #14516
Conversation
As `getVoices` is populated asynchronous, it will return an empty array, see https://stackoverflow.com/questions/49506716/speechsynthesis-getvoices-returns-empty-array-on-windows On native it's possible to provide a `voice`'s identifier as part of the options, to select a different voice. Allow web to do the same thing.
const voices = await getVoices(); | ||
message.voice = | ||
voices[ | ||
Math.max( | ||
0, | ||
voices.findIndex((voice) => voice.voiceURI === options.voice) | ||
) | ||
]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the voice provided in the options don't match any available voice we fallback to the first one in the list.
Not doing any clever stuff with voice.default
here, as _voiceIndex
does the same
async getVoices(): Promise<WebVoice[]> { | ||
const voices = await getVoices(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine to be async. It's used in an async function already:
export async function getAvailableVoicesAsync(): Promise<Voice[]> {
if (!ExponentSpeech.getVoices) {
throw new UnavailabilityError('Speech', 'getVoices');
}
return ExponentSpeech.getVoices(); // <--
}
It's not a BC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Federkun, great job on this one! 👏 🥳
It looks rock solid 🪨
Let's add this single SO reference to the comment as well and we're ready to merge 😉
Co-authored-by: Bartłomiej Bukowski <bartlomiejbukowski.b@gmail.com>
Brilliant, added, thank you so much! |
Why
As
getVoices
is populated asynchronous, on web, it may return an empty array. See https://stackoverflow.com/questions/49506716/speechsynthesis-getvoices-returns-empty-array-on-windowsOn native it's possible to provide a
voice
's identifier as part of the options, to select a different voice. This PR allow web to do the same thing.How
Test Plan
I applied this as a patch and tested on chrome (only chrome).
Checklist
expo build
(eg: updated@expo/xdl
).expo prebuild
& EAS Build (eg: updated a module plugin).