Share via


SpeakCompletedEventArgs Class

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Returns data from the ISynthesizer.SpeakCompleted event.

Namespace: Microsoft.SpeechServer.Synthesis
Assembly: Microsoft.SpeechServer (in microsoft.speechserver.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public NotInheritable Class SpeakCompletedEventArgs
    Inherits AsyncCompletedEventArgs
[SerializableAttribute] 
public sealed class SpeakCompletedEventArgs : AsyncCompletedEventArgs

Remarks

The SpeakCompletedEventArgs class provides access to the reason that the synthesizer stopped and any exception that occurred.

Inheritance Hierarchy

System.Object
???? System.EventArgs
???????? Microsoft.SpeechServer.AsyncCompletedEventArgs
????????????Microsoft.SpeechServer.Synthesis.SpeakCompletedEventArgs

Example

The following code example consists of a custom activity that prompts while listening for user speech that might stop the prompt. If the BargeInType property indicates speech bargein, the example extracts the time offset at which the bargein occurred.

using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using Microsoft.SpeechServer.Dialog;
using Microsoft.SpeechServer.Recognition;
using Microsoft.SpeechServer.Synthesis;

namespace BargeIn
{
    /// <summary>
    /// Activity deriving from SpeechCompositeActivity.
    /// </summary>
    public class CoreBargeIn : SpeechCompositeActivity
    {
        /// <summary>
        /// Prompt played by the activity.
        /// </summary>
        public const string pt = "Please say a number between one and nine, while I drone on. ";

        /// <summary>
        /// Creates a new instance.
        /// </summary>
        public CoreBargeIn()
        {
        }

        /// <summary>
        /// Executes the activity.
        /// </summary>
        /// <param name="executionContext">The execution context</param>
        protected override void ExecuteCore(ActivityExecutionContext executionContext)
        {
            Uri gu = new System.Uri(Workflow.ApplicationHost.LocalPath, "Grammars/Library.grxml");
            Grammar g = new Microsoft.SpeechServer.Recognition.Grammar(gu, "Cardinal_1_to_9");
            Workflow.SpeechRecognizer.LoadGrammarAsync(g);

            Workflow.Synthesizer.BargeInType = BargeInTypes.Speech;

            // Specify the SpeakCompleted event-handler and start the prompt
            Workflow.Synthesizer.SpeakCompleted += Synthesizer_SpeakCompleted;
            Workflow.Synthesizer.SpeakAsync(pt, SynthesisTextFormat.PlainText);

            // Specify the RecognizeCompleted event-handler and start listening
            Workflow.SpeechRecognizer.RecognizeCompleted += SpeechRecognizer_RecognizeCompleted;
            Workflow.SpeechRecognizer.RecognizeAsync();
        }

        private void Synthesizer_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
        {
            // Remove event-handler from SpeakCompleted
            Workflow.Synthesizer.SpeakCompleted -= Synthesizer_SpeakCompleted;

            if (e.BargeInType == BargeInTypes.Speech)
            {
                System.TimeSpan bargie = e.BargeInOffset;
            }
        }

        private void SpeechRecognizer_RecognizeCompleted(object sender, RecognizeCompletedEventArgs e)
        {
            // Remove event-handler from RecognizeCompleted
            Workflow.SpeechRecognizer.RecognizeCompleted -= SpeechRecognizer_RecognizeCompleted;

            // End the custom activity
            OnSpeechActivityClosed(e.Error);
        }
    }
}

Thread Safety

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

Platforms

Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

Windows Server 2003

See Also

Reference

SpeakCompletedEventArgs Members
Microsoft.SpeechServer.Synthesis Namespace