You can use prerecorded speech or text-to-speech in a Java voice application
by using one of the following subclasses of MediaType. These media
data objects specify the sounds that the caller hears:
- VoiceSegment specifies recorded voice data and is used both for
output, and for input recorded from the user.
- DTMFSequence specifies a number of dual-tone multifrequency
signals to be played.
- AudioCurrency specifies a currency amount to be spoken.
- AudioDate specifies a date to be spoken.
- AudioNumber specifies a number to be spoken.
- AudioString specifies a character string to be spoken.
- AudioTime specifies a time to be spoken.
- TextToSpeech specifies text from which speech is to be synthesized.
- MediaSequence is a composite of other MediaType objects.
VoiceSegment and DTMFSequence are primitive audio types;
they can be played by the telephony server directly. All other media type
objects are decomposed by the system into a sequence of these two types, so
that they can be played to the user. For example, an AudioTime object
representing a time of 3:30 pm would be decomposed and played as three VoiceSegments: 'three', 'thirty', 'p m'.
The locale of each media type object can be individually altered using
the
setLocale() method inherited from the
MediaType superclass. This method is useful for creating multilingual applications
as it changes the language in which an individual media type object is spoken.
For example, if this method was used to set the locale of the 3:30 pm
AudioTime object to French, it would be spoken as 'quinze', 'heures',
'trente'. If the locale is not specified when the object is created, the default
locale is used. The default locale is taken from the application, or if you
are running your application managed (in a node), the node in which the application
is running. The
setLocale() method takes a
java.util.Locale object
as a parameter. For example, to change the locale of an
AudioTime object
called 'today' to French:
today.setLocale(new Locale("fr","FR"));
The MediaType class also has a style property
that affects the way in which the media object is spoken. For example, if
the Full style is specified for an AudioDate, the value
2000/1/26 is spoken as “Thursday, January twenty-six, two thousand”
while the same value is spoken as “Thursday” if DOW (day-of-week)
is specified. The style property only applies to AudioDate, AudioTime, AudioNumber, AudioCurrency and AudioString — for other media types the style property is ignored. For more
information see the individual section for the relevant MediaType.
Note: If you define your MediaType objects as 'static',
one copy is shared between all instances of an application within a JVM, reducing
overall storage usage.
To play a voice segment or any other
MediaType object in an application,
use one of the following
Call methods:
- play(MediaType message)
- Used to play a simple uninterruptible message that requires no response,
using any kind of MediaType.
- play(MediaType[] message)
- Used to play a composite, uninterruptible message that requires no response.
The message can include one or more voice segments together with other media
objects such as AudioNumber, AudioCurrency, AudioDate, AudioString, or AudioTime. The MediaType objects
in the array, which can be in any order, are played in sequence.
You can
use the Call.play(Playable message) method to play your own mixed media objects.
- playAndGetInput(PlayAttributes, InputAttributes, DTMFAttributes, RecoAttributes)
- Used to play an interruptible or non-interruptible free form message
that requires a response. The attribute objects are used to define what to
play, how to play it, and what to expect in return.
- playAndGetInput(PlayAttributes, MenuAttributes, DTMFAttributes, RecoAttributes)
- Used to play within a menu structure an interruptible or non-interruptible
message that requires a response. The attribute objects are used to define
what to play, how to play it, and what to expect in return.