語言

BookmarkReachedEventArgs 類別

定義

回傳事件 BookmarkReached 資料。

public ref class BookmarkReachedEventArgs : System::Speech::Synthesis::PromptEventArgs
public class BookmarkReachedEventArgs : System.Speech.Synthesis.PromptEventArgs
type BookmarkReachedEventArgs = class
    inherit PromptEventArgs
Public Class BookmarkReachedEventArgs
Inherits PromptEventArgs
繼承

範例

以下範例建立一個包含兩個書籤的提示,並將輸出傳送到 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);
    }
  }
}

備註

當BookmarkReachedEventArgs物件提出事件時SpeechSynthesizer,會產生一個BookmarkReached實例。 當 在處理任何 、 、 或方法時,遇到書籤時,事件SpeechSynthesizer會BookmarkReached被提升。SpeakSpeakAsyncSpeakSsmlSpeakSsmlAsync 要取得觸發事件的書籤名稱與位置,請在該事件的處理程序中存取 和 BookmarkAudioPosition 屬性。

屬性

名稱 Description
AudioPosition

會顯示書籤被觸及的時間偏移。

Bookmark

會得到被點擊的書籤名稱。

Cancelled

會得到一個值,表示非同步操作是否已被取消。

(繼承來源 AsyncCompletedEventArgs)
Error

會獲得一個值,表示非同步操作中發生了哪個錯誤。

(繼承來源 AsyncCompletedEventArgs)
Prompt

會收到與事件相關的提示。

(繼承來源 PromptEventArgs)
UserState

取得非同步任務的唯一識別碼。

(繼承來源 AsyncCompletedEventArgs)

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type。

(繼承來源 Object)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
RaiseExceptionIfNecessary()

若非同步操作失敗,則會觸發使用者提供的例外。

(繼承來源 AsyncCompletedEventArgs)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於

另請參閱