leaonline/easy-speech

Is there any way of setting the language?

Closed this issue · 10 comments

First, cool project!

Second, after reading about it, I was expecting something like

EasySpeech.speak({ text: "Bonjour mon ami", language: "fr" })

to work out of the box, but it does not seem to be a feature.

Or am I missing something?

I was really attracted by this: "It will not only detect, which features are available but also loads an optimal default voice, based on a few heuristics" that I read here: https://dev.to/jankapunkt/cross-browser-speech-synthesis-the-hard-way-and-the-easy-way-353

Hi @mircealungu thanks for the idea. Currently you need to manually find an appropriate voice and pass it via

EasySpeech.speak({ text, voice })

However, this looks like a very useful feature. Under the hood it might work like this:

  • if language is passed to EasySpeech.speak and the current default voice has this language then use this voice
  • otherwise find the next voice in the list that matches the language pattern
  • if none is found use the default

This is partially done already when loading the voices:

https://github.com/jankapunkt/easy-speech/blob/b8c6fd354a5e7c8fab461c51f0d0f3a67a10c1ee/src/EasySpeech.js#L368-L375

A good approach would be to extract a function from this and use it in both places.

Let me know if you'd like to work with me on this :-)

@mircealungu can u assign this issue to me

haha. for sure I can assign it. but I'm not one of the devs.
better ask @jankapunkt ?

Hi @mircealungu thanks for the idea. Currently you need to manually find an appropriate voice and pass it via

EasySpeech.speak({ text, voice })

However, this looks like a very useful feature. Under the hood it might work like this:

  • if language is passed to EasySpeech.speak and the current default voice has this language then use this voice
  • otherwise find the next voice in the list that matches the language pattern
  • if none is found use the default

This is partially done already when loading the voices:

https://github.com/jankapunkt/easy-speech/blob/b8c6fd354a5e7c8fab461c51f0d0f3a67a10c1ee/src/EasySpeech.js#L368-L375

A good approach would be to extract a function from this and use it in both places.

Let me know if you'd like to work with me on this :-)

I've been playing with French, and what I've seen is:

  • different voices in different browsers
  • no default voice (at least this is what it seemed to me to be the case in Chrome on Mac OS)
  • the first voice in the list of French languages, In Chrome is "Grandma" which is a horrible voice.

For my own needs, I have decided to create a prioritized list of voices per language and then try to find those: i.e. https://github.com/zeeguu/web/blob/e33ae100f7f33c1f67c8e38d0278655f13387ece/src/speech/ZeeguuSpeech.js#L3C13-L3C13

There might be a better approach, and indeed it would make a lot of sense if every browser / OS would propose what they know is the best languages as "default". But as far as I can tell, this is not the case.

Otherwise, if you don't find a better approach algorithmically, maybe we could crowdsource the voice quality rankings in a separate package?

@Shreya111111 I assigned you to this issue. However, in order to be fair for other hacktoberfest contributors I will remove you if there is no pull request until in a week (26th).

@Shreya111111 how are things going?

This issue is free to take again.

@mircealungu I implemented a new method EasySpeech.filterVoices which allows you to simply add your language code (two-chars or full code are possible) and filter the voices by this.

It's also used internally when calling EasySpeech.init to determine the default voice when no voice is flagged with default: true by reading the navigator language and searching for a voice with that language.

The demo uses this now, too to auto-select a voice in the user's language.

Would you mind reviewing this PR?

By the way - I will open a new Rpo for the voice quality list. Once, we have something usable I will think about a good, non-breaking way to weak-include this into the package.

@mircealungu would you mind reviewing #243 ?