-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
TextFragment.xml
505 lines (424 loc) · 29.5 KB
/
TextFragment.xml
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<Type Name="TextFragment" FullName="System.Speech.Synthesis.TtsEngine.TextFragment">
<TypeSignature Language="C#" Value="public class TextFragment" />
<TypeSignature Language="ILAsm" Value=".class public sequential ansi beforefieldinit TextFragment extends System.Object" />
<TypeSignature Language="DocId" Value="T:System.Speech.Synthesis.TtsEngine.TextFragment" />
<TypeSignature Language="VB.NET" Value="Public Class TextFragment" />
<TypeSignature Language="F#" Value="type TextFragment = class" />
<TypeSignature Language="C++ CLI" Value="public ref class TextFragment" />
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Contains text and speech attribute information for consumption by a speech synthesizer engine.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The Speech platform infrastructure unpacks the XML based structure of the SSML input and constructs <xref:System.Speech.Synthesis.TtsEngine.TextFragment> objects.
Speech content is available through the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A>, <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A>, and <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> properties of a <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instance.
Speech attribute information, such as emphasis, pitch, and rate, are obtained from the <xref:System.Speech.Synthesis.TtsEngine.FragmentState> object returned by the <xref:System.Speech.Synthesis.TtsEngine.TextFragment><xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A> property.
## Examples
The example below is part of a custom speech synthesis implementation inheriting from <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml>, and using the use of <xref:System.Speech.Synthesis.TtsEngine.TextFragment>, <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo>, <xref:System.Speech.Synthesis.TtsEngine.FragmentState>, and <xref:System.Speech.Synthesis.TtsEngine.TtsEventId>.
The implementation of <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml.Speak%2A>
1. Receives an array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances and creates a new array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances to be passed to the `Speak` method on an underlying synthesis engine.
Particular care is used to respect the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A>, <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A> on the original <xref:System.Speech.Synthesis.TtsEngine.TextFragment> when creating the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> on the new <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances.
2. If the <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction> enumeration value by found from the <xref:System.Speech.Synthesis.TtsEngine.FragmentState.Action%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.FragmentState> returned by the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A> property of each <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instance is <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction.Speak>, the implementation
- Translates Americanism to Britishisms in the text to be spoken.
- If the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite.EventInterest%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite> interfaces provided to the implementation support the <xref:System.Speech.Synthesis.TtsEngine.TtsEventId.WordBoundary> event type, a <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo> instance is used to create an event to drive a synthesizer progress meter is created.
3. A speech rendering engine is then called with the modified <xref:System.Speech.Synthesis.TtsEngine.TextFragment> array.
```
private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };
internal struct UsVsUk
{
internal string UK;
internal string US;
}
override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)
{
TextFragment [] newFrags=new TextFragment[frags.Length];
for (int i=0;i<frags.Length;i++){
newFrags[i].State=frags[i].State;
//truncate
newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
frags[i].TextLength);
newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;
newFrags[i].TextOffset = 0;
if (newFrags[i].State.Action == TtsEngineAction.Speak) {
//Us to UK conversion
foreach (UsVsUk term in TransList) {
newFrags[i].TextToSpeak.Replace(term.US, term.UK);
}
//Generate progress meter events if supported
if ((site.EventInterest & WordBoundaryFlag) != 0) {
string[] subs = newFrags[i].TextToSpeak.Split(spaces);
foreach (string s in subs) {
int offset = newFrags[i].TextOffset;
SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,
(Int16)EventParameterType.Undefined,
s.Length, new IntPtr(offset));
offset += s.Length;
if (s.Trim().Length > 0) {
SpeechEventInfo[] events = new SpeechEventInfo[1];
events[0] = spEvent;
site.AddEvents(events, 1);
}
}
}
}
}
_baseSynthesize.Speak(newFrags, wfx, site);
}
```
]]></format>
</remarks>
</Docs>
<Members>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public TextFragment ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Speech.Synthesis.TtsEngine.TextFragment.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:
 TextFragment();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Parameters />
