How to mock Speech Synthesis voices with a new CDP command?

139 views
Skip to first unread message

Heraldo Lucena

unread,
Oct 10, 2022, 1:50:48 PM10/10/22
to Chromium-dev
I want to add a new Chrome DevTools Protocol (CDP) command to the Emulation domain for mocking speech synthesis voices on my own chromium fork.

That command would be called Emulation.setSpeechSynthesisVoiceOverride() and it would take an array of voices, which are objects with the same shape as the SpeechSynthesisVoice interface of the Web Speech API.

I read the chromium docs about CDP dev and I think the right domain handler to patch is at content/browser/devtools/protocol/emulation_handler.cc, is that right? Where I should incude the C++ function which implements setSpeechSynthesisVoiceOverride() and how I should declare the array of voices parameter?

Also, how do I access the speech synthesis service/mojom object to inject new voices? I looked at blink/renderer/modules/speech/speech_synthesis.cc but couldn't find how.

guest271314

unread,
Oct 11, 2022, 1:19:07 PM10/11/22
to heral...@gmail.com, Chromium-dev
You can install local speech synthesis engine and Speech Dispatcher, then run spd-conf -u and set the speech synthesis engine and voices, voice variant to be used thereby for Web Speech API.

On Chrome, when Google voices are used, the text is sent to remote servers https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/resources/network_speech_synthesis/tts_extension.js;l=33. When non-Google voices are used the local speech synthesis engine is used.

Chromium is not shipped with Google voices option. 

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/e663f2fa-45ed-4e9d-8602-d73452db4c41n%40chromium.org.

Heraldo Lucena

unread,
Oct 11, 2022, 3:06:46 PM10/11/22
to Chromium-dev, guest...@gmail.com, Chromium-dev, Heraldo Lucena
I don't want to play the actual voices, I just want to mock their existence. If the user try to play these voices nothing happens. Can I do that without setting up a local speech synthesis engine?

Katie D

unread,
Oct 12, 2022, 9:50:11 AM10/12/22
to Chromium-dev, heral...@gmail.com, guest...@gmail.com, Chromium-dev
I don't know about CDP, but here are some ideas for fake voices / speech:

* On Chrome OS, we use a fake speech synthesis engine built in C++ in browser tests for Accessibility features which use speech over the chrome.tts JS API: chrome/browser/ash/accessibility/speech_monitor.h. Perhaps you can create something similar.
* You can create your own JS extension which implements ttsEngine and have it do whatever you want; I believe if this extension is installed those voices listed by your ttsEngine will be available. Here's the espeak engine which comes with Chrome OS as an example.

guest271314

unread,
Oct 12, 2022, 1:17:04 PM10/12/22
to Katie D, Chromium-dev, heral...@gmail.com
 Here's the espeak engine which comes with Chrome OS as an example.

How to modify that code to enable SSML input? 

Heraldo Lucena

unread,
Oct 26, 2022, 4:47:52 PM10/26/22
to guest271314, Katie D, Chromium-dev
Is there a way to change available voices at runtime with the TTS JS extensions? I would like to change through CDP commands.
Reply all
Reply to author
Forward
0 new messages