SpeakProgressEventArgs.CharacterPosition プロパティ

定義

プロンプトの最初から、たったいま読み上げられた単語の最初の文字の前の位置までの、文字とスペースの数を取得します。

public:
 property int CharacterPosition { int get(); };
public int CharacterPosition { get; }
member this.CharacterPosition : int
Public ReadOnly Property CharacterPosition As Integer

プロパティ値

プロンプトの最初から、たったいま読み上げられた単語の最初の文字の前の位置までの、文字とスペースの数を返します。

次の例では、 を PromptBuilder 作成し、 を使用して XmlReaderXML ファイルの SSML コンテンツを追加します。 この例では、音声を 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 タグ内の文字の数 (角かっこを含む) が含まれます。 、AppendTextWithAlias、、AppendTextWithHintAppendSsmlMarkup、または AppendTextWithPronunciation のいずれかのメソッドをAppendText使用する場合、内容は、開始要素と終了speak要素を含む SSML プロンプトに追加されます。 開始 speak 要素は、プロンプト内のすべての単語と文字の に 82 文字とスペース CharacterPosition のオフセットを追加します。 たとえば、次のスニペットでは、 CharacterPosition 最初の単語 "this" の は 82 です。

builder.AppendText("This is a test");  
Synthesizer.Speak(builder);  

上記の例では、 CharacterPosition "test" という単語の は 92 です。 次のスニペット CharacterPosition では、"test" という単語の は 23 文字高い (115) です。これは、その前の開始 <プロソディ pitch="high"> タグに 23 文字とスペースが含まれているためです (2 つのエスケープ文字 "\" はカウントされません)。

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" という数字を "4,003" と読み上げます。 3 つの話し SpeakProgress 言葉のそれぞれに対してイベントが発生します。 ただし、 CharacterPosition 3 つの各単語の プロパティは同じです。 これは、プロンプトのテキスト内の数値 "4003" の最初の文字の前の位置です。

適用対象