Skip to content

Commit

Permalink
Merge pull request #79 from nixonsam/SSML
Browse files Browse the repository at this point in the history
added SSML tags to Speak Element
  • Loading branch information
Sachin Kulshrestha authored Oct 16, 2018
2 parents d7394ae + 5c63afe commit 3d8bb68
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/Plivo/XML/Break.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class Break : PlivoElement
{
public Break(dict parameters): base(parameters)
{
Nestables = new list() { "" };
ValidAttributes = new list()
{
"strength",
"time",
};
addAttributes();
}
}
}
29 changes: 29 additions & 0 deletions src/Plivo/XML/Emphasis.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class Emphasis : PlivoElement
{
public Emphasis(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list()
{
"Break",
"Emphasis",
"Lang",
"Phoneme",
"Prosody",
"SayAs",
"Sub",
"W"
};
ValidAttributes = new list()
{
"level"
};
addAttributes();
}
}
}
32 changes: 32 additions & 0 deletions src/Plivo/XML/Lang.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;
using System.Xml.Linq;

namespace Plivo.XML
{
public class Lang : PlivoElement
{
public Lang(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list()
{
"Break",
"Emphasis",
"Lang",
"P",
"Phoneme",
"Prosody",
"S",
"SayAs",
"Sub",
"W"
};
ValidAttributes = new list()
{
"xmllang"
};
addAttributes();
}
}
}
25 changes: 25 additions & 0 deletions src/Plivo/XML/P.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class P : PlivoElement
{
public P(string body)
: base(body)
{
Nestables = new list() {
"Break",
"Emphasis",
"Lang",
"Phoneme",
"Prosody",
"SayAs",
"Sub",
"S",
"W"
};
ValidAttributes = new list() {""};
}
}
}
20 changes: 20 additions & 0 deletions src/Plivo/XML/Phoneme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class Phoneme : PlivoElement
{
public Phoneme(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list() {""};
ValidAttributes = new list()
{
"alphabet",
"ph"
};
addAttributes();
}
}
}
80 changes: 80 additions & 0 deletions src/Plivo/XML/PlivoElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using Plivo.Exception;
using Plivo.Utilities;
using dict = System.Collections.Generic.Dictionary<string, string>;
Expand Down Expand Up @@ -99,6 +100,85 @@ public PlivoElement AddSpeak(string body, dict parameters)
return Add(new Speak(body, parameters));
}

public PlivoElement AddBreak(dict parameters)
{
PlivoElement elem = new Break(parameters);
elem.Element.Name = "break";
return Add(elem);

}

public PlivoElement AddEmphasis(string body, dict parameters)
{
PlivoElement elem = new Emphasis(body, parameters);
elem.Element.Name = "emphasis";
return Add(elem);
}

public PlivoElement AddLang(string body, dict parameters)
{
PlivoElement elem = new Lang(body, parameters);
elem.Element.Name = "lang";

var oldAttribute = elem.Element.Attribute("xmllang");
var attributeList = elem.Element.Attributes().ToList();
XAttribute newAttribute = new XAttribute(XNamespace.Xml + "lang", oldAttribute.Value);
attributeList.Add(newAttribute);
attributeList.Remove(oldAttribute);
elem.Element.ReplaceAttributes(attributeList);

return Add(elem);
}

public PlivoElement AddP(string body)
{
PlivoElement elem = new P(body);
elem.Element.Name = "p";
return Add(elem);
}

public PlivoElement AddPhoneme(string body, dict parameters)
{
PlivoElement elem = new Phoneme(body, parameters);
elem.Element.Name = "phoneme";
return Add(elem);
}

public PlivoElement AddProsody(string body, dict parameters)
{
PlivoElement elem = new Prosody(body, parameters);
elem.Element.Name = "prosody";
return Add(elem);
}

public PlivoElement AddS(string body)
{
PlivoElement elem = new S(body);
elem.Element.Name = "s";
return Add(elem);
}

public PlivoElement AddSayAs(string body, dict parameters)
{
PlivoElement elem = new SayAs(body, parameters);
elem.Element.Name = "say-as";
return Add(elem);
}

public PlivoElement AddSub(string body, dict parameters)
{
PlivoElement elem = new Sub(body, parameters);
elem.Element.Name = "sub";
return Add(elem);
}

public PlivoElement AddW(string body, dict parameters)
{
PlivoElement elem = new W(body, parameters);
elem.Element.Name = "w";
return Add(elem);
}

public PlivoElement AddPlay(string body, dict parameters)
{
return Add(new Play(body, parameters));
Expand Down
33 changes: 33 additions & 0 deletions src/Plivo/XML/Prosody.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class Prosody : PlivoElement
{
public Prosody(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list()
{
"Break",
"Emphasis",
"Lang",
"P",
"Phoneme",
"Prosody",
"S",
"SayAs",
"Sub",
"W"
};
ValidAttributes = new list()
{
"volume",
"rate",
"pitch"
};
addAttributes();
}
}
}
24 changes: 24 additions & 0 deletions src/Plivo/XML/S.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class S : PlivoElement
{
public S(string body)
: base(body)
{
Nestables = new list() {
"Break",
"Emphasis",
"Lang",
"Phoneme",
"Prosody",
"SayAs",
"Sub",
"W"
};
ValidAttributes = new list() {""};
}
}
}
20 changes: 20 additions & 0 deletions src/Plivo/XML/SayAs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class SayAs : PlivoElement
{
public SayAs(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list() {""};
ValidAttributes = new list()
{
"interpret-as",
"format"
};
addAttributes();
}
}
}
16 changes: 14 additions & 2 deletions src/Plivo/XML/Speak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ public class Speak : PlivoElement
public Speak(string body, dict attributes)
: base(body, attributes)
{
Nestables = new list() {""};
Nestables = new list()
{
"Break",
"Emphasis",
"Lang",
"P",
"Phoneme",
"Prosody",
"S",
"SayAs",
"Sub",
"W"
};
ValidAttributes = new list()
{
"loop",
Expand All @@ -18,4 +30,4 @@ public Speak(string body, dict attributes)
addAttributes();
}
}
}
}
19 changes: 19 additions & 0 deletions src/Plivo/XML/Sub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class Sub : PlivoElement
{
public Sub(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list() {""};
ValidAttributes = new list()
{
"alias",
};
addAttributes();
}
}
}
26 changes: 26 additions & 0 deletions src/Plivo/XML/W.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using dict = System.Collections.Generic.Dictionary<string, string>;
using list = System.Collections.Generic.List<string>;

namespace Plivo.XML
{
public class W : PlivoElement
{
public W(string body, dict parameters)
: base(body, parameters)
{
Nestables = new list() {
"Break",
"Emphasis",
"Phoneme",
"Prosody",
"SayAs",
"Sub"
};
ValidAttributes = new list()
{
"role",
};
addAttributes();
}
}
}

0 comments on commit 3d8bb68

Please sign in to comment.