SpeechSynthesizer.BookmarkReached SpeechSynthesizer.BookmarkReached SpeechSynthesizer.BookmarkReached SpeechSynthesizer.BookmarkReached Event

定義

SpeechSynthesizer がプロンプトのブックマークを検出したときに発生します。Raised when the SpeechSynthesizer encounters a bookmark in a prompt.

public:
 event EventHandler<System::Speech::Synthesis::BookmarkReachedEventArgs ^> ^ BookmarkReached;
public event EventHandler<System.Speech.Synthesis.BookmarkReachedEventArgs> BookmarkReached;
member this.BookmarkReached : EventHandler<System.Speech.Synthesis.BookmarkReachedEventArgs> 
Public Custom Event BookmarkReached As EventHandler(Of BookmarkReachedEventArgs) 

次の例では、2つのブックマークを含むプロンプトを作成し、再生用の WAV ファイルに出力を送信します。The following example creates a prompt that includes two bookmarks and sends the output to a WAV file for playback. イベントのハンドラー BookmarkReachedは、イベントがコンソールに発生したときの、オーディオストリーム内のブックマークの名前とその位置を書き込みます。The handler for the BookmarkReached event writes the name of the bookmark and its position in the audio stream when the event was raised to the console.

using System;  
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.SetOutputToWaveFile(@"C:\test\weather.wav");  
  
        // Create a SoundPlayer instance to play the output audio file.  
        System.Media.SoundPlayer m_SoundPlayer =  
          new System.Media.SoundPlayer(@"C:\test\weather.wav");  
  
        // Build a prompt and append bookmarks.  
        PromptBuilder builder = new PromptBuilder(  
          new System.Globalization.CultureInfo("en-US"));  
        builder.AppendText(  
          "The weather forecast for today is partly cloudy with some sun breaks.");  
        builder.AppendBookmark("Daytime forecast");  
        builder.AppendText(  
          "Tonight's weather will be cloudy with a 30% chance of showers.");  
        builder.AppendBookmark("Nighttime forecast");  
  
        // Add a handler for the BookmarkReached event.  
        synth.BookmarkReached +=  
          new EventHandler<BookmarkReachedEventArgs>(synth_BookmarkReached);  
  
        // Speak the prompt and play back the output file.  
        synth.Speak(builder);  
        m_SoundPlayer.Play();  
      }  
  
      Console.WriteLine();  
      Console.WriteLine("Press any key to exit...");  
      Console.ReadKey();  
    }  
  
    // Write the name and position of the bookmark to the console.  
    static void synth_BookmarkReached(object sender, BookmarkReachedEventArgs e)  
    {  
      Console.WriteLine("Bookmark ({0}) reached at: {1} ",  
        e.Bookmark, e.AudioPosition);  
    }  
  }  
}  
  

注釈

SpeechSynthesizer 、、、 SpeakSsmlSpeakのいずれSpeakAsyncかのメソッドを処理するときに、このイベントを発生させます。SpeakSsmlAsyncThe SpeechSynthesizer raises this event while processing any of the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync methods. イベントに関連付けられているデータのBookmarkReachedEventArgs詳細については、「」を参照してください。For information about data associated with the event, see BookmarkReachedEventArgs.

ブックマークは、 AppendBookmarkメソッドを使用して追加できます。You can add bookmarks using the AppendBookmark method.

適用対象