How to use speech-rule-engine - 10 common examples

To help you get started, we’ve selected a few speech-rule-engine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathjax / MathJax-node / lib / mj-page.js View on Github external
serverState = STATE.BUSY;
  var result = {}, $$ = window.Array, HUB = MathJax.Hub;

  //
  //  Get the math data and callback and set the content
  //
  var item = queue.shift();
  data = item[0]; callback = item[1];
  content.innerHTML = data.html;  //  %%% disable 
github pkra / mathjax-node-sre / lib / main.js View on Github external
const preprocessor = function (data, callback) {
    // setup SRE
    const speechConfig = {
        semantics: true,
        domain: data.speakRuleset || 'mathspeak',
        style: data.speakStyle || 'default',
        semantic: data.semantic,
        minSTree: data.minSTree,
        speakText: true,
        speech: 'deep'
    };
    if (data.speakText === false) speechConfig.speakText = false
    sre.setupEngine(speechConfig);
    // if MathML, enrich and continue
    if (data.format === "MathML") {
        data.speakText = sre.toSpeech(data.math);
        data.math = sre.toEnriched(data.math).toString();
        data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
        callback(data);
    } else {
        // convert to MathML, enrich and continue
        const newdata = {
            math: data.math,
            format: data.format,
            mml: true
        };
        mathjax.typeset(newdata, function (result) {
            if (result.error) throw result.error;
            data.speakText = sre.toSpeech(result.mml);
github pkra / mathjax-node-sre / lib / main.js View on Github external
if (!result.mml) result.mml = result.mmlNode.outerHTML;
    if (!speechConfig.speech) speechConfig.speech =  'deep';
    // add semantic tree
    if (speechConfig.semantic) {
        result.streeJson = sre.toJson(result.mml);
        const xml = sre.toSemantic(result.mml).toString();
        result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
    }
    // return if no speakText is requested
    if (!speechConfig.speakText) {
        callback(result, input);
        return
    }
    // enrich output
    sre.setupEngine(speechConfig);
    result.speakText = sre.toSpeech(result.mml);
    if (result.svgNode) {
        result.svgNode.querySelector('title').innerHTML = result.speakText;
        // update serialization
        // HACK add lost xlink namespaces TODO file jsdom bug
        if (result.svg) result.svg = result.svgNode.outerHTML
            .replace(/><([^/])/g, ">\n<$1")
            .replace(/(<\/[a-z]*>)(?=<\/)/g, "$1\n")
            .replace(/(<(?:use|image) [^>]*)(href=)/g, ' $1xlink:$2');
    }
    if (result.htmlNode) {
        result.htmlNode.firstChild.setAttribute("aria-label", result.speakText);
        // update serialization
        if (result.html) result.html = result.htmlNode.outerHTML;
    }
    if (result.mmlNode) {
        result.mmlNode.setAttribute("alttext", result.speakText);
github pkra / mathjax-node-sre / lib / main.js View on Github external
const preprocessor = function (data, callback) {
    // setup SRE
    const speechConfig = {
        semantics: true,
        domain: data.speakRuleset || 'mathspeak',
        style: data.speakStyle || 'default',
        semantic: data.semantic,
        minSTree: data.minSTree,
        speakText: true,
        speech: 'deep'
    };
    if (data.speakText === false) speechConfig.speakText = false
    sre.setupEngine(speechConfig);
    // if MathML, enrich and continue
    if (data.format === "MathML") {
        data.speakText = sre.toSpeech(data.math);
        data.math = sre.toEnriched(data.math).toString();
        data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
        callback(data);
    } else {
        // convert to MathML, enrich and continue
        const newdata = {
            math: data.math,
            format: data.format,
            mml: true
        };
        mathjax.typeset(newdata, function (result) {
            if (result.error) throw result.error;
            data.speakText = sre.toSpeech(result.mml);
            data.math = sre.toEnriched(result.mml).toString();
            data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
            data.format = 'MathML';
github mathjax / MathJax-node / lib / mj-page.js View on Github external
var SPEAK = function (svg) {
    var jax = MathJax.Hub.getJaxFor(svg), id = jax.inputID, mml;
    try {mml = jax.root.toMathML('',jax)} catch(err) {
      if (!err.restart) {throw err;} // an actual error
      if (!queue) {queue = MathJax.Callback.Queue()}
      return queue.Push(err.restart,window.Array(SPEAK,svg));
    }
    jax.speech = speech.processExpression(mml);
    svg.setAttribute("role","math");
    svg.setAttribute("aria-labelledby",id+"-Title "+id+"-Desc");
    for (var i = 0, m = svg.childNodes.length; i < m; i++)
      svg.childNodes[i].setAttribute("aria-hidden",true);
    var node = MathJax.HTML.Element("desc",{id:id+"-Desc"},[jax.speech]);
    svg.insertBefore(node,svg.firstChild);
    node = MathJax.HTML.Element("title",{id:id+"-Title"},["Equation"]);
    svg.insertBefore(node,svg.firstChild);
  }
  for (var i = nodes.length-1; i >= 0; i--) SPEAK(nodes[i]);
github pkra / mathjax-node-sre / lib / main.js View on Github external
// setup SRE
    const speechConfig = {
        semantics: true,
        domain: data.speakRuleset || 'mathspeak',
        style: data.speakStyle || 'default',
        semantic: data.semantic,
        minSTree: data.minSTree,
        speakText: true,
        speech: 'deep'
    };
    if (data.speakText === false) speechConfig.speakText = false
    sre.setupEngine(speechConfig);
    // if MathML, enrich and continue
    if (data.format === "MathML") {
        data.speakText = sre.toSpeech(data.math);
        data.math = sre.toEnriched(data.math).toString();
        data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
        callback(data);
    } else {
        // convert to MathML, enrich and continue
        const newdata = {
            math: data.math,
            format: data.format,
            mml: true
        };
        mathjax.typeset(newdata, function (result) {
            if (result.error) throw result.error;
            data.speakText = sre.toSpeech(result.mml);
            data.math = sre.toEnriched(result.mml).toString();
            data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
            data.format = 'MathML';
            callback(data);
github pkra / mathjax-node-sre / lib / main.js View on Github external
const postprocessor = function (speechConfig, result, input, callback) {
    if (result.error) throw result.error;
    if (!result.mml && !result.mmlNode) throw new Error('No MathML found. Please check the mathjax-node configuration');
    if (!result.svgNode && !result.htmlNode && !result.mmlNode) throw new Error('No suitable output found. Either svgNode, htmlNode or mmlNode are required.');
    if (!result.mml) result.mml = result.mmlNode.outerHTML;
    if (!speechConfig.speech) speechConfig.speech =  'deep';
    // add semantic tree
    if (speechConfig.semantic) {
        result.streeJson = sre.toJson(result.mml);
        const xml = sre.toSemantic(result.mml).toString();
        result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
    }
    // return if no speakText is requested
    if (!speechConfig.speakText) {
        callback(result, input);
        return
    }
    // enrich output
    sre.setupEngine(speechConfig);
    result.speakText = sre.toSpeech(result.mml);
    if (result.svgNode) {
        result.svgNode.querySelector('title').innerHTML = result.speakText;
        // update serialization
        // HACK add lost xlink namespaces TODO file jsdom bug
        if (result.svg) result.svg = result.svgNode.outerHTML
            .replace(/><([^/])/g, ">\n<$1")
            .replace(/(<\/[a-z]*>)(?=<\/)/g, "$1\n")
github pkra / mathjax-node-sre / lib / main.js View on Github external
const postprocessor = function (speechConfig, result, input, callback) {
    if (result.error) throw result.error;
    if (!result.mml && !result.mmlNode) throw new Error('No MathML found. Please check the mathjax-node configuration');
    if (!result.svgNode && !result.htmlNode && !result.mmlNode) throw new Error('No suitable output found. Either svgNode, htmlNode or mmlNode are required.');
    if (!result.mml) result.mml = result.mmlNode.outerHTML;
    if (!speechConfig.speech) speechConfig.speech =  'deep';
    // add semantic tree
    if (speechConfig.semantic) {
        result.streeJson = sre.toJson(result.mml);
        const xml = sre.toSemantic(result.mml).toString();
        result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
    }
    // return if no speakText is requested
    if (!speechConfig.speakText) {
        callback(result, input);
        return
    }
    // enrich output
    sre.setupEngine(speechConfig);
    result.speakText = sre.toSpeech(result.mml);
    if (result.svgNode) {
        result.svgNode.querySelector('title').innerHTML = result.speakText;
        // update serialization
        // HACK add lost xlink namespaces TODO file jsdom bug
        if (result.svg) result.svg = result.svgNode.outerHTML
github pkra / mathjax-node-sre / lib / main.js View on Github external
const postprocessor = function (speechConfig, result, input, callback) {
    if (result.error) throw result.error;
    if (!result.mml && !result.mmlNode) throw new Error('No MathML found. Please check the mathjax-node configuration');
    if (!result.svgNode && !result.htmlNode && !result.mmlNode) throw new Error('No suitable output found. Either svgNode, htmlNode or mmlNode are required.');
    if (!result.mml) result.mml = result.mmlNode.outerHTML;
    if (!speechConfig.speech) speechConfig.speech =  'deep';
    // add semantic tree
    if (speechConfig.semantic) {
        result.streeJson = sre.toJson(result.mml);
        const xml = sre.toSemantic(result.mml).toString();
        result.streeXml = speechConfig.minSTree ? xml : sre.pprintXML(xml);
    }
    // return if no speakText is requested
    if (!speechConfig.speakText) {
        callback(result, input);
        return
    }
    // enrich output
    sre.setupEngine(speechConfig);
    result.speakText = sre.toSpeech(result.mml);
    if (result.svgNode) {
        result.svgNode.querySelector('title').innerHTML = result.speakText;
        // update serialization
        // HACK add lost xlink namespaces TODO file jsdom bug
        if (result.svg) result.svg = result.svgNode.outerHTML
            .replace(/><([^/])/g, ">\n<$1")
github pkra / mathjax-node-sre / lib / main.js View on Github external
mathjax.typeset(newdata, function (result) {
            if (result.error) throw result.error;
            data.speakText = sre.toSpeech(result.mml);
            data.math = sre.toEnriched(result.mml).toString();
            data.math = data.math.replace(/alttext="(.*?)"/,'alttext="' + data.speakText + '"');
            data.format = 'MathML';
            callback(data);
        });
    }

speech-rule-engine

A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.

Apache-2.0
Latest version published 4 days ago

Package Health Score

78 / 100
Full package analysis