语言

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、SpeakSpeakAsync或SpeakSsml方法时遇到书签时引发SpeakSsmlAsync该事件。 若要获取触发事件的书签的名称和位置,请访问 Bookmark 事件的处理程序中的属性和 AudioPosition 属性。

属性

名称 说明
AudioPosition

获取书签到达的时间偏移量。

Bookmark

获取已到达的书签的名称。

Cancelled

获取一个值,该值指示是否已取消异步操作。

(继承自 AsyncCompletedEventArgs)
Error

获取一个值,该值指示异步操作期间发生的错误。

(继承自 AsyncCompletedEventArgs)
Prompt

获取与事件关联的提示。

(继承自 PromptEventArgs)
UserState

获取异步任务的唯一标识符。

(继承自 AsyncCompletedEventArgs)

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type。

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
RaiseExceptionIfNecessary()

如果异步操作失败,则引发用户提供的异常。

(继承自 AsyncCompletedEventArgs)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