Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
kingstudio committed Oct 20, 2022
0 parents commit 1661330
Show file tree
Hide file tree
Showing 11 changed files with 1,482 additions and 0 deletions.
50 changes: 50 additions & 0 deletions BlockRules.cs
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
{
}
}
45 changes: 45 additions & 0 deletions Gymd2ssml.cs
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;
}
}
}
Loading

0 comments on commit 1661330

Please sign in to comment.