Skip to content

Add default voice preferences for SpeechSynthesis API #304

@RangerMauve

Description

@RangerMauve

At the moment the SpeechSynthesis API in chromium doesn't seem to respect the users preferred voice (at least I haven't gotten it to work on Linux).

We should add a way to set this in the config and to monkey-patch speechSynthesis.speak to add the voice if no voice was set.

  • Add a new speechSynthesis.voice config item, default to null
  • In the settings page add a dropdown which populates with the names from speechSynthesis.getVoices()
  • There should be an option whose value is "null" so users can "unset" their preference
  • Add some JS to each page which does something along these lines
((() => {
const realSpeak = SpeechSynthesis.prototype.speak

SpeechSynthesis.prototype.speak = patchedSpeak

function patchedSpeak(utterance) {
  if(utterance.voice === null) {
    for(const voice of this.getVoices()) {
      if(voice.name === ${JSON.stringify(config.speechSynthesis.voice)}) {
        utterance.voice = voice
      }
    }
  }
  realSpeak.call(this, utterance)
}
})())

If utterance.voice is never null we should mokeypatch the setter for voice and track a private flag using a Symbol saying "a voice was set".

This should be injected inside a preload, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions