ebook img

Java InstantCode: Developing Applications using Java Speech API PDF

146 Pages·0.822 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Java InstantCode: Developing Applications using Java Speech API

toc Java InstantCode: Developing Applications using Java Speech API SkillSoft Press © 2004 Use this code-intensive reference to design speech-enabled Java applications and provides support for speech synthesizers, command and control recognizers, and more. Table of Contents Introduction Copyright Chapter 1- Introduction to Java Speech API Chapter 2- Creating a Speech-Enabled Calendar Application Chapter 3- Creating a Voice Synthesizer Application Chapter 4- Creating a Voice Help Application Chapter 5- Creating a Counting Application Chapter 6- Creating a Form Validation Application Chapter 7- Creating an Online Java Tutorial Application Chapter 8- Creating the Auto Answering Machine Application Index List of Figures List of Listings CD Content file:///D|/...nsorted/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/toc.html[03.12.2011 18:59:56] Introduction Introduction About InstantCode Books The InstantCode series is designed to provide you - the developer - with code you can use for common tasks in the workplace. The goal of the InstantCode series is not to provide comprehensive information on specific technologies - this is typically well-covered in other books. Instead, the purpose of this series is to provide actual code listings that you can immediately put to use in building applications for your particular requirements. How These Books are Structured The underlying philosophy of the InstantCode series is to present code listings that you can download and apply to your own business needs. To support this, these books are divided into chapters, each covering an independent task. Each chapter includes a brief description of the task, followed by an overview of the element of the book's subject technology that we will use to perform that task. Each section ends with a code listing: each of the individual code segments in the chapter is independently downloadable, as is the complete chapter code. You will be able to download source code files, as well as application files. Who Should Read These Books These books are written for software development professionals who have basic knowledge of the associated technology and want to develop customized technology solutions. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0001.html[03.12.2011 18:59:57] Copyright Copyright Java InstantCode: Developing Applications Using Java Speech API Copyright © 2004 by SkillSoft Corporation All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of SkillSoft. Trademarked names may appear in the InstantCode series. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Published by SkillSoft Corporation 20 Industrial Park Drive Nashua, NH 03062 (603) 324-3000 [email protected] The information in this book is distributed on an "as is" basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author nor SkillSoft shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0003.html[03.12.2011 18:59:57] Chapter 1: Introduction to Java Speech API Chapter 1: Introduction to Java Speech API The Java Speech API (JSAPI) helps you design speech-enabled Java applications and provides support for speech synthesizers, command and control recognizers, and dictation systems. JSAPI is a part of the Java Media API, which enhances the functioning of Java applications by using audio, video, animation, graphics, and images. This chapter describes the JSAPI technologies and packages that help you create speech-enabled applications for converting text to speech. The two main speech technologies supported by JSAPI are: Speech Synthesis: Converts the input text to speech. Speech Recognition: Converts the input audio to text. Speech Synthesis The speech synthesis technology helps you develop Java applications that convert text to speech. This process of converting text to speech is known as Text To Speech (TTS) conversion. The various phases in TTS conversion are: 1. Formation analysis: The speech synthesizer analyzes the input text to determine the start and end of paragraphs, sentences, and words. 2. Text analysis: The speech synthesizer identifies the text for special language constructs, such as abbreviations, date, time, e-mail address, and credit card number. 3. Text-to-phoneme conversion: The speech synthesizer converts each unit of text to phonemes. A phoneme is a unit of sound. Different languages have varied sets of sounds and phonemes. 4. Wave format production: The phoneme generated in the previous phase generates the audio waveform. Generation of an audio waveform occurs for each unit of text. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0004.html[03.12.2011 18:59:58] Chapter 2: Creating a Speech-Enabled Calendar Application Chapter 2: Creating a Speech-Enabled Calendar Application 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: SelectFormat.java: Allows an end user to choose a date format from the various formats provided by the interface. SpeakText.java: Converts to speech the date, day, and time values that the end user specifies. SpeechCalendar.java: Allows the end user to retrieve current system date, day, and time from the computer. 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. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0007.html[03.12.2011 18:59:58] Chapter 3: Creating a Voice Synthesizer Application Chapter 3: Creating a Voice Synthesizer Application Download CD Content The Java Speech API provides the javax.speech package that contains various classes and interfaces, such as the Central, EngineList and EngineModeDesc classes and the Engine interface. The Central class helps you locate, select, and create speech recognizers and speech synthesizers. The EngineList class helps you select speech engines and contains a set of EngineModeDesc class objects. The EngineModeDesc class provides information about the speech engine, such as locale and mode of operation of the speech engine. This chapter describes how to develop the Voice Synthesizer application that converts text to speech by using the javax.speech and javax.speech.synthesis packages. In this application, end users can select the required voice for speech conversion. Architecture of the Voice Synthesizer Application The Voice Synthesizer application provides an interface that allows end users to create a text file or open an existing file in the text area provided by the interface. This application retrieves and lists all the voices that an end user’s computer supports. This application converts the text specified in the text area to speech by using the voice selected by the end user. The Voice Synthesizer application uses the following files: TextPad.java: Creates the user interface for the Voice Synthesizer application. This file also sets the voice of the synthesizer to read out the written text. SelectVoice.java: Helps an end user to select the voice that the synthesizer uses to read out the text. SpeakText.java: Converts text to speech by using the voice selected by an end user. Figure 3-1 shows the architecture of the Voice Synthesizer application: Figure 3-1: Architecture of the Voice Synthesizer Application The TextPad.java file creates the user interface of the Voice Synthesizer application that contains the File and Voice menus. The File menu allows end users to create a file to write the required text or to open an existing file. If an end user selects the Voice-> Select Voice option in the user interface, the TextPad.java file calls the SelectVoice.java file. The SelectVoice.java file retrieves all the voices that the end user’s computer supports and allows the end user to select the voice in which the synthesizer reads out the text. The interface of the SelectVoice.java file provides two radio buttons, Voice 1 and Voice 2, for selecting a voice. After selecting a voice, the end user selects the Speak button and the TextPad.java file calls the SpeakText.java file. The SpeakText.java file converts the text to speech in the voice selected by the end user. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0012.html[03.12.2011 18:59:59] Chapter 4: Creating a Voice Help Application Chapter 4: Creating a Voice Help Application Download CD Content The Java API provides the javax.speech and javax.speech.synthesis packages to develop the Voice Help application. This chapter describes how to develop the Voice Help application that provides help information for the various menu options, such as File and Voice. End users can listen to this help information. Architecture of the Voice Help Application The Voice Help application provides end users help information about various interface elements, such as menu options and buttons. The Voice Help application uses the following files: SpeakHelp.java: Allows an end user to select a menu option or a button to listen to the help information for that menu option or button in the selected voice. SelectHelpVoice.java: Allows an end user to select the required voice. SpeakHelpText.java: Converts the text attached to menu options to speech in the selected voice. This file allows the end users to start and stop the audio. Figure 4-1 shows the architecture of the Voice Help application: Figure 4-1: Architecture of the Voice Help Application The SpeakHelp.java file provides end users with the main user interface that contains the File and Voice menus and three buttons: Speak, Stop, and Help. The File menu allows end users to create a file or open an existing file in the text area provided by the interface. The Voice menu contains the Select Voice menu option to select the required voice from the list of voices that an end user’s system supports. The SpeakHelp.java file calls the SelectHelpVoice.java file to set the selected voice as the help voice. An end user can select any of the menu options and click the Help button to listen to the help information for the selected option. The SpeakHelp.java file calls the SpeakHelpText.java file to convert the text attached to the menu options to speech in the voice selected by an end user. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0017.html[03.12.2011 18:59:59] Chapter 5: Creating a Counting Application Chapter 5: Creating a Counting Application Download CD Content The Java API provides the javax.speech and javax.speech.synthesis packages to develop an application to count the number of vowels, consonants, words, and sentences in the text provided by an end user. This helps in calculating the word count of a document. This chapter describes how to develop a Counting application, which provides a user interface containing four buttons to count the number of vowels, consonants, words, and sentences in the specified text. This application converts the count values to speech in the voice selected by an end user. Architecture of the Counting Application The Counting application uses the following files: SpeechCounting.java: Allows an end user to specify the text in the text area provided by the interface. This file also counts the number of vowels, consonants, words, and sentences in the specified text. SpeakCounting.java: Converts the count values to speech. SelectVoiceType.java: Allows an end user to select the voice in which the application converts the count values to speech. Figure 5-1 shows the architecture of the Counting application: Figure 5-1: Architecture of the Counting Application The SpeechCounting.java file creates the user interface of the Counting application that contains the File menu and four buttons: Vowel, Consonant, Word, and Sentence. The File menu allows end users to open an existing file in the text area provided by the interface. An end user can select File->Select Voice to select the required voice. The application uses the selected voice to read out the count values of vowels, consonants, words, and sentences. The SpeechCounting.java file calls the SelectVoiceType.java file, which provides an interface that contains two radio buttons, Voice 1 and Voice 2, for selecting a voice. The SpeechCounting.java file calls the SpeakCounting.java file to convert the count values of vowels, consonants, words, and sentences to speech. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0022.html[03.12.2011 19:00:00] Chapter 6: Creating a Form Validation Application Chapter 6: Creating a Form Validation Application Download CD Content The Java API provides the javax. speech and javax.speech.synthesis packages to develop an application to check the validity of field values specified by an end user in a form. This chapter describes how to develop a Form Validation application, which converts the validation error text and confirmation message text to speech by using the javax.speech and javax.speech.synthesis packages . This application provides a user interface that contains a blank user information form. The application validates the values provided by an end user in the different fields of the form to check for errors and reads out the validation error text. If the end user enters valid values in the specified fields, the Form Validation application reads out the confirmation message text. Architecture of the Form Validation Application The Form Validation application allows end users to listen to the validation error text in the user information form. When an end user clicks the Save button, the application converts the validation error text to speech. The Form Validation application uses the following files: FormValidation.java: Allows end users to enter the user information form. This file also checks whether or not the information specified by an end user is correct. SpeakFormValidation.java: Converts the validation error text to speech. Figure 6-1 shows the architecture of the Form Validation application: Figure 6-1: Architecture of the Form Validation Application The FormValidation.java file provides end users with the user information form, which contains various labels, text boxes, combo boxes, and the Save and Close buttons. This file allows end users to fill the user information form and checks for errors in the form. The FormValidation.java file passes the validation errors to the SpeakFormValidation.java file. When an end user clicks the Save button, the FormValidation.java file calls the SpeakFormValidation.java file to convert the validation errors passed by the FormValidation.java file to speech. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0027.html[03.12.2011 19:00:01] Chapter 7: Creating an Online Java Tutorial Application Chapter 7: Creating an Online Java Tutorial Application Download CD Content The Java API provides the javax.speech.synthesis and javax.speech packages to develop an application that converts the text in an online Java tutorial to speech. This chapter describes how to develop the Online Java Tutorial application, which converts the text in the Java tutorial to speech by using the javax.speech and javax.speech.synthesis packages. This application provides a user interface using, which end users can select, any topic of the tutorial to view the text in that topic. The application then reads out the selected topic. Architecture of the Online Java Tutorial Application The Online Java Tutorial application allows end users to listen to the text in the tutorial. The application provides two panes, left and right. The left pane shows the various topics of the tutorial. The right pane shows the text contained in the selected topic. The application converts the text corresponding to the selected topic in the tutorial to speech. The Online Java Tutorial application uses the following files: Tutorial.java: Allows end users to select a topic from the tutorial to view the corresponding text. SpeakText.java: Converts the text in the Java tutorial to speech. Figure 7-1 shows the architecture of the Online Java Tutorial application: Figure 7-1: Architecture of the Online Java Tutorial Application The Tutorial.java file provides the main user interface, which is divided into two panes, left and right. The Tutorial.java file calls the SpeakText.java file to convert the text corresponding to the selected topic to speech. file:///D|/...ed/old/Java%20InstantCode.%20Developing%20Applications%20using%20Java%20Speech%20API(2004)/8253final/LiB0031.html[03.12.2011 19:00:01]

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.