-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1661330
Showing
11 changed files
with
1,482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace Kingstudio.Speach.Synthesis.Gymd2ssml | ||
{ | ||
/// <summary> | ||
/// Block-Level Grammar | ||
/// </summary> | ||
public class BlockRules | ||
{ | ||
#region Fields | ||
|
||
private static readonly Regex newline = new Regex(@"^\n+"); | ||
private static readonly Regex paragraph = new Regex(@"^((?:[^\n]+\n?(?!( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$)))+)\n*"); | ||
private static readonly Regex question = new Regex(@"^#\[['""]?question['""]?\]((?:[^\n]+\n?(?!( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$)))+)\n*"); | ||
private static readonly Regex answer = new Regex(@"^#\[['""]?answer['""]?\]((?:[^\n]+\n?(?!( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$)))+)\n*"); | ||
private static readonly Regex voice = new Regex(@"^#\[['""]?voice['""]?:['""]?([a-zA-Z0-9-_ ]+)['""]?,?['""]?lang['""]?:?['""]?([a-zA-Z0-9-_]+)['""]?\]((?:[^\n]+\n?(?!( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$)))+)\n*"); | ||
private static readonly Regex prosody = new Regex(@"^#\[?['""]?pitch['""]?:?['""]?([xlowmediuhghsfat-]+)['""]?,?['""]?rate['""]?:?['""]?([xlowmediuhghsfat-]+)['""]?,?['""]?volume['""]?:?['""]?([xlowmediuhghsfat-]+)['""]?\]((?:[^\n]+\n?(?!( *[-*_]){3,} *(?:\n+|$)| *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)|([^\n]+)\n *(=|-){2,} *(?:\n+|$)|( *>[^\n]+(\n(?! *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$))[^\n]+)*\n*)+|<(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\b)\w+(?!:\/|[^\w\s@]*@)\b| *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +[""(]([^\n]+)["")])? *(?:\n+|$)))+)\n*"); | ||
private static readonly Regex singlelineComment = new Regex(@"^\/\/(.*)"); | ||
private static readonly Regex multilineComment = new Regex(@"^\/\*([\w\W]*?)\*\/"); | ||
private static readonly Regex text = new Regex(@"^[^\n]+"); | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
public virtual Regex Newline { get { return newline; } } | ||
public virtual Regex Paragraph { get { return paragraph; } } | ||
public virtual Regex Question { get { return question; } } | ||
public virtual Regex Answer { get { return answer; } } | ||
public virtual Regex Prosody { get { return prosody; } } | ||
public virtual Regex Voice { get { return voice; } } | ||
public virtual Regex SinglelineComment { get { return singlelineComment; } } | ||
public virtual Regex MultilineComment { get { return multilineComment; } } | ||
public virtual Regex Text { get { return text; } } | ||
|
||
#endregion | ||
} | ||
|
||
/// <summary> | ||
/// Normal Block Grammar | ||
/// </summary> | ||
public class NormalBlockRules : BlockRules | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Kingstudio.Speach.Synthesis.Gymd2ssml | ||
{ | ||
public class Gymd2ssml | ||
{ | ||
public Options Options { get; set; } | ||
|
||
|
||
public Gymd2ssml() | ||
: this(null) | ||
{ | ||
} | ||
|
||
public Gymd2ssml(Options options) | ||
{ | ||
Options = options ?? new Options(); | ||
} | ||
|
||
|
||
public static string Parse(string src, Options options) | ||
{ | ||
var ssmd2ssml = new Gymd2ssml(options); | ||
return ssmd2ssml.Parse(src); | ||
} | ||
|
||
public virtual string Parse(string src) | ||
{ | ||
if (String.IsNullOrEmpty(src)) | ||
{ | ||
return src; | ||
} | ||
|
||
TokensResult tokensResult = Lexer.Lex(src, Options); | ||
var tokens = tokensResult; | ||
var result = Parser.Parse(tokens, Options); | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.