共用方式為


SpeechSynthesizer.BookmarkReached 事件

定義

SpeechSynthesizer 在提示中遇到書籤時引發。

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) 

事件類型

範例

下列範例會建立包含兩個書簽的提示,並將輸出傳送至 WAV 檔案以供播放。 事件的處理常式 BookmarkReached 會在事件引發至主控台時,寫入書簽的名稱及其在音訊資料流程中的位置。

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 處理任何 SpeakSpeakAsyncSpeakSsmlSpeakSsmlAsync 方法時引發這個事件。 如需與事件相關聯的資料相關資訊,請參閱 BookmarkReachedEventArgs

您可以使用 方法新增書簽 AppendBookmark

適用於