PageSourceSearch

https://mathlive.io/assets/js/e7acc82b.0c54f5c2.js

js mathlive.io collected 2026-10-10 00:36:18 UTC 12,049 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkcortexjs_io||=[]).push([[4686],{3270(e,t,s){s.r(t),s.d(t,{assets:()=>h,contentTitle:()=>l,default:()=>d,frontMatter:()=>r,metadata:()=>n,toc:()=>c});const n=JSON.parse('{"id":"mathfield/speech","title":"Speech","description":"Speech output for mathfields: keyboard shortcuts to speak a formula or the selection, the speak command, and how to configure the speech engine.","source":"@site/docs/mathfield/19-speech.md","sourceDirName":"mathfield","slug":"/mathfield/guides/speech/","permalink":"/mathfield/guides/speech/","draft":false,"unlisted":false,"tags":[],"version":"current","lastUpdatedAt":1784940713000,"sidebarPosition":19,"frontMatter":{"date":"Last Modified","title":"Speech","slug":"/mathfield/guides/speech/","description":"Speech output for mathfields: keyboard shortcuts to speak a formula or the selection, the speak command, and how to configure the speech engine."},"sidebar":"docSidebar","previous":{"title":"Macros","permalink":"/mathfield/guides/macros/"},"next":{"title":"Static Math Formulas","permalink":"/mathfield/guides/static/"}}');var i=s(4848),o=s(8453);const r={date:"Last Modified",title:"Speech",slug:"/mathfield/guides/speech/",description:"Speech output for mathfields: keyboard shortcuts to speak a formula or the selection, the speak command, and how to configure the speech engine."},l=void 0,h={},c=[{value:"Using Speech Output",id:"using-speech-output",level:2},{value:"Configuring Speech Options",id:"configuring-speech-options",level:2},{value:"Speech Rules",id:"speech-rules",level:3},{value:"Text-to-Speech Engine",id:"text-to-speech-engine",level:3},{value:"Using the Local TTS Engine",id:"using-the-local-tts-engine",level:4},{value:"Using Amazon Polly TTS Engine",id:"using-amazon-polly-tts-engine",level:4},{value:"Speech Output Format",id:"speech-output-format",level:3}];function a(e){const t={a:"a",code:"code",h2:"h2",h3:"h3",h4:"h4",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,o.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.h2,{id:"using-speech-output",children:"Using Speech Output"}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To speak the formula or a portion of it"}),", use these keyboard shortcuts:"]}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)("kbd",{children:"alt/\u2325"})," + ",(0,i.jsx)("kbd",{children:"ctrl"})," + ",(0,i.jsx)("kbd",{children:"\u21e1"}),": speak the entire formula"]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)("kbd",{children:"alt/\u2325"})," + ",(0,i.jsx)("kbd",{children:"ctrl"})," + ",(0,i.jsx)("kbd",{children:"\u21e3"}),": speak the selection"]}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To programatically trigger speech output"}),", use:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"mf.executeCommand('speak');\n"})}),"\n",(0,i.jsx)(t.p,{children:"The command above will speak the entire formula. To speak a subset of the\nformula use:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"mf.executeCommand(['speak', 'selection');\n"})}),"\n",(0,i.jsx)(t.p,{children:'The options to specify the speech "scope" are:'}),"\n",(0,i.jsx)("div",{className:"symbols-table first-column-header",children:(0,i.jsxs)(t.table,{children:[(0,i.jsx)(t.thead,{children:(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.th,{style:{textAlign:"right"}}),(0,i.jsx)(t.th,{style:{textAlign:"left"}})]})}),(0,i.jsxs)(t.tbody,{children:[(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"all"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the entire formula"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"selection"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the selection portion of the formula"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"left"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the element to the left of the selection"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"right"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the element to the right of the selection"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"group"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the group (numerator, root, etc..) the selection is in"})]}),(0,i.jsxs)(t.tr,{children:[(0,i.jsx)(t.td,{style:{textAlign:"right"},children:(0,i.jsx)(t.code,{children:"parent"})}),(0,i.jsx)(t.td,{style:{textAlign:"left"},children:"the parent of the selection"})]})]})]})}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To get a textual representation of a spoken description of the formula"}),", use\nthe ",(0,i.jsx)(t.code,{children:"spoken-text"})," format:"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-js",children:"mf.getValue('spoken-text');\n"})}),"\n",(0,i.jsx)(t.h2,{id:"configuring-speech-options",children:"Configuring Speech Options"}),"\n",(0,i.jsx)(t.p,{children:"There are two aspects that can be configured independently:"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Speech Rules: the set of rules use to produce readable text from a math expression."}),"\n"]}),"\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsx)(t.p,{children:"Text-to-Speech engine: the softw
1are used to transform the readable text\nproduced by the speech rules into sound. By default, the TTS engine provide\nby the operating system will be used, but you can use the Amazon Cloud TTS engine as well."}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.h3,{id:"speech-rules",children:"Speech Rules"}),"\n",(0,i.jsxs)(t.p,{children:["A set of ",(0,i.jsx)(t.strong,{children:"speech rules"})," define how a math formula is transformed to speakable\ntext."]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To use the built-in speech rules"}),", set ",(0,i.jsx)(t.code,{children:"MathfieldElement.textToSpeechRules"})," to ",(0,i.jsx)(t.code,{children:'"mathlive"'}),"."]}),"\n",(0,i.jsx)(t.p,{children:"Another set of speech rules supported are the SRE speech rules from Volker Sorge"}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To use the SRE speech rules"}),":"]}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Include the browser version of the SRE JavaScript file in your project.\nYou can download it on ",(0,i.jsx)(t.a,{href:"https://github.com/zorkow/speech-rule-engine",children:"GitHub"})]}),"\n",(0,i.jsxs)(t.li,{children:["Set ",(0,i.jsx)(t.code,{children:"MathfieldElement.textToSpeechRules"})," to ",(0,i.jsx)(t.code,{children:'"sre"'}),"."]}),"\n"]}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To configure SRE"}),", set the ",(0,i.jsx)(t.code,{children:"MathfieldElement.textToSpeechRulesOptions"})," property."]}),"\n",(0,i.jsx)(t.p,{children:"For example:"}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-javascript",children:"MathfieldElement.textToSpeechRulesOptions = {\n    domain: 'mathspeak', // 'mathspeak' or 'chromevox'\n    ruleset: 'mathspeak-brief',   // 'mathspeak-default', \n    // 'mathspeak-brief', 'mathspeak-sbrief', 'chromevox-short', \n    // 'chromevox-default' or 'chromevox-alternative'\n};\n"})}),"\n",(0,i.jsx)(t.h3,{id:"text-to-speech-engine",children:"Text-to-Speech Engine"}),"\n",(0,i.jsx)(t.h4,{id:"using-the-local-tts-engine",children:"Using the Local TTS Engine"}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To use the local (built-in, OS specific) TTS engine"}),", set ",(0,i.jsx)(t.code,{children:"MathfieldElement.speechEngine"})," to ",(0,i.jsx)(t.code,{children:'"local"'}),"."]}),"\n",(0,i.jsx)(t.p,{children:"There is great variation between platforms (and browsers) on the quality of the TTS engine. However, it can be used even when offline, while the Amazon TTS engine offers higher quality and better consistency, but it does require a network connection."}),"\n",(0,i.jsx)(t.h4,{id:"using-amazon-polly-tts-engine",children:"Using Amazon Polly TTS Engine"}),"\n",(0,i.jsxs)(t.ol,{children:["\n",(0,i.jsxs)(t.li,{children:["Include the AWS SDK for JavaScript in your app. See ",(0,i.jsx)(t.a,{href:"https://aws.amazon.com/sdk-for-browser/",children:"here for details"}),".\nThis may be as simple as adding this:"]}),"\n"]}),"\n",(0,i.jsx)(t.pre,{children:(0,i.jsx)(t.code,{className:"language-html",children:"<head>\n    <script src=\"https://sdk.amazonaws.com/js/aws-sdk-2.657.0.min.js\"><\/script>\n    <script>\n        AWS.config.region = 'eu-west-1';\n        AWS.config.accessKeyId = 'YOUR-KEY';\n        AWS.config.secretAccessKey = 'YOUR-SECRET';\n    <\/script>\n</head>\n"})}),"\n",(0,i.jsxs)(t.p,{children:["See ",(0,i.jsx)(t.a,{href:"https://www.npmjs.com/package/aws-sdk",children:"npm"})," for the latest version."]}),"\n",(0,i.jsxs)(t.ol,{start:"2",children:["\n",(0,i.jsxs)(t.li,{children:["\n",(0,i.jsxs)(t.p,{children:["To get the necessary keys, follow ",(0,i.jsx)(t.a,{href:"https://docs.aws.amazon.com/polly/latest/dg/setting-up.html",children:"these instructions"})]}),"\n",(0,i.jsxs)(t.p,{children:["2.1 Create a custom policy in your ",(0,i.jsx)(t.a,{href:"https://console.aws.amazon.com/iam/home",children:"AWS console"})," with action: Read SynthesizeSpeech and a request condition of a referrer with a StringEquals to your domain, e.g. '",(0,i.jsx)(t.a,{href:"https://example.com/",children:"https://example.com/"}),"*'"]}),"\n",(0,i.jsx)(t.p,{children:"2.2 Create a group, and associated it with the policy above"}),"\n",(0,i.jsx)(t.p,{children:"2.3. Create a new user, for example the name of your app. Give it 'programmatic access' and associate it with the group above"}),"\n",(0,i.jsx)(t.p,{children:"2.4 At the end of the creation, you will be provided by the access key and the secret access key."}),"\n"]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"Carefully consider how to handle the access and secret access keys. With the setup above they are somewhat restricted to a domain, however, they could be abused if accessed by an unauthorized user. To prevent this, you could require users to authenticate and use AW
1S Cognito."}),"\n",(0,i.jsx)(t.h3,{id:"speech-output-format",children:"Speech Output Format"}),"\n",(0,i.jsxs)(t.p,{children:[(0,i.jsx)(t.strong,{children:"To configure the format of the speech output engine"}),", use the ",(0,i.jsx)(t.code,{children:"MathfieldElement.textToSpeechMarkup"}),". Set it to:"]}),"\n",(0,i.jsxs)(t.ul,{children:["\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:'"ssml"'})," to request an output using the SSML markup language. Both SRE and the Mathfield rules can produce this format."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:'"mac"'})," to request an output using Mac OS speech markup, e.g. '[[slc 150]]'. This format can only be used on Mac OS (and may not work will all browsers). On platforms other than Mac OS, this option does nothing."]}),"\n",(0,i.jsxs)(t.li,{children:[(0,i.jsx)(t.code,{children:'""'})," (empty string) to request no markup."]}),"\n"]}),"\n",(0,i.jsx)(t.p,{children:"The Amazon TTS engine supports SSML, and it is recommended to use this option for the highest quality."})]})}function d(e={}){const{wrapper:t}={...(0,o.R)(),...e.components};return t?(0,i.jsx)(t,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}},8453(e,t,s){s.d(t,{R:()=>r,x:()=>l});var n=s(6540);const i={},o=n.createContext(i);function r(e){const t=n.useContext(o);return n.useMemo(function(){return"function"==typeof e?e(t):{...t,...e}},[t,e])}function l(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:r(e.components),n.createElement(o.Provider,{value:t},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.