-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderer.cs
305 lines (256 loc) · 8.74 KB
/
Renderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
using System;
using System.Windows.Documents;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace Kingstudio.Speach.Synthesis.Gymd2ssml
{
public class Renderer
{
#region Properties
public Options Options { get; set; }
#endregion
#region Constructors
public Renderer()
: this(null)
{
}
public Renderer(Options options)
{
Options = options ?? new Options();
}
#endregion
#region Methods
public virtual string Speak(string content)
{
return $"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<speak version=\"{Options.SsmlVersion}\" xmlns=\"{Options.SsmlNameSpace}\" xml:lang=\"{Options.SsmlLanguage}\">\n{content}</speak>\n";
}
public virtual string Audio(string src, string content)
{
var output = string.IsNullOrEmpty(content) ?$"<audio src=\"{src}\" />": $"<audio src=\"{src}\" >{content}</audio> ";
return output;
}
public virtual string Image(string src, string content)
{
var output = string.IsNullOrEmpty(content) ? $"<image src=\"{src}\" />" : $"<image src=\"{src}\" >{content}</image>";
output = Comment(output);
return output;
}
public virtual string Break(string time)
{
var output = $"<break time=\"{time}\" />";
return output;
}
public virtual string Emphasis(string level, string content)
{
level = string.IsNullOrEmpty(level) ? "moderate " : level;
var output = $"<emphasis level=\"{level}\">{content}</emphasis>";
return output;
}
public virtual string Paragraph(string content, string breaks)
{
var output = "";
if (this.Options.Text)
{
output += content;
}
else
{
output += $"<p>{content}</p>\n";
}
if (!string.IsNullOrEmpty(breaks))
{
output += $"{Break(breaks)}\n";
}
return output;
}
public virtual string Sentence(string content)
{
return $"<s>{content}</s>";
}
public virtual string Phoneme(string content, string ph)
{
var output = $"<phoneme ph=\"{ph}\">{content}</phoneme>";
return output;
}
public virtual string Pitch(string content, string pitch, bool newInnerline)
{
return Prosody(content, pitch, null, null, false);
}
public virtual string Rate(string content, string rate, bool newInnerline)
{
return Prosody(content, null, rate, null, false);
}
public virtual string Volume(string content, string volume, bool newInnerline)
{
return Prosody(content, null, null, volume, false);
}
public virtual string Prosody(string content, string pitch, string rate, string volume, bool newInnerline)
{
return Prosody(content, pitch, rate, volume, newInnerline, false);
}
public virtual string Prosody(string content, string pitch, string rate, string volume, bool newInnerline, bool newOutline)
{
var output = "";
if (!string.IsNullOrEmpty(content))
{
if (newOutline)
{
output += $"\n";
}
output += $"<prosody ";
if (!string.IsNullOrEmpty(pitch))
{
output += $"pitch=\"{pitch}\" ";
}
if (!string.IsNullOrEmpty(rate))
{
output += $"rate=\"{rate}\" ";
}
if (!string.IsNullOrEmpty(volume))
{
output += $"volume=\"{volume}\" ";
}
if (newInnerline)
{
output += $">\n{content}</prosody>";
}
else
{
output += $">{content}</prosody>";
}
if (newOutline)
{
output += $"\n";
}
}
return output;
}
public virtual string Date(string content, string interpretas, string format)
{
return Sayas(content, interpretas, format, null);
}
public virtual string Telephone(string content, string interpretas, string format)
{
return Sayas(content, interpretas, format, null);
}
public virtual string Time(string content, string interpretas, string format)
{
return Sayas(content, interpretas, format, null);
}
public virtual string Sayas(string content, string interpretas)
{
return Sayas(content, interpretas, null, null);
}
public virtual string Sayas(string content, string interpretas, string format, string detail)
{
var output = "";
if (!string.IsNullOrEmpty(content) && !string.IsNullOrEmpty(interpretas))
{
output = $"<say-as interpret-as=\"{interpretas}\" ";
if (!string.IsNullOrEmpty(format))
{
output += $"format=\"{format}\" ";
}
if (!string.IsNullOrEmpty(detail))
{
output += $"detail=\"{detail}\"";
}
output += $"> {content} </say-as>";
}
return output;
}
public virtual string Sub(string alias, string content)
{
var output = $"<sub alias=\"{alias}\">{content}</sub>";
return output;
}
public virtual string Voice(string name, string lang, string content)
{
return Voice(name, lang, content, true, true);
}
public virtual string Voice(string name, string lang, string content, bool isInerNewline)
{
return Voice(name, lang, content, isInerNewline, true);
}
public virtual string Voice(string name, string lang, string content, bool isInerNewline, bool isOutNewline)
{
var output = "";
if (isOutNewline)
{
output += $"\n";
}
output = $"<voice name=\"{name}\" ";
if (!string.IsNullOrEmpty(lang))
{
output += $"xml:lang=\"{lang}\" ";
}
if (isInerNewline)
{
output += $">\n{content}\n</voice>";
}
else
{
output += $">{content}</voice>";
}
if (isOutNewline)
{
output += $"\n";
}
return output;
}
public virtual string Repeat(string time, string breaks, string content)
{
int count = 0;
var output = "";
try
{
count = int.Parse(time);
}
catch
{
Console.WriteLine("无法完成转换!");
}
for(int i = 0; i < count; i++)
{
output += $"<s>{content}</s>";
if (!string.IsNullOrEmpty(breaks))
{
output += Break(breaks);
}
}
return output;
}
public virtual string Question(string content)
{
content = "**The following areas are the test questions**\n" + content;
var output = Comment(content, true, true);
return output;
}
public virtual string Answer(string content)
{
content = "**The following areas are the test answer**\n" + content;
var output = Comment(content, true, true);
return output;
}
public virtual string Comment(string content)
{
var output = $"<!-- {content} -->\n";
return output;
}
public virtual string Comment(string content, bool multiline)
{
var output = $"\n<!--\n{content}\n-->\n";
return output;
}
public virtual string Comment(string content, bool multiline, bool cdata)
{
var output = $"\n<![CDATA[\n{content}\n]]>\n";
return output;
}
public virtual string Text(string content)
{
return content;
}
#endregion
}
}