wiki2ssml
Advanced tools
Comparing version 0.2.3 to 0.2.4
{ | ||
"name": "wiki2ssml", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Wiki2SSML provides the WikiVoice markup language used for fine-tuning synthesised voice.", | ||
@@ -8,4 +8,6 @@ "license": "Apache-2.0", | ||
"scripts": { | ||
"lint": "./node_modules/eslint/bin/eslint.js ./src/wiki2ssml.js ./test/wiki2ssml-test.js", | ||
"test": "./node_modules/mocha/bin/mocha ./test", | ||
"lint": "./node_modules/eslint/bin/eslint.js ./src/wiki2ssml.js ./test/wiki2ssml-test.js" | ||
"coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec", | ||
"codecov": "./node_modules/.bin/codecov" | ||
}, | ||
@@ -24,3 +26,4 @@ "repository": { | ||
"ibm watson tts", | ||
"microsoft azure tts" | ||
"microsoft azure tts", | ||
"nuance" | ||
], | ||
@@ -36,7 +39,10 @@ "author": { | ||
"dependencies": { | ||
"pegjs": "^0.10.0" | ||
"pegjs": "^0.10.0", | ||
"prettify-xml": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"codecov": "^3.6.1", | ||
"eslint": "^5.12.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0", | ||
@@ -43,0 +49,0 @@ "xml2js": "^0.4.19" |
@@ -0,1 +1,5 @@ | ||
[![Build Status](https://travis-ci.com/baxtree/wiki2ssml.svg?branch=master)](https://travis-ci.com/baxtree/wiki2ssml) ![Codecov](https://img.shields.io/codecov/c/github/baxtree/wiki2ssml)![Node](https://img.shields.io/static/v1?label=node.js&message=≥6.4.0&color=green) | ||
[![GitHub license](https://img.shields.io/github/license/baxtree/wiki2ssml)](https://github.com/baxtree/wiki2ssml/blob/master/LICENSE) | ||
# Wiki2SSML | ||
@@ -17,3 +21,3 @@ `wiki2ssml` can transform the `WikiVoice` markups into the W3C SSML widely supported by various text-to-speech services as an interchange format for synthesised voice tuning. | ||
``` | ||
[[attribute:value(,attribute:value)*(|TEXT)*]] | ||
[[attribute(:value)*(,attribute:value)*(|target)*]] | ||
``` | ||
@@ -40,2 +44,4 @@ # Supported WikiVoice Markups | ||
| [[mark:NAME]] | Mark referencing a location | | ||
| [[seeAlso:URI] | URI providing additional information about marked-up content] | ||
| [[cacheControl:no-cache]] | No caching on marked-up content | | ||
@@ -57,5 +63,11 @@ # Supported Vendor-Specific Markups | ||
More details on canonical attribute values can be found at [Speech Synthesis Markup Language (SSML)](https://www.w3.org/TR/speech-synthesis/). For ranges of vendor-specific values please refer to their online documents. | ||
# parseToSsml(input, languageCode, options) | ||
- input `<string>` (required) | ||
- languageCode `<string>` (required: [RFC 1766](https://tools.ietf.org/html/rfc1766)) | ||
- options `<object>` (optional) | ||
- version `<string>` (default: "1.1") | ||
- pretty `<boolean>` (default: false) | ||
# Example | ||
@@ -65,9 +77,10 @@ ```js | ||
try { | ||
var ssml = parser.parseToSsml("[[volume:+2dB,speed:50%|Speak this with the volume increased by 2dB at half the default speech rate.]]", "en-GB"); | ||
var input = "[[volume:+2dB,speed:50%|Speak this with the volume increased by 2dB at half the default speech rate.]]"; | ||
var ssml = parser.parseToSsml(input, "en-GB", {pretty: true}); | ||
console.log(ssml); | ||
} catch (e) { | ||
if (e instanceof parser.SyntaxError) { | ||
// WikiVoice markups are invalid | ||
// The input does not have valid WikiVoice markups | ||
} else if (e instanceof parser.ArgumentError) { | ||
// The language code is missing | ||
// Either the input or the language code is missing | ||
} else { | ||
@@ -80,7 +93,6 @@ // Handle any unspecified exceptions | ||
```xml | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/10/synthesis http://www.w3.org/TR/speech-synthesis/synthesis.xsd" xml:lang="en-GB"> | ||
<prosody volume="+2dB" rate="50%"> | ||
Speak this with the volume increased by 2dB at half the default speech rate. | ||
</prosody> | ||
<prosody rate="50%" volume="+2dB">Speak this with the volume increased by 2dB at half the default speech rate.</prosody> | ||
</speak> | ||
``` |
@@ -5,2 +5,3 @@ "use strict"; | ||
var fs = require("fs"); | ||
var prettifyXml = require("prettify-xml"); | ||
@@ -27,15 +28,26 @@ module.exports = (() => { | ||
var _getSsmlAsString = (ssmlBody, language, version) => { | ||
return _getSsmlHead(language, version) + ssmlBody + _getSsmlTail(); | ||
var _getSsmlAsString = (ssmlBody, language, options) => { | ||
var ssml = _getSsmlHead(language, options.version) + ssmlBody + _getSsmlTail(); | ||
if (options.pretty) { | ||
return prettifyXml(ssml, {indent: 2, newline: "\n"}); | ||
} | ||
return ssml; | ||
}; | ||
var _parseToSsml = (ssmlStr, languageCode, version) => { | ||
var _parseToSsml = (input, languageCode, options) => { | ||
if (!input || input.length === 0) { | ||
throw new ArgumentError("Input is missing when calling parseToSsml"); | ||
} | ||
if (!languageCode) { | ||
throw new ArgumentError("Language code is missing when calling parseToSsml"); | ||
} | ||
if (typeof(version) === "undefined") { | ||
version = "1.1"; | ||
options = (typeof(options) === "undefined") ? {} : options; | ||
if (typeof(options.version) === "undefined") { | ||
options.version = "1.1"; | ||
} | ||
if (typeof(options.pretty) === "undefined") { | ||
options.pretty = false; | ||
} | ||
try { | ||
var parsed = _parser.parse(ssmlStr); | ||
var parsed = _parser.parse(input); | ||
} | ||
@@ -45,3 +57,3 @@ catch (e) { | ||
} | ||
return _getSsmlAsString(parsed, languageCode, version); | ||
return _getSsmlAsString(parsed, languageCode, options); | ||
}; | ||
@@ -86,4 +98,4 @@ | ||
parseToPlainText: (ssmlStr) => { | ||
var parsed = _parseToSsml(ssmlStr, "ANY"); | ||
parseToPlainText: (input) => { | ||
var parsed = _parseToSsml(input, "ANY"); | ||
return parsed.replace(/(<([^>]+)>)/ig, ""); | ||
@@ -94,4 +106,4 @@ }, | ||
try { | ||
var ssml_body = _parser.parse(input); | ||
return ssml_body !== input; | ||
var ssmlBody = _parser.parse(input); | ||
return ssmlBody !== input; | ||
} | ||
@@ -98,0 +110,0 @@ catch (e) { |
@@ -489,2 +489,14 @@ "use strict"; | ||
describe("Meta content", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
var happy = [ | ||
{ expression: "[[seeAlso:http://example.com/metadata.xml]]", expected: HEAD + "<meta name=\"seeAlso\" content=\"http://example.com/metadata.xml\"/>" + TAIL }, | ||
{ expression: "[[see:http://example.com/metadata.xml]]", expected: HEAD + "<meta name=\"seeAlso\" content=\"http://example.com/metadata.xml\"/>" + TAIL }, | ||
{ expression: "[[cacheControl:no-cache]]", expected: HEAD + "<meta http-equiv=\"Cache-Control\" content=\"no-cache\"/>" + TAIL }, | ||
{ expression: "[[cac:no-cache]]", expected: HEAD + "<meta http-equiv=\"Cache-Control\" content=\"no-cache\"/>" + TAIL } | ||
]; | ||
runHappyTests(happy); | ||
}); | ||
it("should ignore whitespaces", () => { | ||
@@ -522,8 +534,8 @@ undertest = require("../src/wiki2ssml"); | ||
it("should return original input which dose not have markups", () => { | ||
it("should output the original input which dose not have markups in SSML", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
var text_without_markup = "This is a test without markups"; | ||
var parsed = undertest.parseToSsml(text_without_markup, "en-GB"); | ||
var textWithoutMarkup = "This is a test without markups"; | ||
var parsed = undertest.parseToSsml(textWithoutMarkup, "en-GB"); | ||
expect(parsed).to.be.a("string"); | ||
expect(parsed).to.equal(HEAD + text_without_markup + TAIL); | ||
expect(parsed).to.equal(HEAD + textWithoutMarkup + TAIL); | ||
}); | ||
@@ -533,3 +545,3 @@ | ||
undertest = require("../src/wiki2ssml"); | ||
var parsed = undertest.parseToSsml("[[volume:+6dB|TEXT]]", "en-GB", "1.0"); | ||
var parsed = undertest.parseToSsml("[[volume:+6dB|TEXT]]", "en-GB", {version: "1.0"}); | ||
expect(parsed).to.be.a("string"); | ||
@@ -539,2 +551,13 @@ expect(parsed).to.have.string("version=\"1.0\""); | ||
it("should prettify SSML when configured", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
var parsed = undertest.parseToSsml("[[volume:+6dB|TEXT]]", "en-GB", {pretty: true}); | ||
var expected = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>", | ||
"<speak version=\"1.1\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.w3.org/2001/10/synthesis http://www.w3.org/TR/speech-synthesis/synthesis.xsd\" xml:lang=\"en-GB\">", | ||
" <prosody volume=\"+6dB\">TEXT</prosody>", | ||
"</speak>"].join("\n"); | ||
expect(parsed).to.be.a("string"); | ||
expect(parsed).to.equal(expected); | ||
}); | ||
it("should detect and validate markups", () => { | ||
@@ -565,2 +588,53 @@ undertest = require("../src/wiki2ssml"); | ||
}); | ||
describe("should throw ArgumentError on", () => { | ||
[ | ||
{ input: null, expected: undertest.ArgumentError }, | ||
{ input: undefined, expected: undertest.ArgumentError }, | ||
{ input: "", expected: undertest.ArgumentError } | ||
].forEach((test) => { | ||
it((test.input == "" ? "empty" : test.input) + " input", () => { | ||
try { | ||
undertest.parseToSsml(test.input, "en-GB"); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e instanceof test.expected).to.be.true; | ||
expect(e.message).to.equal("Input is missing when calling parseToSsml"); | ||
} | ||
}); | ||
}); | ||
}); | ||
it("should throw ArgumentError on null input", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
try { | ||
undertest.parseToSsml(null, "en-GB"); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e instanceof undertest.ArgumentError).to.be.true; | ||
expect(e.message).to.equal("Input is missing when calling parseToSsml"); | ||
} | ||
}); | ||
it("should throw ArgumentError on undefined input", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
try { | ||
undertest.parseToSsml(undefined, "en-GB"); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e instanceof undertest.ArgumentError).to.be.true; | ||
expect(e.message).to.equal("Input is missing when calling parseToSsml"); | ||
} | ||
}); | ||
it("should throw ArgumentError on empty input", () => { | ||
undertest = require("../src/wiki2ssml"); | ||
try { | ||
undertest.parseToSsml("", "en-GB"); | ||
expect.fail(); | ||
} catch (e) { | ||
expect(e instanceof undertest.ArgumentError).to.be.true; | ||
expect(e.message).to.equal("Input is missing when calling parseToSsml"); | ||
} | ||
}); | ||
@@ -567,0 +641,0 @@ it("should throw ArgumentError on missing language code", () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
172392
21
1172
94
2
6
+ Addedprettify-xml@^1.2.0
+ Addedprettify-xml@1.2.0(transitive)