Share via


RecordMessageActivity.Abandon Method (Object, RecognizedEventArgs)

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.

Abandons recording, allowing RecordMessageActivity to exit successfully.

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

Syntax

'Declaration
Public Sub Abandon ( _
    sender As Object, _
    e As RecognizedEventArgs _
)
public void Abandon (
    Object sender,
    RecognizedEventArgs e
)

Parameters

  • sender
    A dummy argument to simplify the use of this method as an event handler. This parameter does not play any role in the logic of this method.
  • e
    A dummy argument to simplify the use of this method as an event handler. This parameter does not play any role in the logic of this method.

Remarks

The default action-phase grammars recognize "accept," "cancel," "continue," "play back," and "start over." If you use grammars other than the default action-phase grammars, call Abandon to abandon recording.

Example

The following example shows how to use custom action-phase grammars to respond to a user request to "cancel." The first of the five methods, RecordMessageWorkflow, sets UseDefaultGrammars to False, adds five rules to the Grammars property on recordMessage, and uses a while loop to attach an event handler to the Recognized property on each grammar rule. Each iteration through the loop attaches an event handler to one grammar in the Grammars collection.

recordMessage_RecordTurnStarting, the handler for the RecordTurnStarting event, plays a short prompt asking the user to record a message.

recordMessage_ActionTurnStarting, the handler for the ActionTurnStarting event, prompts the user for the action to perform.

Cancel_SpeechRecognized is called when the user requests that recording be canceled. This method sets a global variable to True, and then calls Cancel.

The last method, playMessage_TurnStarting, is the event handler for the TurnStarting event on a StatementActivity. If cancelFlag is False (that is, recordMessage has not been canceled), this method plays the audio data that the user recorded. Otherwise, this method plays a short message. This logic is necessary because recorded audio is deleted when a RecordMessageActivity exits.

public RecordMessageWorkflow()
{
  InitializeComponent();
  // Turn off default action-phase grammars
  this.recordMessage.UseDefaultGrammars = false;
  // Now load grammar rules for the five actions
  this.recordMessage.Grammars.Add(new Microsoft.SpeechServer.Recognition.Grammar(new System.Uri("http://localhost/RecordMessage/Grammars/Actions.grxml", System.UriKind.RelativeOrAbsolute), "Accept"));
  this.recordMessage.Grammars.Add(new Microsoft.SpeechServer.Recognition.Grammar(new System.Uri("http://localhost/RecordMessage/Grammars/Actions.grxml", System.UriKind.RelativeOrAbsolute), "Cancel"));
  this.recordMessage.Grammars.Add(new Microsoft.SpeechServer.Recognition.Grammar(new System.Uri("http://localhost/RecordMessage/Grammars/Actions.grxml", System.UriKind.RelativeOrAbsolute), "Continue"));
  this.recordMessage.Grammars.Add(new Microsoft.SpeechServer.Recognition.Grammar(new System.Uri("http://localhost/RecordMessage/Grammars/Actions.grxml", System.UriKind.RelativeOrAbsolute), "Playback"));
  this.recordMessage.Grammars.Add(new Microsoft.SpeechServer.Recognition.Grammar(new System.Uri("http://localhost/RecordMessage/Grammars/Actions.grxml", System.UriKind.RelativeOrAbsolute), "Startover"));

  // Attach handlers to the Recognized property for each grammar rule
  // Get index of Accept grammar rule
  int idx = -1;
  IEnumerator en = this.recordMessage.Grammars.GetEnumerator();
  while (en.MoveNext())
  {
    idx++;
    if (((Grammar)en.Current).RuleName.Equals("Accept"))
    {
      this.recordMessage.Grammars[idx].Recognized += Accept_SpeechRecognized;
    }
    else if (((Grammar)en.Current).RuleName.Equals("Cancel"))
    {
      this.recordMessage.Grammars[idx].Recognized += Cancel_SpeechRecognized;
    }
    else if (((Grammar)en.Current).RuleName.Equals("Continue"))
    {
      this.recordMessage.Grammars[idx].Recognized += Continue_SpeechRecognized;
    }
    else if (((Grammar)en.Current).RuleName.Equals("Playback"))
    {
      this.recordMessage.Grammars[idx].Recognized += Playback_SpeechRecognized;
    }
    else if (((Grammar)en.Current).RuleName.Equals("Startover"))
    {
      this.recordMessage.Grammars[idx].Recognized += Startover_SpeechRecognized;
    }
    else break;
  }
}


private void recordMessage_RecordTurnStarting(object sender, TurnStartingEventArgs e)
{
  this.recordMessage.RecordingMainPrompt.SetText("Record your message now");
}


private void recordMessage_ActionTurnStarting(object sender, TurnStartingEventArgs e)
{
  this.recordMessage.ActionMainPrompt.SetText("What action do you want to perform?");
  this.recordMessage.ActionMainPrompt.AppendText("Choose from accept, cancel, continue, play back, or start over");
}


void Cancel_SpeechRecognized(object sender, RecognizedEventArgs e)
{
  cancelFlag = true;
  this.recordMessage.Abandon(sender, e);
}


private void playMessage_TurnStarting(object sender, TurnStartingEventArgs e)
{
  if (!cancelFlag)
  {
    this.playMessage.MainPrompt.ClearContent();
    this.playMessage.MainPrompt.AppendAudio(this.recordMessage.RecordedFilePath);
  }
  else
    this.playMessage.MainPrompt.SetText("All done");
}

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

RecordMessageActivity Class
RecordMessageActivity Members
Microsoft.SpeechServer.Dialog Namespace
UseDefaultGrammars
Grammars
Recognized
RecordTurnStarting
ActionTurnStarting
TurnStarting
StatementActivity
RecordMessageActivity.Abandon Method