JSAPI 2.0

javax.speech
Class AudioSegment

Object
  extended by AudioSegment

public class AudioSegment
extends Object

Associates audio data with a representation of the audio format.

The format of the audio data is described by a media locator String. Use getMediaLocator to get the format. Media locators are described in the AudioManager. Examples of media locators include:

Audio data may be provided by subclasses that override the openInputStream method. Some implementations may limit the capability to get the audio data as indicated by isGettable. Implementations will return a subclass of this class that checks security settings as documented in openInputStream. This class does not check security settings when used directly.

See Also:
openInputStream, getMediaLocator, isGettable, AudioManager

Constructor Summary
AudioSegment(String locator, String markupText)
          Constructs an AudioSegment from the resource indicated by the given media locator.
 
Method Summary
 String getMarkupText()
          Returns the alternate markup text that may be used in case there is a problem with the audio for this AudioSegment.
 String getMediaLocator()
          Returns the media locator for this AudioSegment.
 boolean isGettable()
          Indicates that a openInputStream request will not throw a SecurityException.
 InputStream openInputStream()
          Returns an InputStream that can be used to read this AudioSegment's contents.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AudioSegment

public AudioSegment(String locator,
                    String markupText)
             throws IllegalArgumentException
Constructs an AudioSegment from the resource indicated by the given media locator.

The media locator defines the format and location of the data as described in the AudioManager. The markupText may be used in case there is a problem with the audio data.

The following example shows how to speak audio from a URL:

   Synthesizer synth = ...        // see Synthesizer for creation options
   synth.allocate();
   
   AudioSegment audio = 
       new AudioSegment("http://www.example.org/audio.wav", 
                        "<speak xml:lang='en-US' version='1.0'>" +
                            "My name is Smith" +
                        "</speak>"); 
   synth.speak(audio, null);      // speak
 

Parameters:
locator - a non-null media locator description
markupText - the alternate markup text
Throws:
IllegalArgumentException - if an invalid parameter value is specified
See Also:
openInputStream, getMediaLocator, getMarkupText, AudioManager
Method Detail

getMediaLocator

public String getMediaLocator()
Returns the media locator for this AudioSegment. This locator specifies characteristics about this AudioSegment including the sample rate and encoding.

If openInputStream returns null, then the locator must also encode information used to determine how to obtain the data (e.g., a "resource:" or "http:" locator).

Returns:
a media locator description.
See Also:
openInputStream, getMarkupText, AudioManager

getMarkupText

public String getMarkupText()
Returns the alternate markup text that may be used in case there is a problem with the audio for this AudioSegment.

Returns:
the alternate markup text for this AudioSegment
See Also:
openInputStream, getMediaLocator

openInputStream

public InputStream openInputStream()
                            throws IOException,
                                   SecurityException
Returns an InputStream that can be used to read this AudioSegment's contents.

The media locator returned by getMediaLocator defines the format of the data.

null is returned unless this method is overridden by a subclass.

A SecurityException is not thrown if isGettable returns true.

Returns:
a new InputStream pointing to the beginning of the AudioSegment's data
Throws:
IOException - if an I/O error occurs
SecurityException - if the application does not have permission
See Also:
isGettable, getMediaLocator, getMarkupText
Required permission:
javax.speech.AudioSegment.openInputStream

isGettable

public boolean isGettable()
Indicates that a openInputStream request will not throw a SecurityException.

This method always returns true unless overridden by a subclass.

Returns:
true if access is allowed to this audio data
See Also:
getMediaLocator, openInputStream

JSAPI 2.0

JavaTM Speech API 2.0, Final Release v2.0.6.
© 2008, Conversay and Sun Microsystems.

Free Web Hosting