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 取得的資訊。 請注意, 、 EndParagraphStartSentenceEndSentence 方法如何 StartParagraph 將其p > 、/p、s 和 /s 標籤新增 <至產生的 SSML,來影響 。<><>CharacterCount<> 此外,輸出中有兩個專案「30%」,每個單字都會說出這個數位字串, (30%) 。 每個 CharacterCount 專案的 和 CharacterPosition 都相同,並代表字元 「30%。 不過,要 AudioPosition 反映 「30」 和 「percent」 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);  
    }  
  }  
}  

備註

當 物件引發 SpeakProgress 事件時 SpeechSynthesizer ,就會建立 的 SpeakProgressEventArgs 實例。 會 SpeechSynthesizer 針對使用任何 SpeakSpeakAsyncSpeakSsmlSpeakSsmlAsync 方法,在提示中說話的每個新單字引發這個事件。

傳回的資料是以程式碼產生的語音合成標記語言 (SSML) 為基礎。 針對 包含空格和程式碼所產生之 SSML 標籤的字元和內容所傳回 CharacterCount 的值。

屬性

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)

適用於