SpeakProgressEventArgs 類別

定義

SpeakProgress 事件傳回資料。Returns data from the SpeakProgress event.

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取得的資訊。The following example demonstrates the information that is available from SpeakProgressEventArgs. StartParagraph注意EndParagraph CharacterCount ,、 、EndSentence和方法如何藉由新增p>、/p>、s>和來影響。< < < StartSentence/s > 標記加入至產生的 SSML。 <Note how the StartParagraph, EndParagraph, StartSentence, and EndSentence methods affect the CharacterCount by their addition of <p>, </p>, <s>, and </s> tags to the generated SSML. 此外, "30%" 的輸出中有兩個專案, 每個單字各有一個用來說出這個數位字串 (三十%)。Also, there are two entries in the output for "30%", one for each word to speak this number string (thirty percent). 每個CharacterPosition專案的和都相同,並代表"30%"字元。CharacterCountThe CharacterCount and CharacterPosition are the same for each entry and represent the characters "30%. 不過, 所AudioPosition做的變更會反映「三十」和「百分比SpeechSynthesizer」這一字的說話。However, the AudioPosition changes to reflect the speaking of the words "thirty" and "percent" by the 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 事件SpeakProgress時, 會建立的實例。 SpeechSynthesizerAn instance of SpeakProgressEventArgs is created when the SpeechSynthesizer object raises the SpeakProgress event. Speak SpeakAsync SpeakSsml會針對它在使用任何、、或SpeakSsmlAsync方法的提示中所說的每個新單字引發這個事件。SpeechSynthesizerThe SpeechSynthesizer raises this event for each new word that it speaks in a prompt using any of the Speak, SpeakAsync, SpeakSsml, or SpeakSsmlAsync methods.

傳回的資料是以程式碼所產生的語音合成標記語言 (SSML) 為基礎。The returned data is based on the Speech Synthesis Markup Language (SSML) that the code generates. 傳回的CharacterCount值包含空格, 以及程式碼所產生之 SSML 標記的字元和內容。The values returned for CharacterCount include spaces and the characters and contents of the SSML tags generated by the code.

屬性

AudioPosition

取得事件的音訊位置。Gets the audio position of the event.

Cancelled

取得值,指出非同步作業是否已取消。Gets a value indicating whether an asynchronous operation has been canceled.

(繼承來源 AsyncCompletedEventArgs)
CharacterCount

取得在引發事件之前剛說出的文字中的字元數。Gets the number of characters in the word that was spoken just before the event was raised.

CharacterPosition

取得從提示開頭到剛說出的文字的第一個字母之前位置的字元和空格數。Gets the number of characters and spaces from the beginning of the prompt to the position before the first letter of the word that was just spoken.

Error

取得值,指出非同步作業期間是否發生錯誤。Gets a value indicating which error occurred during an asynchronous operation.

(繼承來源 AsyncCompletedEventArgs)
Prompt

取得與事件相關聯的提示。Gets the prompt associated with the event.

(繼承來源 PromptEventArgs)
Text

正好在引發事件時所讀出的文字。The text that was just spoken when the event was raised.

UserState

取得非同步工作的唯一識別項。Gets the unique identifier for the asynchronous task.

(繼承來源 AsyncCompletedEventArgs)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
RaiseExceptionIfNecessary()

如果非同步作業失敗,引發使用者提供的例外狀況。Raises a user-supplied exception if an asynchronous operation failed.

(繼承來源 AsyncCompletedEventArgs)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於