Skip to content

Commit

Permalink
Merge pull request #23 from baxtree/development
Browse files Browse the repository at this point in the history
add more optional values and attributes
  • Loading branch information
baxtree authored Jun 18, 2020
2 parents c42cdac + 79d59a1 commit db81b81
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wiki2ssml",
"version": "0.2.14",
"version": "0.2.15",
"description": "Wiki2SSML provides the WikiVoice markup language used for fine-tuning synthesised voice.",
"license": "Apache-2.0",
"main": "index.js",
Expand Down
97 changes: 83 additions & 14 deletions src/wikivoice.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
}

function toTime(matches) {
var integral = matches[0].join("");
var decimal = matches[1] == undefined ? "" : matches[1][0] + matches[1][1].join("")
var unit = matches[2];
var sign = matches[0] == null ? "" : matches[0];
var integral = matches[1].join("");
var decimal = matches[2] == undefined ? "" : matches[2][0] + matches[2][1].join("")
var unit = matches[3];
return integral + decimal + unit;
}

Expand Down Expand Up @@ -231,27 +232,27 @@ Emphasis
}

Silence
= TimeStrength / StrengthTime / Time / Strength
= SilenceTimeStrength / SilenceStrengthTime / SilenceTime / SilenceStrength

TimeStrength
SilenceTimeStrength
= "[[" _ ("silence"i / "sil"i) _ ":" _ time:TIME _ "," _ ("strength"i / "str"i) _ ":" _ strength:STRENTH _ "]]"
{
return '<break strength="' + strength + '" time="' + toTime(time) + '"/>';
}

StrengthTime
SilenceStrengthTime
= "[[" _ ("strength"i / "str"i) _ ":" _ strength:STRENTH _ "," _ ("silence"i / "sil"i) _ ":" _ time:TIME _ "]]"
{
return '<break strength="' + strength + '" time="' + toTime(time) + '"/>';
}

Time
SilenceTime
= "[[" _ ("silence"i / "sil"i) _ ":" _ time:TIME _ "]]"
{
return '<break time="' + toTime(time) + '"/>';
}

Strength
SilenceStrength
= "[[" _ ("strength"i / "str"i) _ ":" _ strength:STRENTH _ "]]"
{
return '<break strength="' + strength + '"/>';
Expand All @@ -264,10 +265,69 @@ Substitute
}

Audio
= "[[" _ ("audio"i / "aud"i) _ ":" uri:(!"]]" .)+ "]]"
= AudioSrc / AudioSoundLevel / AudioClipBeginEnd / AudioClipEndBegin
/ AudioClipBeginEndRepeatCount / AudioClipRepeatCountBeginEnd
/ AudioClipBeginEndSpeed / AudioClipSpeedBeginEnd
/ AudioClipRepeatCountDuration / AudioClipRepeatDurationCount

AudioSrc
= "[[" _ ("audio"i / "aud"i) _ ":" uri:(!("," / "]]") .)+ "]]"
{
return '<audio src="' + toText(uri) + '"/>'
}
AudioSoundLevel
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("level"i / "lev"i) _ ":" _ sound_level:SOUND_LEVEL _ "]]"
{
return '<audio src="' + toText(uri) + '" soundLevel="' + toVolume(sound_level) + '"/>'
}

AudioClipBeginEnd
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '"/>'
}

AudioClipEndBegin
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '"/>'
}

AudioClipBeginEndRepeatCount
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "," _ ("count"i / "cou"i) _ ":" _ repeat_count:COUNT _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '" repeatCount="' + toDetail(repeat_count) + '"/>'
}

AudioClipRepeatCountBeginEnd
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("count"i / "cou"i) _ ":" _ repeat_count:COUNT _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '" repeatCount="' + toDetail(repeat_count) + '"/>'
}

AudioClipRepeatCountDuration
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("count"i / "cou"i) _ ":" _ repeat_count:COUNT _ "," _ ("duration"i / "dur"i) _ ":" _ duration:TIME _ "]]"
{
return '<audio src="' + toText(uri) + '" repeatCount="' + toDetail(repeat_count) + '" repeatDur="' + toTime(duration) + '"/>'
}

AudioClipRepeatDurationCount
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("duration"i / "dur"i) _ ":" _ duration:TIME _ "," _ ("count"i / "cou"i) _ ":" _ repeat_count:COUNT _ "]]"
{
return '<audio src="' + toText(uri) + '" repeatCount="' + toDetail(repeat_count) + '" repeatDur="' + toTime(duration) + '"/>'
}

AudioClipBeginEndSpeed
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "," _ ("speed"i / "spe"i) _ ":" _ speed:NON_NEGATIVE_PERCENTAGE _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '" speed="' + toRate(speed) + '"/>'
}

AudioClipSpeedBeginEnd
= "[[" _ ("audio"i / "aud"i) _ ":" _ uri:(!"," .)+ _ "," _ ("speed"i / "spe"i) _ ":" _ speed:NON_NEGATIVE_PERCENTAGE _ "," _ ("begin"i / "beg"i) _ ":" _ clip_begin:TIME _ "," _ ("end"i) _ ":" _ clip_end:TIME _ "]]"
{
return '<audio src="' + toText(uri) + '" clipBegin="' + toTime(clip_begin) + '" clipEnd="' + toTime(clip_end) + '" speed="' + toRate(speed) + '"/>'
}

Lang
= "[[" _ ("lang"i / "lan"i) _ ":" lang:(!"|" .)+ "|" target:Target "]]"
Expand Down Expand Up @@ -427,7 +487,7 @@ LEVEL
= "strong" / "moderate" / "none" / "reduced"

