BookmarkReachedEventArgs Class

BookmarkReachedEventArgs Class

 

Returns data from the BookmarkReached event.

Namespace:   System.Speech.Synthesis
Assembly:  System.Speech (in System.Speech.dll)

System.Object
  System.EventArgs
    System.ComponentModel.AsyncCompletedEventArgs
      System.Speech.Synthesis.PromptEventArgs
        System.Speech.Synthesis.BookmarkReachedEventArgs

public class BookmarkReachedEventArgs : PromptEventArgs

NameDescription
System_CAPS_pubpropertyAudioPosition

Gets the time offset at which the bookmark was reached.

System_CAPS_pubpropertyBookmark

Gets the name of the bookmark that was reached.

System_CAPS_pubpropertyCancelled

Gets a value indicating whether an asynchronous operation has been canceled.(Inherited from AsyncCompletedEventArgs.)

System_CAPS_pubpropertyError

Gets a value indicating which error occurred during an asynchronous operation.(Inherited from AsyncCompletedEventArgs.)

System_CAPS_pubpropertyPrompt

Gets the prompt associated with the event.(Inherited from PromptEventArgs.)

System_CAPS_pubpropertyUserState

Gets the unique identifier for the asynchronous task.(Inherited from AsyncCompletedEventArgs.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodRaiseExceptionIfNecessary()

Raises a user-supplied exception if an asynchronous operation failed.(Inherited from AsyncCompletedEventArgs.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

An instance of BookmarkReachedEventArgs is created when the SpeechSynthesizer object raises the BookmarkReached event. The SpeechSynthesizer raises the BookmarkReached event when it encounters a bookmark while processing any of the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync methods. To obtain the name and location of the bookmark that triggered the event, access the Bookmark and the AudioPosition properties in the handler for the event.

The following example creates a prompt that includes two bookmarks and sends the output to a WAV file for playback. 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("Nightime 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);
    }
  }
}

.NET Framework
Available since 3.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft