Skip to content
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

voice property should utilize voiceURI instead of an index #94

Open
ecc521 opened this issue Mar 8, 2023 · 7 comments
Open

voice property should utilize voiceURI instead of an index #94

ecc521 opened this issue Mar 8, 2023 · 7 comments
Labels
bug/fix Something isn't working needs: triage

Comments

@ecc521
Copy link
Contributor

ecc521 commented Mar 8, 2023

Currently, especially on web, the list of available voices can change while the page is open. Uniquely identifying a specific voice (rather than the current system) avoids the risk of playing the wrong voice due to voices getting added, etc, while the page is open.

Additionally, at least on Android, voices are unordered - so this plugin needs to order the voices in a repeatable manner such that they can be located. I'm not actually sure if voices can change while the app is open, however either way, voiceURI would be less complicated.

Ideal Solution: voice property takes a string representing the voiceURI of the voice (or a separate option for voiceURI)

  • The biggest problem here is that, in order to maintain backwards compatibility, such changes would increase the codebase size overall, which may not be ideal.
@ecc521 ecc521 changed the title voice property should utilize voiceURI instead of an array index voice property should utilize voiceURI instead of an index Mar 8, 2023
@ecc521
Copy link
Contributor Author

ecc521 commented Mar 8, 2023

Also, related to #90
On Android, since the entire list of voices must be retrieved in order to find the index, it adds ~50ms overhead on my test device (OnePlus 7T, Android 12) to calls where the voice property is used. Not a major issue (especially since it's async and I believe on a different thread) but also would be a good thing to address.

We could theoretically cache the list, but I'm not seeing anything guaranteeing that the list doesn't change, so caching seems unwise as compared to using unique identifiers.

@Nikkolas-Cage
Copy link

any solution with this 2024

@robingenz robingenz added the bug/fix Something isn't working label Sep 7, 2024
@kieranbarlow
Copy link

Would like to see this also, I can do a PR but would like to know your preferred approach @robingenz

  1. Check if the 'voice' param is an integer or string, if integer continue to use existing method for determining voice.
  2. Add a new param called voiceUri, if this is used it overwrites the voice param.

If you could let me know which would work best I'll submit a PR.

@robingenz
Copy link
Member

@kieranbarlow Let me take another look at this in the next days. I will get back to you.

@robingenz
Copy link
Member

I have just looked at this issue and wonder if it is still relevant. On Android, there was this commit a few months ago that was supposed to ensure that the same order was always returned. And on the web, the voices are cached so that the order cannot change (see here).

@kieranbarlow
Copy link

@robingenz thanks for the reply. This is still an issue with iOS.

For example, iOS has

Jamie
Jamie (Advanced) - opt in download
Jamie (Premium) - opt in download
Kate
Kate (Advanced) - opt in download


  1. When downloaded, new voices appear at the top - skewing all indexes
  2. If ordered alphabetically, still your chosen index will be off
  3. Can't we use VoiceUri, it's unique across all platforms?
if voiceUri {
          let allVoices = AVSpeechSynthesisVoice.speechVoices()
          if let matchingVoice = allVoices.first(where: { $0.voiceURI == voiceUri }) {
              utterance.voice = matchingVoice
          }
}

@robingenz
Copy link
Member

@kieranbarlow Okay, feel free to create a PR that adds a new parameter voiceUri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/fix Something isn't working needs: triage
Projects
None yet
Development

No branches or pull requests

4 participants