TIME
= [0-9]+(.[0-9]+)?"h" / [0-9]+(.[0-9]+)?"min"/ [0-9]+(.[0-9]+)?"s" / [0-9]+(.[0-9]+)?"ms"
= [+|-]?[0-9]+(.[0-9]+)?"s" / [+|-]?[0-9]+(.[0-9]+)?"ms"

RATE
= "x-slow" / "slow" / "medium" / "fast" / "x-fast" / "default" / NON_NEGATIVE_PERCENTAGE
Expand All @@ -436,7 +496,7 @@ PITCH
= "x-low" / "low" / "medium" / "high" / "x-high" / "default" / PERCENTAGE / [\+\-0-9]+"Hz" / [\+\-0-9]+"st"

VOLUME
= "silent" / "x-soft" / "soft" / "medium" / "loud" / "x-loud" / "default" / [\+\-0-9]+(.[0-9])*"dB"
= "silent" / "x-soft" / "soft" / "medium" / "loud" / "x-loud" / "default" / SOUND_LEVEL

INTERPRET
= "cardinal" / "number" / "ordinal" / "characters" / "digits" / "fraction" / "expletive" / "bleep" / "interjection" / "unit" / "verbatim" / "spell-out" / "date" / "time" / "telephone" / "address"
Expand All @@ -453,6 +513,12 @@ PERCENTAGE
NON_NEGATIVE_PERCENTAGE
= [0-9]+"%"

COUNT
= [+]?[0-9]+(.[0-9]+)?

SOUND_LEVEL
= [\+\-0-9]+(.[0-9])*"dB"

VendorExtension
= AmazonWhispered / AmazonPhonation / AmazonTimbre / AmazonDynamicRangeCompression / AmazonMaxDuration
/ AmazonBreathSound / AmazonAutoBreathSound / AmazonSpeakingStyle / AmazonEmotionIntensity / AmazonIntensityEmotion
Expand Down Expand Up @@ -661,7 +727,7 @@ AMAZON_DURATION
= "x-short" / "short" / "medium" / "long" / "x-long" / "default"

AMAZON_STYLE
= "music" / "news" / "conversational"
= "music" / "news" / "conversational" / "long-form"

AMAZON_EMOTION
= "excited" / "disappointed"
Expand All @@ -670,7 +736,7 @@ AMAZON_INTENSITY
= "low" / "medium" / "high"

AMAZON_MAX_DURATION
= [0-9]+(.[0-9]+)?"s" / [0-9]+(.[0-9]+)?"ms"
= [+]?[0-9]+(.[0-9]+)?"s" / [+]?[0-9]+(.[0-9]+)?"ms"

GoogleMediaContainer
= GoolgeMediaSpeak / GoolgeMediaSpeakBegin / GoolgeMediaSpeakEnd / GoolgeMediaSpeakBeginEnd / GoolgeMediaSpeakEndBegin
Expand Down Expand Up @@ -762,7 +828,10 @@ GoolgeMediaAudioFadeOutMediaFadeIn
}

GoogleTime
= _ [+|-]? _ TIME / (!"." .)+."begin" _ [+|-]? _ TIME / (!"." .)+."end" _ [+|-]? _ TIME
= GoogleTimeDesignation / (!"." .)+."begin" GoogleTimeDesignation / (!"." .)+."end" GoogleTimeDesignation

GoogleTimeDesignation
= [+|-]?[0-9]+(.[0-9]+)?"h" / [+|-]?[0-9]+(.[0-9]+)?"min"/ TIME

IBMExpressiveness
= "[[" _ ("ibm-expr-type"i / "ibm-expr-typ"i / "ibmExprType"i / "iet"i) _ ":" _ expressiveness:IBM_EXPRTYPE _ "|" target:Target "]]"
Expand Down
3 changes: 3 additions & 0 deletions test/wiki2ssml-extension-test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion test/wiki2ssml-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@ describe("Test wiki2ssml", () => {
undertest = require("../src/wiki2ssml");
var happy = [
{ expression: "[[audio:https://example.mp3]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\"/>" + helper.TAIL }
{ expression: "[[aud:https://example.mp3]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\"/>" + helper.TAIL },
{ expression: "[[audio:https://example.mp3,level:+6dB]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" soundLevel=\"+6dB\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3,lev:+6dB]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" soundLevel=\"+6dB\"/>" + helper.TAIL },
{ expression: "[[audio:https://example.mp3,begin:0.5s,end:5s]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3,end:5s,begin:0.5s]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\"/>" + helper.TAIL },
{ expression: "[[audio:https://example.mp3,begin:0.5s,end:5s,count:3]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\" repeatCount=\"3\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3,count:3,begin:0.5s,end:5s]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\" repeatCount=\"3\"/>" + helper.TAIL },
{ expression: "[[audio:https://example.mp3,begin:0.5s,end:5s,speed:100%]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\" speed=\"100%\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3,speed:100%,begin:0.5s,end:5s]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" clipBegin=\"0.5s\" clipEnd=\"5s\" speed=\"100%\"/>" + helper.TAIL },
{ expression: "[[audio:https://example.mp3,duration:5s,count:3]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" repeatCount=\"3\" repeatDur=\"5s\"/>" + helper.TAIL },
{ expression: "[[aud:https://example.mp3,count:3,duration:5s]]", expected: helper.HEAD + "<audio src=\"https://example.mp3\" repeatCount=\"3\" repeatDur=\"5s\"/>" + helper.TAIL }
];

helper.runHappyTests(happy, undertest);
Expand Down

0 comments on commit db81b81

Please sign in to comment.