Skip to content

Commit 5deb7ec

Browse files
committed
Update speech generator-lab (still need to fix markup menu)
1 parent 87440c1 commit 5deb7ec

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

speech-generator/convert-with-speech.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,24 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta http-equiv="x-ua-compatible" content="ie=edge">
65
<meta name="viewport" content="width=device-width">
6+
<link rel="stylesheet" href="../styles/convert.css">
77
<title>Convert LaTeX or MathML to Speech</title>
88
<script>
99
MathJax = {
10-
loader: {load: ['input/asciimath', 'input/mml', 'input/tex', 'output/svg', 'a11y/sre']},
10+
loader: {load: ['input/asciimath', 'input/mml', 'input/tex', 'output/svg', 'a11y/speech']},
1111
tex: {inlineMath: {'[+]': [['$', '$']]}},
1212
startup: {
1313
ready: function() {
1414
MathJax.startup.defaultReady();
15-
// Initialise convert when MathJax/SRE is fully loaded.
16-
MathJax.startup.promise.then(function () {
17-
Convert.init();
18-
});
15+
// Initialize convert when MathJax/SRE is fully loaded.
16+
MathJax.startup.promise.then(() => Convert.init());
1917
}
2018
}
2119
};
2220
</script>
23-
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/startup.js"></script>
24-
<link rel="stylesheet" href="../styles/convert.css">
21+
<!-- <script defer src="https://cdn.jsdelivr.net/npm/mathjax@4.0.0-rc.4/startup.js"></script>-->
22+
<script defer src="../../MathJax-src/bundle/startup.js"></script>
2523
<script src="./convert-with-speech.js"></script>
2624
</head>
2725
<body>
@@ -72,9 +70,9 @@ <h2>Input:</h2>
7270

7371
<h2>Expression:</h2>
7472
<div id="rendered"></div>
75-
</div>
73+
</div><!--
7674
77-
<div class="output-panel converter" id="outputpanel">
75+
--><div class="output-panel converter" id="outputpanel">
7876

7977
<h2>Mathspeak Output:</h2>
8078
<div class="style-selector">

speech-generator/convert-with-speech.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Convert.setupSre = function() {
5656
};
5757

5858
Convert.init = function() {
59-
SRE = MathJax._.a11y.sre.Sre;
59+
SRE = MathJax._.a11y.sre_ts;
60+
MathJax.startup.document.getWebworker();
6061
Convert.getElements();
6162
Convert.setupSre();
6263
};
@@ -80,12 +81,18 @@ Convert.preferenceSelection = function(pref, values) {
8081
});
8182
};
8283

83-
Convert.setPreferences = function(locale) {
84+
Convert.setPreferences = async function(locale) {
8485
const container = Convert.divs.preferences;
8586
container.innerHTML = '';
8687
Convert.state.preferences = [];
8788

88-
const prefs = SRE.clearspeakPreferences.getLocalePreferences()[locale];
89+
const map = new Map();
90+
const mdoc= MathJax.startup.document;
91+
mdoc.options.sre.locale = locale
92+
await mdoc.webworker.Setup(mdoc.options.sre);
93+
await mdoc.webworker.clearspeakLocalePreferences(mdoc.options.sre, map);
94+
const prefs = map.get(locale);
95+
8996
if (!prefs) {
9097
Convert.state.clearspeak = false;
9198
Convert.textAreas.clearspeak.innerHTML = '';
@@ -160,20 +167,19 @@ Convert.setPreferences = function(locale) {
160167
}
161168
};
162169

163-
Convert.updatePreferences = async function(locale) {
164-
return SRE.setupEngine({locale: locale})
165-
.then(() => Convert.setPreferences(locale));
170+
Convert.updatePreferences = function(locale) {
171+
return Convert.setPreferences(locale);
166172
};
167173

168174

169-
Convert.computeClearspeak = async function() {
175+
Convert.computeClearspeak = function() {
170176
return Convert.computeSpeech(
171177
Convert.textAreas.clearspeak, 'clearspeak',
172178
Convert.state.preferences.map((x) => x.value).join(':'));
173179
};
174180

175181

176-
Convert.computeMathspeak = async function() {
182+
Convert.computeMathspeak = function() {
177183
return Convert.computeSpeech(
178184
Convert.textAreas.mathspeak, 'mathspeak', Convert.selectors.style.value);
179185
};
@@ -182,10 +188,28 @@ Convert.computeMathspeak = async function() {
182188
Convert.computeSpeech = async function(node, domain, style) {
183189
const locale = Convert.selectors.locale.value;
184190
const modality = locale === 'nemeth' ? 'braille' : 'speech';
185-
return SRE.setupEngine(
186-
{locale: locale, domain: domain, modality: modality,
187-
style: style, markup: Convert.selectors.markup.value, pprint: true
188-
}).then(() => node.innerHTML = SRE.toSpeech(Convert.input2Mathml()));
191+
const mdoc = MathJax.startup.document;
192+
const options = mdoc.options.sre = {...mdoc.options.sre,
193+
locale, domain, modality, style, markup: Convert.selectors.markup.value, pprint: true
194+
};
195+
await mdoc.webworker.Setup(options);
196+
const data = JSON.parse(await mdoc.webworker.Post({
197+
cmd: 'speech',
198+
data: {
199+
mml: Convert.input2Mathml(),
200+
options: options
201+
}
202+
}));
203+
node.innerHTML = options.markup === 'ssml'
204+
? [
205+
'<!--?xml version="1.0"?-->\n',
206+
'<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis">',
207+
'<prosody rate="100%">',
208+
data.ssml,
209+
'</prosody>',
210+
'</speak>'
211+
].join('')
212+
: data.label;
189213
};
190214

191215

styles/convert.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ body {
99
.converter {
1010
display: inline-block;
1111
box-sizing: border-box;
12-
width: 48%;
12+
margin: 0 2px;
13+
width: calc(50% - 4px);
1314
min-width: 25em;
1415
vertical-align: top;
1516
background-color: var(--box-background);
@@ -97,7 +98,7 @@ body {
9798
.preferences-grid {
9899
display: flex;
99100
flex-wrap: wrap;
100-
gap: 1em 2em; /* vertical and horizontal gaps */
101+
gap: 1em 1em; /* vertical and horizontal gaps */
101102
margin-top: 1em;
102103
}
103104

0 commit comments

Comments
 (0)