<Docs>
<summary>Constructs a new instance of <see langword="TextFragment" />.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Parameterless constructor for <xref:System.Speech.Synthesis.TtsEngine.TextFragment>.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="State">
<MemberSignature Language="C#" Value="public System.Speech.Synthesis.TtsEngine.FragmentState State { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance valuetype System.Speech.Synthesis.TtsEngine.FragmentState State" />
<MemberSignature Language="DocId" Value="P:System.Speech.Synthesis.TtsEngine.TextFragment.State" />
<MemberSignature Language="VB.NET" Value="Public Property State As FragmentState" />
<MemberSignature Language="F#" Value="member this.State : System.Speech.Synthesis.TtsEngine.FragmentState with get, set" Usage="System.Speech.Synthesis.TtsEngine.TextFragment.State" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::Speech::Synthesis::TtsEngine::FragmentState State { System::Speech::Synthesis::TtsEngine::FragmentState get(); void set(System::Speech::Synthesis::TtsEngine::FragmentState value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Speech.Synthesis.TtsEngine.FragmentState</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets speech attribute information for a <see langword="TextFragment" />.</summary>
<value>A <see cref="T:System.Speech.Synthesis.TtsEngine.FragmentState" /> instance is returned, or used to set speech attribute information for a <see cref="T:System.Speech.Synthesis.TtsEngine.TextFragment" />.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default value of this property is `null`.
Prosody information can be obtained from the instance of <xref:System.Speech.Synthesis.TtsEngine.Prosody> returned by the <xref:System.Speech.Synthesis.TtsEngine.FragmentState.Prosody%2A> property on the instance of <xref:System.Speech.Synthesis.TtsEngine.FragmentState> returned by <xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A>.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="TextLength">
<MemberSignature Language="C#" Value="public int TextLength { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 TextLength" />
<MemberSignature Language="DocId" Value="P:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength" />
<MemberSignature Language="VB.NET" Value="Public Property TextLength As Integer" />
<MemberSignature Language="F#" Value="member this.TextLength : int with get, set" Usage="System.Speech.Synthesis.TtsEngine.TextFragment.TextLength" />
<MemberSignature Language="C++ CLI" Value="public:
 property int TextLength { int get(); void set(int value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the length of the speech text in the fragment.</summary>
<value>An <see langword="int" /> is returned or can be used to set the length, in character, of the text string associated with this fragment to be spoken.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default value of this property is 0.
## Examples
The example below is part of a custom speech synthesis implementation inheriting from <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml>, and using the use of <xref:System.Speech.Synthesis.TtsEngine.TextFragment>, <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo>, <xref:System.Speech.Synthesis.TtsEngine.FragmentState>, and <xref:System.Speech.Synthesis.TtsEngine.TtsEventId>.
The implementation of <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml.Speak%2A>
1. Receives an array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances and creates a new array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances to be passed to the `Speak` method on an underlying synthesis engine.
Particular care is used to respect the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A>, <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A> on the original <xref:System.Speech.Synthesis.TtsEngine.TextFragment> when creating the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> on the new <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances.
2. If the <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction> enumeration value by found from the <xref:System.Speech.Synthesis.TtsEngine.FragmentState.Action%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.FragmentState> returned by the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A> property of each <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instance is <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction.Speak>, the implementation
- Translates Americanism to Britishisms in the text to be spoken.
- If the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite.EventInterest%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite> interfaces provided to the implementation support the <xref:System.Speech.Synthesis.TtsEngine.TtsEventId.WordBoundary> event type, a <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo> instance is used to create an event to drive a synthesizer progress meter is created.
3. A speech rendering engine is then called with the modified <xref:System.Speech.Synthesis.TtsEngine.TextFragment> array.
```
private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };
internal struct UsVsUk
{
internal string UK;
internal string US;
}
override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)
{
TextFragment [] newFrags=new TextFragment[frags.Length];
for (int i=0;i<frags.Length;i++){
newFrags[i].State=frags[i].State;
//truncate
newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
frags[i].TextLength);
newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;
newFrags[i].TextOffset = 0;
if (newFrags[i].State.Action == TtsEngineAction.Speak) {
//Us to UK conversion
foreach (UsVsUk term in TransList) {
newFrags[i].TextToSpeak.Replace(term.US, term.UK);
}
//Generate progress meter events if supported
if ((site.EventInterest & WordBoundaryFlag) != 0) {
string[] subs = newFrags[i].TextToSpeak.Split(spaces);
foreach (string s in subs) {
int offset = newFrags[i].TextOffset;
SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,
(Int16)EventParameterType.Undefined,
s.Length, new IntPtr(offset));
offset += s.Length;
if (s.Trim().Length > 0) {
SpeechEventInfo[] events = new SpeechEventInfo[1];
events[0] = spEvent;
site.AddEvents(events, 1);
}
}
}
}
}
_baseSynthesize.Speak(newFrags, wfx, site);
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="TextOffset">
<MemberSignature Language="C#" Value="public int TextOffset { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance int32 TextOffset" />
<MemberSignature Language="DocId" Value="P:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset" />
<MemberSignature Language="VB.NET" Value="Public Property TextOffset As Integer" />
<MemberSignature Language="F#" Value="member this.TextOffset : int with get, set" Usage="System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset" />
<MemberSignature Language="C++ CLI" Value="public:
 property int TextOffset { int get(); void set(int value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<set: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Int32</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the starting location of the text in the fragment.</summary>
<value>An <see langword="int" /> is returned or can be used to set the start location, in character, of the part of text string associated with this fragment to be spoken.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default value of this property is 0.
## Examples
The example below is part of a custom speech synthesis implementation inheriting from <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml>, and using the use of <xref:System.Speech.Synthesis.TtsEngine.TextFragment>, <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo>, <xref:System.Speech.Synthesis.TtsEngine.FragmentState>, and <xref:System.Speech.Synthesis.TtsEngine.TtsEventId>.
The implementation of <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml.Speak%2A>
1. Receives an array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances and creates a new array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances to be passed to the `Speak` method on an underlying synthesis engine.
Particular care is used to respect the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A>, <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A> on the original <xref:System.Speech.Synthesis.TtsEngine.TextFragment> when creating the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> on the new <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances.
2. If the <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction> enumeration value by found from the <xref:System.Speech.Synthesis.TtsEngine.FragmentState.Action%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.FragmentState> returned by the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A> property of each <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instance is <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction.Speak>, the implementation
- Translates Americanism to Britishisms in the text to be spoken.
- If the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite.EventInterest%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite> interfaces provided to the implementation support the <xref:System.Speech.Synthesis.TtsEngine.TtsEventId.WordBoundary> event type, a <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo> instance is used to create an event to drive a synthesizer progress meter is created.
3. A speech rendering engine is then called with the modified <xref:System.Speech.Synthesis.TtsEngine.TextFragment> array.
```
private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };
internal struct UsVsUk
{
internal string UK;
internal string US;
}
override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)
{
TextFragment [] newFrags=new TextFragment[frags.Length];
for (int i=0;i<frags.Length;i++){
newFrags[i].State=frags[i].State;
//truncate
newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
frags[i].TextLength);
newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;
newFrags[i].TextOffset = 0;
if (newFrags[i].State.Action == TtsEngineAction.Speak) {
//Us to UK conversion
foreach (UsVsUk term in TransList) {
newFrags[i].TextToSpeak.Replace(term.US, term.UK);
}
//Generate progress meter events if supported
if ((site.EventInterest & WordBoundaryFlag) != 0) {
string[] subs = newFrags[i].TextToSpeak.Split(spaces);
foreach (string s in subs) {
int offset = newFrags[i].TextOffset;
SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,
(Int16)EventParameterType.Undefined,
s.Length, new IntPtr(offset));
offset += s.Length;
if (s.Trim().Length > 0) {
SpeechEventInfo[] events = new SpeechEventInfo[1];
events[0] = spEvent;
site.AddEvents(events, 1);
}
}
}
}
}
_baseSynthesize.Speak(newFrags, wfx, site);
}
```
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="TextToSpeak">
<MemberSignature Language="C#" Value="public string TextToSpeak { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance string TextToSpeak" />
<MemberSignature Language="DocId" Value="P:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak" />
<MemberSignature Language="VB.NET" Value="Public Property TextToSpeak As String" />
<MemberSignature Language="F#" Value="member this.TextToSpeak : string with get, set" Usage="System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak" />
<MemberSignature Language="C++ CLI" Value="public:
 property System::String ^ TextToSpeak { System::String ^ get(); void set(System::String ^ value); };" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Speech</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]</AttributeName>
<AttributeName Language="F#">[<get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets or sets the speech text of the fragment.</summary>
<value>A <see langword="System.String" /> is returned or can be used to set the speech text to be used by a speech synthesis engine to generate audio output.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The default value of this property is `System.String.Empty`.
Applications are free to completely change the value of <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A>.
Resetting the value of <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> will not change the value of <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A> and <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A>.
## Examples
The example below is part of a custom speech synthesis implementation inheriting from <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml>, and using the use of <xref:System.Speech.Synthesis.TtsEngine.TextFragment>, <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo>, <xref:System.Speech.Synthesis.TtsEngine.FragmentState>, and <xref:System.Speech.Synthesis.TtsEngine.TtsEventId>.
The implementation of <xref:System.Speech.Synthesis.TtsEngine.TtsEngineSsml.Speak%2A>
1. Receives an array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances and creates a new array of <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances to be passed to the `Speak` method on an underlying synthesis engine.
Particular care is used to respect the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextOffset%2A>, <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextLength%2A> on the original <xref:System.Speech.Synthesis.TtsEngine.TextFragment> when creating the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.TextToSpeak%2A> on the new <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instances.
2. If the <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction> enumeration value by found from the <xref:System.Speech.Synthesis.TtsEngine.FragmentState.Action%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.FragmentState> returned by the <xref:System.Speech.Synthesis.TtsEngine.TextFragment.State%2A> property of each <xref:System.Speech.Synthesis.TtsEngine.TextFragment> instance is <xref:System.Speech.Synthesis.TtsEngine.TtsEngineAction.Speak>, the implementation
- Translates Americanism to Britishisms in the text to be spoken.
- If the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite.EventInterest%2A> property on the <xref:System.Speech.Synthesis.TtsEngine.ITtsEngineSite> interfaces provided to the implementation support the <xref:System.Speech.Synthesis.TtsEngine.TtsEventId.WordBoundary> event type, a <xref:System.Speech.Synthesis.TtsEngine.SpeechEventInfo> instance is used to create an event to drive a synthesizer progress meter is created.
3. A speech rendering engine is then called with the modified <xref:System.Speech.Synthesis.TtsEngine.TextFragment> array.
```
private const int WordBoundaryFlag = 1 << (int)TtsEventId.WordBoundary;
private readonly char[] spaces = new char[] { ' ', '\t', '\r', '\n' };
internal struct UsVsUk
{
internal string UK;
internal string US;
}
override public void Speak (TextFragment [] frags, IntPtr wfx, ITtsEngineSite site)
{
TextFragment [] newFrags=new TextFragment[frags.Length];
for (int i=0;i<frags.Length;i++){
newFrags[i].State=frags[i].State;
//truncate
newFrags[i].TextToSpeak = frags[i].TextToSpeak.Substring(frags[i].TextOffset,
frags[i].TextLength);
newFrags[i].TextLength = newFrags[i].TextToSpeak.Length;
newFrags[i].TextOffset = 0;
if (newFrags[i].State.Action == TtsEngineAction.Speak) {
//Us to UK conversion
foreach (UsVsUk term in TransList) {
newFrags[i].TextToSpeak.Replace(term.US, term.UK);
}
//Generate progress meter events if supported
if ((site.EventInterest & WordBoundaryFlag) != 0) {
string[] subs = newFrags[i].TextToSpeak.Split(spaces);
foreach (string s in subs) {
int offset = newFrags[i].TextOffset;
SpeechEventInfo spEvent = new SpeechEventInfo((Int16)TtsEventId.WordBoundary,
(Int16)EventParameterType.Undefined,
s.Length, new IntPtr(offset));
offset += s.Length;
if (s.Trim().Length > 0) {
SpeechEventInfo[] events = new SpeechEventInfo[1];
events[0] = spEvent;
site.AddEvents(events, 1);
}
}
}
}
}
_baseSynthesize.Speak(newFrags, wfx, site);
}
```
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>