Customizing Greetings at Runtime

Most of the VBVoice controls have some greetings to be played at different stages of voice processing. When the call enters the control, just after the EnterEvent is fired, the EnterGreeting is played. Some controls, like GetDigits, play an InvalidGreeting on bad input from caller.

These greetings are initial properties of the control of type Greeting Object. They are global per control, applying to all channels, e.g. setting a Music greeting for a Delay control would play the same music on any channel in that control.

Note: Being initial properties, they should not be modified at runtime after the voice system has been started (by calling VBVFrame.StartSystem.)

VBVoice controls have some design-time properties for configuring greetings programmatically. Remember that changing a design-time property affects all channels and is normally used before starting the voice system.

But this raises the question: how could be these greetings customized at runtime? Here is the answer:

Modifying Greetings

There are three ways to modify greetings at runtime:

  1. Control Property Substitution

  2. System Phrase type VBPhrase

  3. Enter and EnterB Events

Enter and EnterB events

In the Enter event, an object is passed as parameter, representing another instance of control's EntryGreeting. This is the actual greeting which is going to be played on the channel, then discarded after being played.

You can directly manipulate the phrases in this greeting (without affecting the control's Initial EntryGreeting property), using code in the Enter event using Greeting and Phrase Objects. These objects provide methods and properties that can add, remove, or modify phrases in the greeting.

Note: The Greeting Object is passed as an object and, in C# and VB.NET with late binding disabled (Option Strict), it must be cast to Pronexus.VBVoice.Greeting in order to be able to call its methods.

You can directly manipulate the phrases in the EntryGreeting, using code in the EnterEvent and EnterB events using Greeting and Phrase Objects. These objects provide methods and properties that can add, remove, or modify phrases in the greeting.

For more information on using Greeting and Phrase objects, see Greeting Objects.

New phrases can be created using the Phrase Create methods and can be added or inserted into a greeting using the InsertPhrase method of the Greeting.

Existing phrases in a greeting can be manipulated directly using the Phrase property of the Greeting, in conjunction with the Phrase properties, to modify the phrase data.

Note: This way to customize greetings is applicable only to EntryGreeting.

EXAMPLES

Add a New Phrase

VB

Greeting.InsertSysPhrase 0, vbvSayNumber, "123"

or

Dim newPhrase As new Phrase
newPhrase.PhrsType = vbvSYSPHRASE
newPhrase.Type = vbvSayNumber
newPhrase.PhraseData1 = "123"
Greeting.Phrase(0) = newPhrase

or

Dim newPhrase as Object
Set newPhrase = CreateObject("vbv.phrase")
Greeting.InsertPhrase 0, newPhrase

VB.NET

Dim greet As VBVoiceLib.Greeting
greet = e.greeting
greet.InsertSysPhrase(0, VBVoiceLib.vbvSysPhraseConstants.vbvSayNumber, "123", "")

or

Dim greet As VBVoiceLib.Greeting
greet = e.greeting
Dim phrs As VBVoiceLib.Phrase
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvMoney
phrs.PhraseData1 = "1235"
greet.InsertPhrase(0, phrs)

C#

VBVoiceLib.Greeting greet = e.greeting as VBVoiceLib.Greeting;
greet.InsertSysPhrase(0, VBVoiceLib.vbvSysPhraseConstants.vbvSayNumber, "123", "");

or

VBVoiceLib.Greeting greet = e.greeting as VBVoiceLib.Greeting;
VBVoiceLib.Phrase phrs = new VBVoiceLib.Phrase();
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE;
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvMoney;
phrs.PhraseData1 = "1235";
greet.InsertPhrase(0, phrs);

Change an Existing Phrase

VB

Dim nphrase as Phrase
Set nphrase = Greeting.Phrase(0)
nphrase.PhrsType = vbvSysPhrase
Greeting.Phrase(0).Type = vbvSayNumber
Greeting.Phrase(0). PhraseData1 = "123"

VB.NET

Dim greet As VBVoiceLib.Greeting
greet = e.greeting
Dim phrs As VBVoiceLib.Phrase
phrs = greet.get_Phrase(0)
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvMoney
phrs.PhraseData1 = "1235"
greet.Phrase(0) = phrs

C#

VBVoiceLib.Phrase phrs = new VBVoiceLib.Phrase();
phrs = (e.greeting as VBVoiceLib.Greeting).get_Phrase(0);
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE;
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvMoney;
phrs.PhraseData1 = "1235";
greet.set_Phrase(0, phrs);

Add a new SayDate Phrase

VB

Dim NewPhrase As Object
Set NewPhrase = New Phrase
NewPhrase.PhrsType = vbvSYSPHRASE
NewPhrase.Type = vbvSayDate
NewPhrase.PhraseData1 = "10/12/2000"
NewPhrase.PhraseData2 = "Day,MonthName,Year"
Greeting.InsertPhrase 0, NewPhrase

VB.NET

Dim greet As VBVoiceLib.Greeting = TryCast(e.greeting,Greeting)
Dim phrs As VBVoiceLib.Phrase = New VBVoiceLib.Phrase
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvSayDate
phrs.PhraseData1 = "10/12/2010"
phrs.PhraseData2 = "Day,MonthName,Year"
greet.InsertPhrase(0, phrs)

C#

VBVoiceLib.Greeting greet = e.greeting as VBVoiceLib.Greeting;
VBVoiceLib.Phrase phrs = new VBVoiceLib.Phrase();
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE;
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvSayDate;
phrs.PhraseData1 = "10/12/2010";
phrs.PhraseData2 = "Day,MonthName,Year";
greet.InsertPhrase(0, phrs);

Add a new DateToday Phrase

VB

Dim NewPhrase As Object
Set NewPhrase = New Phrase
NewPhrase.PhrsType = vbvSYSPHRASE
NewPhrase.Type = vbvDateToday
ewPhrase.PhraseData1 = "Day,MonthName,Year"
Greeting.InsertPhrase 0, NewPhrase

VB.NET

Dim greet As VBVoiceLib.Greeting = TryCast(e.greeting,Greeting)
Dim phrs As VBVoiceLib.Phrase = New VBVoiceLib.Phrase
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvDateToday
phrs.PhraseData1 = "Day,MonthName,Year"
greet.InsertPhrase(0, phrs)

C#

VBVoiceLib.Greeting greet = e.greeting as VBVoiceLib.Greeting;
VBVoiceLib.Phrase phrs = new VBVoiceLib.Phrase();
phrs.PhrsType = VBVoiceLib.vbvPhraseTypeConstants.vbvSYSPHRASE;
phrs.Type = VBVoiceLib.vbvSysPhraseConstants.vbvDateToday;
phrs.PhraseData1 = "Day,MonthName,Year";
greet.InsertPhrase(0, phrs);

For more information, see Greeting Objects and Phrase Objects in the reference section.

Greeting Properties

VBVoice controls have some design-time properties for configuring greetings programmatically. Remember that changing a design-time property affects all channels, and is normally used before VBVFrame.StartSystem is called. The greeting properties are:

Customizing Greetings Examples

VBVoice has a CustPhrs example -- demonstrates custom greeting code.

To view a sample application that demonstrates the use of VBVoice custom greeting code, see CustPhrs.