UNPKG

speech-rule-engine

Version:

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

64 lines (63 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractSpeechGenerator = void 0; const engine_setup_js_1 = require("../common/engine_setup.js"); const EnrichAttr = require("../enrich_mathml/enrich_attr.js"); const rebuild_stree_js_1 = require("../walker/rebuild_stree.js"); const SpeechGeneratorUtil = require("./speech_generator_util.js"); const locale_js_1 = require("../l10n/locale.js"); class AbstractSpeechGenerator { constructor() { this.modality = EnrichAttr.addPrefix('speech'); this.rebuilt_ = null; this.options_ = {}; } getRebuilt() { return this.rebuilt_; } setRebuilt(rebuilt) { this.rebuilt_ = rebuilt; } computeRebuilt(xml, force = false) { if (!this.rebuilt_ || force) { this.rebuilt_ = new rebuild_stree_js_1.RebuildStree(xml); } return this.rebuilt_; } setOptions(options) { this.options_ = options || {}; this.modality = EnrichAttr.addPrefix(this.options_.modality || 'speech'); } setOption(key, value) { const options = this.getOptions(); options[key] = value; this.setOptions(options); } getOptions() { return this.options_; } generateSpeech(_node, xml) { if (!this.rebuilt_) { this.rebuilt_ = new rebuild_stree_js_1.RebuildStree(xml); } (0, engine_setup_js_1.setupEngine)(this.options_); return SpeechGeneratorUtil.computeMarkup(this.getRebuilt().xml); } nextRules() { this.setOptions(SpeechGeneratorUtil.nextRules(this.getOptions())); } nextStyle(id) { this.setOption('style', SpeechGeneratorUtil.nextStyle(this.getRebuilt().nodeDict[id], this.getOptions())); } getLevel(depth) { return locale_js_1.LOCALE.MESSAGES.navigate.LEVEL + ' ' + depth; } getActionable(actionable) { return actionable ? actionable < 0 ? locale_js_1.LOCALE.MESSAGES.navigate.EXPANDABLE : locale_js_1.LOCALE.MESSAGES.navigate.COLLAPSIBLE : ''; } } exports.AbstractSpeechGenerator = AbstractSpeechGenerator;