leaonline / easy-speech

🔊 Cross browser Speech Synthesis also known as Text to speech or TTS; no dependencies; uses Web Speech API
https://leaonline.github.io/easy-speech/
175 stars 20 forks source link

Is there any way of setting the language? #218

Closed mircealungu closed 6 months ago

mircealungu commented 9 months ago

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

jankapunkt commented 9 months ago

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:

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 :-)

Shreya111111 commented 9 months ago

@mircealungu can u assign this issue to me

mircealungu commented 9 months ago

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

mircealungu commented 9 months ago

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:

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.

mircealungu commented 9 months ago

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

jankapunkt commented 9 months ago

@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).

jankapunkt commented 9 months ago

@Shreya111111 how are things going?

jankapunkt commented 9 months ago

This issue is free to take again.

jankapunkt commented 7 months ago

@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.

jankapunkt commented 6 months ago

@mircealungu would you mind reviewing #243 ?