Java InstantCode. Developing Applications using Java Speech API

 Download CD Content

The Java API provides the javax.speech and javax.speech.synthesis packages that contain classes, such as SynthesizerModeDesc, SynthesizerProperties, and Voice and interfaces, such as Synthesizer, which help convert text to speech. To convert text to speech, the javax.speech.synthesis package allows you to retrieve and list all the system voices installed on a computer. The javax.speech package provides a class called central, which helps you to locate, select, and create speech recognizers and speech synthesizers.

This chapter describes how to develop a speech-enabled calendar application, which reads out the date, day, and time specified by an end user by using the javax.speech and javax.speech.synthesis packages. To specify the date, the end user selects the required date format. The application also checks the validity of the date specified. If the date is invalid, the application reads out an error message.

Architecture of the Speech-Enabled Calendar Application

The Speech-Enabled Calendar application uses the following files:

Figure 2-1 shows the architecture of the Speech-Enabled Calendar application:

Figure 2-1: Architecture of the Speech-Enabled Calendar Application

The SpeechCalendar.java file allows an end user to retrieve the current date, day, and time from the computer and validates the date entered by the end user. This file also sets the date in the format specified by the end user. If the end user selects the Date option, the application provides an interface with two radio buttons , Current Date and Enter Date. The Current Date option retrieves the current date from the computer and displays it. The Enter Date option prompts the end user to specify a date and checks whether or not the date is in a valid format.

If an end user clicks the Select Date Format button, the SpeechCalendar.java file calls the SelectFormat.java file, which provides the end user with various date formats. An end user can select the required date format. If the end user clicks the Speak button, the SpeechCalendar.java file calls the SpeakText.java file, which retrieves and lists all the types of voices supported by the end user s computer. When an end user selects a voice, the specified date, day, or time is spoken out in that voice.

Категории