The right way to use SSML with Web Speech API

前端 未结 3 1963
-上瘾入骨i
-上瘾入骨i 2021-02-13 16:53

Web Speech API specification says:

text attribute
This attribute specifies the text to be synthesized and spoken for thi

3条回答
  •  别那么骄傲
    2021-02-13 17:20

    In Chrome 46, the XML is being interpreted properly as an XML document, on Windows, when the language is set to en; however, I see no evidence that the tags are actually doing anything. I heard no difference between the and non- versions of this SSML:

    var msg = new SpeechSynthesisUtterance();
    msg.text = '\r\nWelcome to the Bird Seed Emporium.  Welcome to the Bird Seed Emporium.';
    msg.lang = 'en';
    speechSynthesis.speak(msg);
    

    The tag was also completely ignored, which made my attempt to speak IPA fail.

    var msg = new SpeechSynthesisUtterance();
    msg.text='  Pavlova is a meringue-based dessert named after the Russian ballerina Anna Pavlova. It is a meringue cake with a crisp crust and soft, light inside, usually topped with fruit and, optionally, whipped cream.  The name is pronounced ... or ..., unlike the name of the dancer, which was ... ';
    msg.lang = 'en';
    speechSynthesis.speak(msg);
    

    This is despite the fact that the Microsoft speech API does handle SSML correctly. Here is a C# snippet, suitable for use in LinqPad:

    var str = "Pavlova is a meringue-based dessert named after the Russian ballerina Anna Pavlova. It is a meringue cake with a crisp crust and soft, light inside, usually topped with fruit and, optionally, whipped cream.  The name is pronounced /pævˈloʊvə/ or /pɑːvˈloʊvə/, unlike the name of the dancer, which was /ˈpɑːvləvə/.";
    var regex = new Regex("/([^/]+)/");
    if (regex.IsMatch(str))
    {
        str = regex.Replace(str, "word");
        str.Dump();
    }   
    SpeechSynthesizer synth = new SpeechSynthesizer();
    PromptBuilder pb = new PromptBuilder();
    pb.AppendSsmlMarkup(str);
    synth.Speak(pb);
    

提交回复
热议问题