Share via


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 , , SpeakAsyncSpeakSsml또는 SpeakSsmlAsync 메서드를 Speak처리하는 동안 이 이벤트를 발생합니다. 이벤트와 연결된 데이터에 대한 자세한 내용은 를 참조하세요 BookmarkReachedEventArgs.

메서드를 사용하여 AppendBookmark 책갈피를 추가할 수 있습니다.

적용 대상