SpeakProgressEventArgs 类

定义

从事件返回数据 SpeakProgress

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

示例

下面的示例演示了从 SpeakProgressEventArgs中获取的信息。 请注意,StartParagraph通过将 EndSentence生成的 SSML,这些标记CharacterCount和方法如何影响它们。<><><><> 此外,“30%”的输出中有两个条目,每个单词都有一个条目来朗写这个数字字符串(30%) 。 每个 CharacterCount 条目的字符 CharacterPosition 相同,并表示字符“30%。 然而,反映 AudioPosition “三十”和“百分比” SpeechSynthesizer一词的讲话的变化。

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 containing a paragraph and two sentences.
        PromptBuilder builder = new PromptBuilder(
          new System.Globalization.CultureInfo("en-US"));
        builder.StartParagraph();
        builder.StartSentence();
        builder.AppendText(
          "The weather forecast for today is partly cloudy with some sun breaks.");
        builder.EndSentence();
        builder.StartSentence();
        builder.AppendText(
          "Tonight's weather will be cloudy with a 30% chance of showers.");
        builder.EndSentence();
        builder.EndParagraph();

        // Add a handler for the SpeakProgress event.
        synth.SpeakProgress +=
          new EventHandler<SpeakProgressEventArgs>(synth_SpeakProgress);

        // 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 each word and its character position to the console.
    static void synth_SpeakProgress(object sender, SpeakProgressEventArgs e)
    {
      Console.WriteLine("CharPos: {0}   CharCount: {1}   AudioPos: {2}    \"{3}\"",
        e.CharacterPosition, e.CharacterCount, e.AudioPosition, e.Text);
    }
  }
}

注解

当对象引发SpeakProgressEventArgs事件时SpeechSynthesizer,将创建一个实例SpeakProgress。 对于它使用任何、SpeechSynthesizerSpeakSpeakAsyncSpeakSsml方法在提示中说话的每个新单词,都会SpeakSsmlAsync引发此事件。

返回的数据基于代码生成的语音合成标记语言 (SSML)。 返回的值包括 CharacterCount 空格和代码生成的 SSML 标记的字符和内容。

属性

名称 说明
AudioPosition

获取事件的音频位置。

Cancelled

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

(继承自 AsyncCompletedEventArgs)
CharacterCount

获取在引发事件之前说出的单词中的字符数。

CharacterPosition

获取从提示的开头到刚说出单词的第一个字母之前的位置的字符数和空格数。

Error

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

(继承自 AsyncCompletedEventArgs)
Prompt

获取与事件关联的提示。

(继承自 PromptEventArgs)
Text

引发事件时刚刚说出的文本。

UserState

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

(继承自 AsyncCompletedEventArgs)

方法

名称 说明
Equals(Object)

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

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
RaiseExceptionIfNecessary()

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

(继承自 AsyncCompletedEventArgs)
ToString()

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

(继承自 Object)

适用于