Search code examples
javascripttext-to-speechssml

Using SSML with plain javascript


I'm trying to use speech API to read aloud a text. I would want to insert a pause in the sentence but I've been unable to do it. I've been trying to use SSML as the text:

var msg = new SpeechSynthesisUtterance();
msg.text = "Hello <break> World";
window.speechSynthesis.speak(msg);

But it reads it as it was plain text (reading the marks, etc.) I've also tried this kind of strings:

msg.text = '<speak>Hello <break time="2000ms"/> World </speak>'
msg.text = '<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="string"></speak>'

But it didn't worked. There is an onMark property on SpeechSynthesisUtterance that suggest that it should be possible to use SSML, but I haven't found anything about that.

Do you know if it's possible to use SSML and how to do it?


Solution

  • SSML still isn't implemented:
    https://github.com/WICG/speech-api/issues/10
    https://bugs.chromium.org/p/chromium/issues/detail?id=88072

    The final comment on the first thread seems to say that they still have no ideaa how to implement it.