SpeakProgressEventArgs.CharacterPosition 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
프롬프트의 처음부터 방금 읽은 단어의 첫 번째 문자 바로 앞의 위치까지 문자 및 공백의 수를 가져옵니다.
public:
property int CharacterPosition { int get(); };
public int CharacterPosition { get; }
member this.CharacterPosition : int
Public ReadOnly Property CharacterPosition As Integer
속성 값
프롬프트의 처음부터 방금 읽은 단어의 첫 번째 문자 바로 앞의 위치까지 문자와 공백의 수를 반환합니다.
예제
다음 예제에서는 를 만들고 를 PromptBuilder 사용하여 XML 파일의 SSML 내용을 추가합니다. XmlReader 이 예제는 재생을 위해 WAV 파일에 음성을 출력합니다. SSML을 포함하는 XML 파일의 내용은 코드 예제 아래에 나타납니다.
using System;
using System.Xml;
using System.IO;
using System.Speech.Synthesis;
namespace SampleSynthesis
{
class Program
{
static void Main(string[] args)
{
// Initialize a new instance of the SpeechSynthesizer.
using (SpeechSynthesizer synth = new SpeechSynthesizer())
{
// Configure the audio output.
synth.SetOutputToDefaultAudioDevice();
// Create a path to the file that contains SSML.
string weatherFile = Path.GetFullPath("c:\\test\\Weather.ssml");
// Create an XML Reader from the file, create a PromptBuilder and
// append the XmlReader.
PromptBuilder builder = new PromptBuilder();
if (File.Exists(weatherFile))
{
XmlReader reader = XmlReader.Create(weatherFile);
builder.AppendSsml(reader);
reader.Close();
}
// Add a handler for the SpeakProgress event.
synth.SpeakProgress +=
new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);
// Speak the prompt and play back the output file.
synth.Speak(builder);
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
// Write each word and its character position to the console.
static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
{
Console.WriteLine("Speak progress: {0} {1}",
e.CharacterPosition, e.Text);
}
}
}
<!-- The following are the contents of the file Weather.ssml.
Note that because of the <p> tag and the space that follows it,
that the character position of the first word "The" will be 86. -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<speak version="1.0"
xmlns="http://www.w3.org/2001/10/synthesis"
xml:lang="en-US">
<p> The weather forecast for today is partly cloudy with
some sun breaks. </p>
<break strength="medium" />
<p> Tonight's weather will be cloudy with a 30% chance of
showers. </p>
</speak>
설명
CharacterPosition에는 바운딩 대괄호를 포함하여 XML 태그의 문자 수가 포함됩니다. , , , 또는 메서드를 사용하는 경우 AppendText AppendTextWithAlias 열기 및 AppendTextWithHint AppendSsmlMarkup AppendTextWithPronunciation 닫는 요소가 포함된 SSML 프롬프트에 내용이 speak 추가됩니다. 여는 speak 요소는 프롬프트에 있는 모든 단어와 문자의 에 82자 CharacterPosition 및 공백의 오프셋을 추가합니다. 예를 들어 다음 조각에서 CharacterPosition 첫 번째 단어 "this"의 는 82입니다.
builder.AppendText("This is a test");
Synthesizer.Speak(builder);
위의 예제에서 CharacterPosition "test"라는 단어의 는 92입니다. 다음 코드 조각에서 CharacterPosition "test"라는 단어의 는 23자 이상(115자)입니다. 앞에 오는 <prosody pitch="high"> 여는 태그에는 23자 및 공백이 포함되어 있기 때문입니다(두 개의 이스케이프 문자 " \ "은 계산되지 않음).
builder.AppendSsmlMarkup("This is a <prosody pitch=\"high\"> test </prosody>.");
Synthesizer.Speak(builder);
메서드를 사용하여 AppendSsml 파일을 지정하여 프롬프트에 콘텐츠를 추가하는 경우 파일의 xml 여는 선언과 speak 요소가 사용되거나 계산되지 않습니다. 여는 태그 뒤의 파일에서 첫 번째 문자는 speak 프롬프트의 첫 번째 콘텐츠인 경우 위치 82에 있습니다.
반면, 메서드의 문자열 매개 Speak 변수는 말하기 전에 SSML 프롬프트에 추가되지 않습니다. 따라서 다음 CharacterPosition 조각에서 첫 번째 단어 "this"의 는 0입니다.
Synthesizer.Speak("This is a test.");
는 SpeechSynthesizer 숫자를 말하는 방법에 해당하는 단어로 숫자를 정규화합니다. 예를 들어 신시사이저는 숫자 "4003"을 "4003"으로 말합니다. 세 개의 SpeakProgress 음성 단어 각각에 대해 이벤트를 발생합니다. 그러나 세 CharacterPosition 단어 각각에 대한 속성은 동일합니다. 프롬프트 텍스트에서 숫자 "4003"의 첫 번째 문자 앞의 위치입니다.