Share via


ISynthesizer.SpeakAsync Method (PromptBuilder, TimeSpan)

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.

Speaks the specified PromptBuilder object asynchronously, starting from a TimeSpan offset.

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

Syntax

'Declaration
Sub SpeakAsync ( _
    prompt As PromptBuilder, _
    offset As TimeSpan _
)
void SpeakAsync (
    PromptBuilder prompt,
    TimeSpan offset
)

Parameters

  • prompt
    A PromptBuilder object that defines the prompt to be spoken.
  • offset
    The time into the prompt (in milliseconds) at which to start synthesis.

Exceptions

Exception type Condition
ArgumentNullException

prompt is null.

InvalidOperationException

Playback is already in progress or DTMF digits are currently being sent.

Remarks

If an error occurs during asynchronous operation of the SpeakAsync method, information about the error is returned in the SpeakCompletedEventArgs object. To access this information, developers must write a procedure that extracts the information from the eventargs object and assign this procedure to the method's SpeakCompleted event handler. The SpeakCompletedEventArgs class derives from AsyncCompletedEventArgs and inherits an Error property that contains any error information.

Example

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 YourSpeechApplicationNamespace
{
    /// <summary>
    /// Activity deriving from SpeechCompositeActivity.
    /// </summary>
    public class ISynthesizer_SpeakAsync3 : SpeechCompositeActivity
    {
        /// <summary>
        /// Prompt played by the activity.
        /// </summary>
        PromptBuilder pb;
        public const string pt = "This is an example of a prompt text that lasts several seconds. ";

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

        /// <summary>
        /// Executes the activity.
        /// </summary>
        /// <param name="executionContext">The execution context</param>
        protected override void ExecuteCore(ActivityExecutionContext executionContext)
        {
            // Prepare the PromptBuilder
            pb = new PromptBuilder();
            pb.AppendText(pt);

            // Specify the event-handler and play seven seconds of the prompt
            Workflow.Synthesizer.SpeakCompleted += Synthesizer_SpeakCompleted;
            Workflow.Synthesizer.SpeakAsync(pb, System.TimeSpan.Parse("00:00:02.5000000"));
        }
        /// <summary>
        /// Closes the activity.
        /// </summary>
        /// <param name="sender">The synthesizer</param>
        /// <param name="e">The result of SpeakAsync</param>
        private void Synthesizer_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
        {
            // Remove this event-handler
            Workflow.Synthesizer.SpeakCompleted -= Synthesizer_SpeakCompleted;

            // End the custom activity
            Close(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

ISynthesizer Interface
ISynthesizer Members
Microsoft.SpeechServer.Synthesis Namespace