From dabb5dbd7bdf8bf6f6f2b40fde8187881db8afbf Mon Sep 17 00:00:00 2001 From: baxtree Date: Mon, 9 Mar 2020 17:44:23 +0000 Subject: [PATCH 1/3] support lexicon, amazon:max-duration and amazon:domain conversational style and fix google media begin/end time --- package-lock.json | 154 ++++-- package.json | 4 +- src/wikivoice.pegjs | 89 +++- test/helper.js | 51 ++ test/wiki2ssml-extension-test.js | 312 ++++++++++++ test/wiki2ssml-test.js | 793 ++++++++++--------------------- yarn.lock | 110 +++-- 7 files changed, 878 insertions(+), 635 deletions(-) create mode 100644 test/helper.js create mode 100644 test/wiki2ssml-extension-test.js diff --git a/package-lock.json b/package-lock.json index 24e4185..47e4a1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,12 @@ "js-tokens": "^4.0.0" } }, + "@tootallnate/once": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.0.0.tgz", + "integrity": "sha512-KYyTT/T6ALPkIRd2Ge080X/BsXvy9O0hcWTtMWkPvwAwF99+vn6Dv4GzrFT/Nn1LePr+FFDbRXXlqmsy9lw2zA==", + "dev": true + }, "abbrev": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz", @@ -43,12 +49,29 @@ "dev": true }, "agent-base": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", - "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.0.tgz", + "integrity": "sha512-j1Q7cSCqN+AwrmDd+pzgqc0/NpC655x2bUf5ZjRIO77DcNBFmh+OgRNzF6OKdCC9RSCb19fGd99+bhXFdkRNqw==", "dev": true, "requires": { - "es6-promisify": "^5.0.0" + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } } }, "ajv": { @@ -211,16 +234,16 @@ "dev": true }, "codecov": { - "version": "3.6.1", - "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.6.1.tgz", - "integrity": "sha512-IUJB6WG47nWK7o50etF8jBadxdMw7DmoQg05yIljstXFBGB6clOZsIj6iD4P82T2YaIU3qq+FFu8K9pxgkCJDQ==", + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/codecov/-/codecov-3.6.5.tgz", + "integrity": "sha512-v48WuDMUug6JXwmmfsMzhCHRnhUf8O3duqXvltaYJKrO1OekZWpB/eH6iIoaxMl8Qli0+u3OxptdsBOYiD7VAQ==", "dev": true, "requires": { - "argv": "^0.0.2", - "ignore-walk": "^3.0.1", - "js-yaml": "^3.13.1", - "teeny-request": "^3.11.3", - "urlgrey": "^0.4.4" + "argv": "0.0.2", + "ignore-walk": "3.0.3", + "js-yaml": "3.13.1", + "teeny-request": "6.0.1", + "urlgrey": "0.4.4" } }, "color-convert": { @@ -302,21 +325,6 @@ "esutils": "^2.0.2" } }, - "es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "dev": true - }, - "es6-promisify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", - "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", - "dev": true, - "requires": { - "es6-promise": "^4.0.3" - } - }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -634,14 +642,65 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, + "http-proxy-agent": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", + "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", + "dev": true, + "requires": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "https-proxy-agent": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz", - "integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-4.0.0.tgz", + "integrity": "sha512-zoDhWrkR3of1l9QAL8/scJZyLu8j/gBkcwcaQOZh7Gyh/+uJQzGVETdgT30akuwkpL8HTRfssqI3BZuV18teDg==", "dev": true, "requires": { - "agent-base": "^4.3.0", - "debug": "^3.1.0" + "agent-base": "5", + "debug": "4" + }, + "dependencies": { + "agent-base": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz", + "integrity": "sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g==", + "dev": true + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } } }, "iconv-lite": { @@ -1218,6 +1277,15 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "stream-events": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/stream-events/-/stream-events-1.0.5.tgz", + "integrity": "sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg==", + "dev": true, + "requires": { + "stubs": "^3.0.0" + } + }, "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", @@ -1243,6 +1311,12 @@ "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "dev": true }, + "stubs": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", + "integrity": "sha1-6NK6H6nJBXAwPAMLaQD31fiavls=", + "dev": true + }, "supports-color": { "version": "5.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", @@ -1265,13 +1339,15 @@ } }, "teeny-request": { - "version": "3.11.3", - "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-3.11.3.tgz", - "integrity": "sha512-CKncqSF7sH6p4rzCgkb/z/Pcos5efl0DmolzvlqRQUNcpRIruOhY9+T1FsIlyEbfWd7MsFpodROOwHYh2BaXzw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-6.0.1.tgz", + "integrity": "sha512-TAK0c9a00ELOqLrZ49cFxvPVogMUFaWY8dUsQc/0CuQPGF+BOxOQzXfE413BAk2kLomwNplvdtMpeaeGWmoc2g==", "dev": true, "requires": { - "https-proxy-agent": "^2.2.1", + "http-proxy-agent": "^4.0.0", + "https-proxy-agent": "^4.0.0", "node-fetch": "^2.2.0", + "stream-events": "^1.0.5", "uuid": "^3.3.2" } }, @@ -1360,9 +1436,9 @@ "dev": true }, "uuid": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz", - "integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "dev": true }, "which": { diff --git a/package.json b/package.json index f32ca41..98f8e0e 100755 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "index.js", "scripts": { "lint": "./node_modules/eslint/bin/eslint.js ./src/wiki2ssml.js ./test/wiki2ssml-test.js", - "test": "./node_modules/mocha/bin/mocha ./test", + "test": "./node_modules/mocha/bin/mocha ./test/*-test.js", "coverage": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec", "codecov": "./node_modules/.bin/codecov" }, @@ -39,7 +39,7 @@ }, "devDependencies": { "chai": "^4.2.0", - "codecov": "^3.6.1", + "codecov": "^3.6.5", "eslint": "^5.12.1", "istanbul": "^0.4.5", "mocha": "^5.2.0", diff --git a/src/wikivoice.pegjs b/src/wikivoice.pegjs index 2626a6f..50f1811 100755 --- a/src/wikivoice.pegjs +++ b/src/wikivoice.pegjs @@ -54,7 +54,7 @@ return matches.join(""); } - function toDigits(matches) { + function toFlattened(matches) { return matches.toString().split(",").join(""); } /* eslint-disable */ @@ -126,6 +126,7 @@ Statement / Mark / SeeAlso / CacheControl + / Lexicon / VendorExtension Prosody @@ -395,6 +396,27 @@ CacheControl return '' } +Lexicon + = LexiconUriMediaType / LexiconMediaTypeUri / LexiconUri + +LexiconUri + = "[[" _ ("lexicon"i / "lex"i) _ ":" uri:(!"]]" .)+ "]]" + { + return '' + } + +LexiconUriMediaType + = "[[" _ ("lexicon"i / "lex"i) _ ":" _ uri:(!"," .)+ _ "," _ ("type"i / "typ"i) _ ":" _ type:(!"]]" .)+ "]]" + { + return '' + } + +LexiconMediaTypeUri + = "[[" _ ("type"i / "typ"i) _ ":" _ type:(!"," .)+ _ "," _ ("lexicon"i / "lex"i) _ ":" _ uri:(!"]]" .)+ "]]" + { + return '' + } + _ "optional whitespace" = [ \t\n\r]* @@ -432,7 +454,7 @@ NON_NEGATIVE_PERCENTAGE = [0-9]+"%" VendorExtension - = AmazonWhispered / AmazonPhonation / AmazonTimbre / AmazonDynamicRangeCompression + = AmazonWhispered / AmazonPhonation / AmazonTimbre / AmazonDynamicRangeCompression / AmazonMaxDuration / AmazonBreathSound / AmazonAutoBreathSound / AmazonSpeakingStyle / AmazonEmotionIntensity / AmazonIntensityEmotion / GoogleMediaContainer / IBMExpressiveness / IBMVoiceTransformation / IBMVoiceCustomTransformation @@ -462,6 +484,12 @@ AmazonDynamicRangeCompression return '' + target + ''; } +AmazonMaxDuration + = "[[" _ ("amz-max-duration"i / "amz-max-dur"i / "amzMaxDuration"i / "amd"i) _ ":" _ duration:AMAZON_MAX_DURATION _"|" target:Target "]]" + { + return '' + target + ''; + } + AmazonBreathSound = AmazonBreathDurationVolume / AmazonBreathVolumeDuration / AmazonBreathDuration / AmazonBreathVolume @@ -572,7 +600,6 @@ AmazonAutoBreathsFrequencyDuration return '' + target + ''; } - AmazonAutoBreathsDurationFrequency = "[[" _ ("amz-auto-breaths-duration"i / "amz-aut-bre-dur"i / "amzAutoBreathsDuration"i / "abd"i) _ ":" _ duration:AMAZON_DURATION _ "," _ ("amz-auto-breaths-frequency"i / "amz-aut-bre-fre"i / "amzAutoBreathsFrequency"i / "abf"i) _ ":" _ frequency:AMAZON_FREQUENCY _ "|" target:Target "]]" { @@ -634,7 +661,7 @@ AMAZON_DURATION = "x-short" / "short" / "medium" / "long" / "x-long" / "default" AMAZON_STYLE - = "music" / "news" + = "music" / "news" / "conversational" AMAZON_EMOTION = "excited" / "disappointed" @@ -642,8 +669,12 @@ AMAZON_EMOTION AMAZON_INTENSITY = "low" / "medium" / "high" +AMAZON_MAX_DURATION + = [0-9]+(.[0-9]+)?"s" / [0-9]+(.[0-9]+)?"ms" + GoogleMediaContainer - = GoolgeMediaSpeak / GoolgeMediaSpeakEnd / GoolgeMediaAudio + = GoolgeMediaSpeak / GoolgeMediaSpeakBegin / GoolgeMediaSpeakEnd / GoolgeMediaSpeakBeginEnd / GoolgeMediaSpeakEndBegin + / GoolgeMediaAudio / GoolgeMediaSpeakFadeInFadeOut / GoolgeMediaSpeakFadeOutFadeIn / GoolgeMediaAudioFadeInFadeOutMedia / GoolgeMediaAudioFadeOutFadeInMedia / GoolgeMediaAudioMediaFadeInFadeOut / GoolgeMediaAudioMediaFadeOutFadeIn @@ -654,11 +685,28 @@ GoolgeMediaSpeak { return '' + target + ''; } +GoolgeMediaSpeakBegin + = "[[" _ ("ggl-media-speak-begin"i / "ggl-med-spe-begin"i / "gglMediaSpeakBegin"i / "gmsb"i) _ ":" _ time:GoogleTime _ "|" target:Target "]]" + { + return '' + target + ''; + } GoolgeMediaSpeakEnd - = "[[" _ ("ggl-media-speak-end"i / "ggl-med-spe-end"i / "gglMediaSpeakEnd"i / "gmse"i) _ ":" _ time:TIME _ "|" target:Target "]]" + = "[[" _ ("ggl-media-speak-end"i / "ggl-med-spe-end"i / "gglMediaSpeakEnd"i / "gmse"i) _ ":" _ time:GoogleTime _ "|" target:Target "]]" { - return '' + target + ''; + return '' + target + ''; + } + +GoolgeMediaSpeakBeginEnd + = "[[" _ ("ggl-media-speak-begin"i / "ggl-med-spe-begin"i / "gglMediaSpeakBegin"i / "gmsb"i) _ ":" _ begin:GoogleTime _ "," _ ("ggl-media-speak-end"i / "ggl-med-spe-end"i / "gglMediaSpeakEnd"i / "gmse"i) _ ":" _ end:GoogleTime _ "|" target:Target "]]" + { + return '' + target + ''; + } + +GoolgeMediaSpeakEndBegin + = "[[" _ ("ggl-media-speak-end"i / "ggl-med-spe-end"i / "gglMediaSpeakEnd"i / "gmse"i) _ ":" _ end:GoogleTime _ "," _ ("ggl-media-speak-begin"i / "ggl-med-spe-begin"i / "gglMediaSpeakBegin"i / "gmsb"i) _ ":" _ begin:GoogleTime _ "|" target:Target "]]" + { + return '' + target + ''; } GoolgeMediaSpeakFadeInFadeOut @@ -713,6 +761,9 @@ GoolgeMediaAudioFadeOutMediaFadeIn return '' } +GoogleTime + = _ [+|-]? _ TIME / (!"." .)+."begin" _ [+|-]? _ TIME / (!"." .)+."end" _ [+|-]? _ TIME + IBMExpressiveness = "[[" _ ("ibm-expr-type"i / "ibm-expr-typ"i / "ibmExprType"i / "iet"i) _ ":" _ expressiveness:IBM_EXPRTYPE _ "|" target:Target "]]" { @@ -881,73 +932,73 @@ MicrosoftBackgroundAudio MicrosoftBackgroundAudioVolume = "[[" _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-volume"i / "mst-bg-aud-vol"i / "mstBackgroundAudioVolume"i / "mbv"i) _ ":" _ volume:MICROSOFT_VOLUME "]]" { - return '' + return '' } MicrosoftBackgroundVolumeAudio = "[[" _ ("mst-background-audio-volume"i / "mst-bg-aud-vol"i / "mstBackgroundAudioVolume"i / "mbv"i) _ ":" _ volume:MICROSOFT_VOLUME _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!("]]" / ",") .)+ "]]" { - return '' + return '' } MicrosoftBackgroundAudioFadeIn = "[[" _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundFadeInAudio = "[[" _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!("]]" / ",") .)+ "]]" { - return '' + return '' } MicrosoftBackgroundAudioFadeOut = "[[" _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundFadeOutAudio = "[[" _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!("]]" / ",") .)+ "]]" { - return '' + return '' } MicrosoftBackgroundAudioFadeInFadeOut = "[[" _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundAudioFadeOutFadeIn = "[[" _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundFadeInAudioFadeOut = "[[" _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundFadeInFadeOutAudio = "[[" _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!("]]" / ",") .)+ "]]" { - return '' + return '' } MicrosoftBackgroundFadeOutAudioFadeIn = "[[" _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mst-bg-aud"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!"," .)+ _ "," _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION "]]" { - return '' + return '' } MicrosoftBackgroundFadeOutFadeInAudio = "[[" _ ("mst-background-audio-fade-out"i / "mst-bg-aud-fad-out"i / "mstBackgroundAudioFadeOut"i / "mfo"i) _ ":" _ fade_out_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio-fade-in"i / "mst-bg-aud-fad-in"i / "mstBackgroundAudioFadeIn"i / "mfi"i) _ ":" _ fade_in_millis:MICROSOFT_FADE_DURATION _ "," _ ("mst-background-audio"i / "mstBackgroundAudio"i / "mba"i) _ ":" uri:(!("]]" / ",") .)+ "]]" { - return '' + return '' } MICROSOFT_VOLUME diff --git a/test/helper.js b/test/helper.js new file mode 100644 index 0000000..06807d3 --- /dev/null +++ b/test/helper.js @@ -0,0 +1,51 @@ +"use strict"; + +var expect = require("chai").expect; +var xml2js = require("xml2js"); + +module.exports = (() => { + + const _HEAD = ""; + const _EXTENDED_HEAD = ""; + const _TAIL = ""; + + function _runHappyTests(tests, undertest) { + tests.forEach((test) => { + it("should parse " + test.expression + " and output SSML string", () => { + var parsed = undertest.parseToSsml(test.expression, "en-GB"); + expect(parsed).to.be.have.string(" { expect(err).to.be.null; }); + }); + }); + } + + function _runSadTests(tests, undertest) { + tests.forEach((test) => { + it("should fail on parsing " + test.expression, () => { + try { + undertest.parseToSsml(test.expression, "en-GB"); + expect.fail(); + } catch (e) { + expect(e instanceof test.expected).to.be.true; + expect(e.message).to.have.string("Expected"); + } + }); + }); + } + + return { + HEAD: _HEAD, + EXTENDED_HEAD: _EXTENDED_HEAD, + TAIL: _TAIL, + runHappyTests: _runHappyTests, + runSadTests: _runSadTests + }; +})(); \ No newline at end of file diff --git a/test/wiki2ssml-extension-test.js b/test/wiki2ssml-extension-test.js new file mode 100644 index 0000000..dbfb90f --- /dev/null +++ b/test/wiki2ssml-extension-test.js @@ -0,0 +1,312 @@ +"use strict"; + +var helper = require("./helper"); + +describe("Test wiki2ssml", () => { + + var undertest; + + describe("Vendor extensions", () => { + describe("Amazon Polly", () => { + undertest = require("../src/wiki2ssml"); + var happy = [ + { expression: "[[amzWhispered|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-whispered|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[aws|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzPhonation:soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-phonation:soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[aph:soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzTimbre:+15%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-timbre:+15%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ati:+15%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzDRC|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-drc|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[adr|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-max-duration:5s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-max-dur:5s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzMaxDuration:5s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amd:5s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzBreathDuration:medium,amzBreathVolume:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amz-breath-duration:medium,amz-breath-volume:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[abd:medium,abv:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amzBreathVolume:x-loud,amzBreathDuration:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amz-breath-volume:x-loud,amz-breath-duration:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[abv:x-loud,abd:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amzBreathVolume:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amz-breath-volume:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[abv:x-loud]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amzBreathDuration:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amz-breath-duration:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[abd:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amzDefaultBreath]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amz-default-breath]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[adb]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[amzAutoBreathsVolume:medium,amzAutoBreathsFrequency:low,amzAutoBreathsDuration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-volume:medium,amz-auto-breaths-frequency:low,amz-auto-breaths-duration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abv:medium,abf:low,abd:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsVolume:medium,amzAutoBreathsDuration:long,amzAutoBreathsFrequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-volume:medium,amz-auto-breaths-duration:long,amz-auto-breaths-frequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abv:medium,abd:long,abf:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsDuration:long,amzAutoBreathsFrequency:low,amzAutoBreathsVolume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-duration:long,amz-auto-breaths-frequency:low,amz-auto-breaths-volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abd:long,abf:low,abv:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsDuration:long,amzAutoBreathsVolume:medium,amzAutoBreathsFrequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-duration:long,amz-auto-breaths-volume:medium,amz-auto-breaths-frequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abd:long,abv:medium,abf:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsFrequency:low,amzAutoBreathsVolume:medium,amzAutoBreathsDuration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-frequency:low,amz-auto-breaths-volume:medium,amz-auto-breaths-duration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abf:low,abv:medium,abd:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsFrequency:low,amzAutoBreathsDuration:long,amzAutoBreathsVolume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-frequency:low,amz-auto-breaths-duration:long,amz-auto-breaths-volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abf:low,abd:long,abv:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsVolume:medium,amzAutoBreathsFrequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-volume:medium,amz-auto-breaths-frequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abv:medium,abf:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsFrequency:low,amzAutoBreathsVolume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-frequency:low,amz-auto-breaths-volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abf:low,abv:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsDuration:long,amzAutoBreathsVolume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-duration:long,amz-auto-breaths-volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abd:long,abv:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsVolume:medium,amzAutoBreathsDuration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-volume:medium,amz-auto-breaths-duration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abv:medium,abd:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsFrequency:low,amzAutoBreathsDuration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-frequency:low,amz-auto-breaths-duration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abf:low,abd:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsDuration:long,amzAutoBreathsFrequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-duration:long,amz-auto-breaths-frequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abd:long,abf:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsVolume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abv:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsFrequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-frequency:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abf:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzAutoBreathsDuration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-auto-breaths-duration:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[abd:long|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzDefaultAutoBreaths|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-default-auto-breaths|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[adb|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzSpeakingStyle:music|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-speaking-style:music|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ass:music|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzSpeakingStyle:news|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-speaking-style:news|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ass:news|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzSpeakingStyle:conversational|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-speaking-style:conversational|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ass:conversational|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzEmotion:excited,amzIntensity:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-emotion:excited,amz-intensity:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[aem:excited,ain:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amzIntensity:low,amzEmotion:excited|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[amz-intensity:low,amz-emotion:excited|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ain:low,aem:excited|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL } + ]; + + var sad = [ + { expression: "[[amzPhonation:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzTimbre:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amz-max-duration:5m|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amz-max-duration:5h|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzBreathVolume:unknown]]", expected: undertest.SyntaxError }, + { expression: "[[amzBreathDuration:unknown]]", expected: undertest.SyntaxError }, + { expression: "[[amzAutoBreathsVolume:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzAutoBreathsFrequency:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzAutoBreathsDuration:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzSpeakingStyle:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzEmotion:unknown,amzIntensity:low|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[amzIntensity:unknown, amzEmotion:excited|TEXT]]", expected: undertest.SyntaxError } + ]; + + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); + }); + }); + + describe("Google Text to Speech", () => { + undertest = require("../src/wiki2ssml"); + var happy = [ + { expression: "[[gglMediaSpeak|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gms|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakBegin:-10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-begin:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gmsb:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakEnd:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-end:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gmse:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakBegin:5s,gglMediaSpeakEnd:10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakEnd:10s,gglMediaSpeakBegin:5s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-end:+10s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-begin:foo_id.begin+250ms|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-end:foo_id.end-250ms|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakFadeIn:1s,gglMediaSpeakFadeOut:2s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-fade-in:1s,ggl-media-speak-fade-out:2s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaSpeakFadeOut:2s,gglMediaSpeakFadeIn:1s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ggl-media-speak-fade-out:2s,ggl-media-speak-fade-in:1s|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[gglMediaAudio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gma:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudioFadeIn:1ms,gglMediaAudioFadeOut:2ms,gglMediaAudio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio-fade-in:1ms,ggl-media-audio-fade-out:2ms,ggl-media-audio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudio:https://example.mp3,gglMediaAudioFadeIn:1ms,gglMediaAudioFadeOut:2ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio:https://example.mp3,gglMediaAudioFadeIn:1ms,gglMediaAudioFadeOut:2ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudio:https://example.mp3,gglMediaAudioFadeOut:2s,gglMediaAudioFadeIn:1s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio:https://example.mp3,gglMediaAudioFadeOut:2s,gglMediaAudioFadeIn:1s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudioFadeIn:1ms,gglMediaAudio:https://example.mp3,gglMediaAudioFadeOut:2ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio-fade-in:1ms,ggl-media-audio:https://example.mp3,ggl-media-audio-fade-out:2ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudioFadeOut:2s,gglMediaAudio:https://example.mp3,gglMediaAudioFadeIn:1s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio-fade-out:2s,ggl-media-audio:https://example.mp3,gglMediaAudioFadeIn:1s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gfi:1ms,gfo:2ms,gglMediaAudio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gfi:1ms,gfo:2ms,ggl-media-audio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gglMediaAudioFadeOut:2ms,gglMediaAudioFadeIn:1ms,gglMediaAudio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[ggl-media-audio-fade-out:2ms,ggl-media-audio-fade-in:1ms,ggl-media-audio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gfo:2ms,gfi:1ms,gglMediaAudio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[gfo:2ms,gfi:1ms,ggl-media-audio:https://example.mp3]]", expected: helper.HEAD + "" + helper.TAIL } + ]; + + var sad = [ + { expression: "[[gglMediaSpeakEnd:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[gglMediaAudioFadeOut:unknown,gglMediaAudioFadeIn:1ms,gglMediaAudio:https://example.mp3]]", expected: undertest.SyntaxError }, + { expression: "[[gglMediaAudioFadeOut:2s,gglMediaAudioFadeIn:unknown,gglMediaAudio:https://example.mp3]]", expected: undertest.SyntaxError } + ]; + + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); + }); + + describe("IBM Watson Text to Speech", () => { + undertest = require("../src/wiki2ssml"); + var happy = [ + { expression: "[[ibmExprType:GoodNews|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-expr-type:GoodNews|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[iet:GoodNews|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransType:Young,ibmTransStrength:80%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-type:Young,ibm-trans-strength:80%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itt:Young,its:80%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransStrength:80%,ibmTransType:Young|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-strength:80%,ibm-trans-type:Young|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransType:Young|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-type:Young|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itt:Young|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransBreathiness:high,ibmTransPitchRange:wide,ibmTransTimbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-breathiness:high,ibm-trans-pitch-range:wide,ibm-trans-timbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itb:high,itp:wide,itm:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransBreathiness:high,ibmTransTimbre:Sunrise,ibmTransPitchRange:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-breathiness:high,ibm-trans-timbre:Sunrise,ibm-trans-pitch-range:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itb:high,itm:Sunrise,itp:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransPitchRange:wide,ibmTransTimbre:Sunrise,ibmTransBreathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itp:wide,itm:Sunrise,itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransPitchRange:wide,ibmTransBreathiness:high,ibmTransTimbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-pitch-range:wide,ibm-trans-breathiness:high,ibm-trans-timbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itp:wide,itb:high,itm:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransTimbre:Sunrise,ibmTransBreathiness:high,ibmTransPitchRange:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-timbre:Sunrise,ibm-trans-breathiness:high,ibm-trans-pitch-range:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itm:Sunrise,itp:wide,itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransTimbre:Sunrise,ibmTransPitchRange:wide,ibmTransBreathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-timbre:Sunrise,ibm-trans-pitch-range:wide,ibm-trans-breathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itm:Sunrise,itp:wide,itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransBreathiness:high,ibmTransPitchRange:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-breathiness:high,ibm-trans-pitch-range:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itb:high,itp:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransBreathiness:high,ibmTransTimbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-breathiness:high,ibm-trans-timbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itb:high,itm:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransPitchRange:wide,ibmTransTimbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-pitch-range:wide,ibm-trans-timbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itp:wide,itm:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransPitchRange:wide,ibmTransBreathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-pitch-range:wide,ibm-trans-breathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itp:wide,itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransTimbre:Sunrise,ibmTransBreathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-timbre:Sunrise,ibm-trans-breathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itm:Sunrise,itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransTimbre:Sunrise,ibmTransPitchRange:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-timbre:Sunrise,ibm-trans-pitch-range:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itm:Sunrise,itp:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransBreathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-breathiness:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itb:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransPitchRange:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-pitch-range:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itp:wide|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibmTransTimbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[ibm-trans-timbre:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[itm:Sunrise|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL } + ]; + + var sad = [ + { expression: "[[ibmExprType:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[ibmTransType:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[ibmTransStrength:unknown,ibmTransType:Young|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[ibmTransBreathiness:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[ibmTransPitchRange:unknown|TEXT]]", expected: undertest.SyntaxError }, + { expression: "[[ibmTransTimbre:unknown|TEXT]]",expected: undertest.SyntaxError } + ]; + + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); + }); + + describe("Microsoft Cognitive Speech Service", () => { + undertest = require("../src/wiki2ssml"); + var happy = [ + { expression: "[[mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioVolume:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mstBackgroundAudioVolume:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3,mbv:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3,mbv:50]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3,mbv:100]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioVolume:0,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-volume:0,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mbv:0,mba:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mstBackgroundAudioFadeIn:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mst-background-audio-fade-in:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeIn:0,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-in:0,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeIn:10000,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-in:10000,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3,mfi:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mst-background-audio-fade-out:0]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mst-background-audio-fade-out:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeOut:0,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-out:0,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeOut:10000,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-out:10000,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mba:https://example.mp3,mfo:10000]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:10,mstBackgroundAudioFadeOut:20]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mst-background-audio-fade-in:10,mst-background-audio-fade-out:20]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:20,mstBackgroundAudioFadeIn:10]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio:https://example.mp3,mst-background-audio-fade-out:20,mst-background-audio-fade-in:10]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeIn:10,mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:20]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-in:10,mst-background-audio:https://example.mp3,mst-background-audio-fade-out:20]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeIn:10,mstBackgroundAudioFadeOut:20,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-in:10,mst-background-audio-fade-out:20,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeOut:20,mstBackgroundAudioFadeIn:10,mstBackgroundAudio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-out:20,mst-background-audio-fade-in:10,mst-background-audio:https://example.mp3]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mstBackgroundAudioFadeOut:20,mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:10]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL }, + { expression: "[[mst-background-audio-fade-out:20,mst-background-audio:https://example.mp3,mst-background-audio-fade-in:10]]", expected: helper.EXTENDED_HEAD + "" + helper.TAIL } + ]; + + var sad = [ + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioVolume:101]]", expected: undertest.SyntaxError }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioVolume:-1]]", expected: undertest.SyntaxError }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:10001]]", expected: undertest.SyntaxError }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeIn:-1]]", expected: undertest.SyntaxError }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:10001]]", expected: undertest.SyntaxError }, + { expression: "[[mstBackgroundAudio:https://example.mp3,mstBackgroundAudioFadeOut:-1]]", expected: undertest.SyntaxError } + ]; + + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); + }); +}); diff --git a/test/wiki2ssml-test.js b/test/wiki2ssml-test.js index 95b6022..8892f8b 100755 --- a/test/wiki2ssml-test.js +++ b/test/wiki2ssml-test.js @@ -2,20 +2,11 @@ var expect = require("chai").expect; var xml2js = require("xml2js"); +var helper = require("./helper"); describe("Test wiki2ssml", () => { var undertest; - const HEAD = ""; - const EXTENDED_HEAD = ""; - const TAIL = ""; describe("Test grammar", () => { it("should have no grammar errors", () => { @@ -31,73 +22,73 @@ describe("Test wiki2ssml", () => { describe("Speed, pitch and volume", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "[[speed:x-slow|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:slow|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:fast|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:x-fast|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:default|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:x-slow|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:slow|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:fast|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:x-fast|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:default|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:x-low|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:low|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:high|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:x-high|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:default|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:+5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:-5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:x-low|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:low|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:high|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:x-high|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:default|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:+5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:-5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:+5Hz|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:+5Hz|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:+12st|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:+12st|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:silent|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:x-soft|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:soft|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:loud|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:x-loud|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:+6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:-6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:silent|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:x-soft|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:soft|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:loud|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:x-loud|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:default|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:+6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:-6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:medium,speed:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[vol:+6dB,spe:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:medium,volume:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:5%,vol:+6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:medium,pitch:+5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pit:+5%,vol:+6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[spe:medium,pit:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:medium,speed:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[speed:medium,volume:+6dB,pitch:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:medium,speed:5%,pitch:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[volume:+6dB,pitch:medium,speed:medium|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:medium,volume:medium,speed:5%|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[pitch:medium,speed:medium,volume:+6dB|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "no markups", expected: HEAD + "no markups" + TAIL } + { expression: "[[speed:x-slow|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:slow|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:fast|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:x-fast|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:default|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:x-slow|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:slow|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:fast|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:x-fast|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:default|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:x-low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:x-high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:default|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:+5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:-5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:x-low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:low|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:x-high|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:default|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:+5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:-5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:+5Hz|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:+5Hz|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:+12st|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:+12st|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:silent|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:x-soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:loud|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:x-loud|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:+6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:-6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:silent|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:x-soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:soft|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:loud|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:x-loud|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:default|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:+6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:-6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:medium,speed:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[vol:+6dB,spe:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:medium,volume:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:5%,vol:+6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:medium,pitch:+5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pit:+5%,vol:+6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[spe:medium,pit:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:medium,speed:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[speed:medium,volume:+6dB,pitch:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:medium,speed:5%,pitch:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[volume:+6dB,pitch:medium,speed:medium|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:medium,volume:medium,speed:5%|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[pitch:medium,speed:medium,volume:+6dB|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "no markups", expected: helper.HEAD + "no markups" + helper.TAIL } ]; var sad = [ @@ -106,15 +97,15 @@ describe("Test wiki2ssml", () => { { expression: "[[volume:unknown|TEXT]]", expected: undertest.SyntaxError } ]; - runHappyTests(happy); - runSadTests(sad); + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); }); describe("Time containers", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "*[[pitch:medium,speed:medium,volume:+6dB|TEXT]]*", expected: HEAD + "TEXT" + TAIL }, - { expression: "#[[pitch:medium,speed:medium,volume:+6dB|TEXT]][[pitch:medium,speed:medium,volume:+6dB|TEXT]]#", expected: HEAD + "TEXTTEXT" + TAIL } + { expression: "*[[pitch:medium,speed:medium,volume:+6dB|TEXT]]*", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "#[[pitch:medium,speed:medium,volume:+6dB|TEXT]][[pitch:medium,speed:medium,volume:+6dB|TEXT]]#", expected: helper.HEAD + "TEXTTEXT" + helper.TAIL } ]; var sad = [ @@ -124,52 +115,52 @@ describe("Test wiki2ssml", () => { { expression: "#[[pitch:medium,speed:medium,volume:+6dB|TEXT]]*", expected: undertest.SyntaxError } ]; - runHappyTests(happy); - runSadTests(sad); + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); }); describe("Emphasis level", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "[[emphasis:strong|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emphasis:moderate|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emphasis:none|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emphasis:reduced|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emp:strong|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emp:moderate|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emp:none|TEXT]]", expected: HEAD + "TEXT" + TAIL }, - { expression: "[[emp:reduced|TEXT]]", expected: HEAD + "TEXT" + TAIL }, + { expression: "[[emphasis:strong|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emphasis:moderate|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emphasis:none|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emphasis:reduced|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emp:strong|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emp:moderate|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emp:none|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, + { expression: "[[emp:reduced|TEXT]]", expected: helper.HEAD + "TEXT" + helper.TAIL }, ]; var sad = [ { expression: "[[emphasis:unknown|TEXT]]", expected: undertest.SyntaxError } ]; - runHappyTests(happy); - runSadTests(sad); + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); }); describe("Silence with duration", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "[[strength:none]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:x-weak]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:weak]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:medium]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:strong]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:x-strong]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:none]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:x-weak]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:weak]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:medium]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:strong]]", expected: HEAD + "" + TAIL }, - { expression: "[[str:x-strong]]", expected: HEAD + "" + TAIL }, - { expression: "[[silence:100s]]", expected: HEAD + "" + TAIL }, - { expression: "[[silence:100ms]]", expected: HEAD + "" + TAIL }, - { expression: "[[sil:100s]]", expected: HEAD + "" + TAIL }, - { expression: "[[sil:100ms]]", expected: HEAD + "" + TAIL }, - { expression: "[[silence:150ms,strength:medium]]", expected: HEAD + "" + TAIL }, - { expression: "[[strength:medium,silence:0.5s]]", expected: HEAD + "" + TAIL } + { expression: "[[strength:none]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:x-weak]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:weak]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:strong]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:x-strong]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:none]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:x-weak]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:weak]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:strong]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[str:x-strong]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[silence:100s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[silence:100ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[sil:100s]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[sil:100ms]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[silence:150ms,strength:medium]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[strength:medium,silence:0.5s]]", expected: helper.HEAD + "" + helper.TAIL } ]; var sad = [ @@ -177,146 +168,146 @@ describe("Test wiki2ssml", () => { { expression: "[[strength:unknown]]", expected: undertest.SyntaxError } ]; - runHappyTests(happy); - runSadTests(sad); + helper.runHappyTests(happy, undertest); + helper.runSadTests(sad, undertest); }); describe("Substitution", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "[[substitute:red color|red colour]]", expected: HEAD + "red colour" + TAIL }, - { expression: "[[substitute:red color|]]", expected: HEAD + "" + TAIL }, - { expression: "[[sub:red color|red colour]]", expected: HEAD + "red colour" + TAIL }, - { expression: "[[sub:red color|]]", expected: HEAD + "" + TAIL } + { expression: "[[substitute:red color|red colour]]", expected: helper.HEAD + "red colour" + helper.TAIL }, + { expression: "[[substitute:red color|]]", expected: helper.HEAD + "" + helper.TAIL }, + { expression: "[[sub:red color|red colour]]", expected: helper.HEAD + "red colour" + helper.TAIL }, + { expression: "[[sub:red color|]]", expected: helper.HEAD + "" + helper.TAIL } ]; - runHappyTests(happy); + helper.runHappyTests(happy, undertest); }); describe("Embedded audio", () => { undertest = require("../src/wiki2ssml"); var happy = [ - { expression: "[[audio:https://example.mp3]]", expected: HEAD + "