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


SpeechSynthesizer 在提示中遇到書籤時引發。Raised when the SpeechSynthesizer encounters a bookmark in a prompt.

 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) 


下列範例會建立包含兩個書簽的提示, 並將輸出傳送至 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.   
        // 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"));  
          "The weather forecast for today is partly cloudy with some sun breaks.");  
        builder.AppendBookmark("Daytime forecast");  
          "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.  
      Console.WriteLine("Press any key to exit...");  
    // 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);  


處理任何Speak、 、SpeakAsync SpeechSynthesizerSpeakSsml方法時,會SpeakSsmlAsync引發這個事件。The 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.