http://www.annedawson.net/JavaSpeech.txt Last updated: Friday 12th September 2008, 8:38, AHD Refresh to get latest version The following information has been adapted from: "Simply Java Programming" by Deitel and Deitel, ISBN 0-13-142648-6 Pages 819 - 833 The following text is for information only. Students will NOT be tested on any of this material. ************************************************************* ************************************************************* Installation instructions for Java Speech API version FreeTTS ************************************************************* ************************************************************* -------------------------------------- Java Speech - How to making Java speak -------------------------------------- --------------------------------------- Creating Speech from text using FreeTTS --------------------------------------- Introduction ------------ FreeTTS is open source (free) software written entirely in Java - and licensed for use by the creators of Java - Sun Microsystems. FreeTTS gives you the ablility to write Java programs (applications or applets) which will allow speech output generated from inputted text - i.e. the text you input at the keyboard will be spoken through your computer's speakers. This type of Java application might be used, for example, to automatically generate telephone messages, or to put aural content onto web pages for the blind or seeing-impaired. This type of program gives people who cannot speak, the chance to conduct a telephone conversation... There are lots of applications for a speech synthesizer like FreeTTS. -------------------------- Java programs are portable -------------------------- Java programs work on many different types of hardware and mobile devices. Java applet programs are embedded in webpages - thus can run on the Internet through all the latest browsers. Client computers that want to run a java program need the Java Runtime Environment (JRE) installed on their machine. Most computers now have a JRE by default. Java needs to be installed on the computer that runs a java program using the speech synthesizer FreeTTS. Any Java version (from 2005 onwards) will do. The creators of Java talk about FreeTTS here: https://java.sun.com/products/java-media/speech/ Reference information about FreeTTS can be found here: http://freetts.sourceforge.net/docs/index.php To install FreeTTS: ------------------ Go here: http://sourceforge.net/project/showfiles.php?group_id=42080&package_id=34183 scroll down and select the following file: Release 1.1.2 This is not the latest release, but it is the release used with these instructions, and with the example programs referred to. Use FreeTTS Release 1.1.2. Save the downloaded file freetts-1_1_2.tar.gz to your computer. 1. Unzip the file using WinZip 2. While in WinZip, select Yes to decompress the freetts-1_1_2.tar file to a temporary directory. 3. Extract the content of the freetts-1_1_2.tar file to C:\ This will create a FreeTTS directory in the C:\ directory. Accept the license Agreement ---------------------------- IMPORTANT: To complete the installation you need to click on the Start button on the Desktop, then Run, then click on the Browse button and browse to C:\FreeTTS\lib\jsapi.exe and click the button to agree to the License Agreement. OR to do the same thing using a Command Prompt window: Start button -> All Programs -> Accessories -> Command Prompt At a command prompt, type: cd C:\FreeTTS\lib Then, type: jsapi.exe This installs the Java Speech API after you click the button to agree to the License Agreement. Install the speech.properties file ---------------------------------- Install the speech.properties file simply by copying the file C:\FreeTTS\speech.properties to the jre\lib directory of your J2SE installation. For example, if your Java SDK is installed in c:\Program Files\Java\jdk1.6.0_02 you should copy the C:\FreeTTS\speech.properties file to: c:\Program Files\Java\jdk1.6.0_02\jre\lib Set the CLASSPATH environment variable -------------------------------------- When Java is installed it knows where to find its own classes, but if you install extra classes (like those included with FreeTTS) Java needs to know where to find them. Use notepad.exe: Start button -> All Programs -> Accessories -> Notepad to create a batch file (just a regular text file) which you save as setclasspath.bat in c:\Program Files\Java\jdk1.6.0_02\bin setclasspath.bat contains the following set CLASSPATH line: (IMPORTANT: the next line is all on one line - don't press the Enter key) set CLASSPATH=C:\FreeTTS\lib\cmuawb.jar;C:\FreeTTS\lib\cmukal16.jar;C:\FreeTTS\lib\cmukal8.jar;C:\FreeTTS\lib\cmulex.jar;C:\FreeTTS\lib\cmutimelex.jar;C:\FreeTTS\lib\demo.jar;C:\FreeTTS\lib\freetts.jar;C:\FreeTTS\lib\JSAPI.JAR;. Copy and paste the above line into your setclasspath.bat file, or better still, just download from: http://www.annedawson.net/setclasspath.bat Save this setclasspath.bat file in c:\Program Files\Java\jdk1.6.0_02\bin You create another batch file which you can save as C:\go.bat - which contains these two lines: cd c:\Program Files\Java\jdk1.6.0_02\bin dir or just download from: http://www.annedawson.net/go.bat Windows stores environment variables to store things like the paths to program installations. The environment variable for Java is automatically set when Java is installed and shouldn't need to be changed. This environment variable is called JAVA_HOME and should have a value of your SDK installation directory path, e.g. c:\Program Files\Java\jdk1.6.0_02 To check or change JAVA_HOME environment variable ------------------------------------------------- 1. Start -> My Computer 2. Click on View System Information 2. Click the Advanced Tab 3. Click the Environment Variables button See if the variable JAVA_HOME exists and if its value matches your installation path: c:\Program Files\Java\jdk1.6.0_02\bin or c:\Program Files\Java\jdk1.6.0_02\bin; If there is no variable JAVA_HOME, then: 4. Under System Variable, click New 5. Enter the variable name as JAVA_HOME 6. Enter the variable value as the install path for the Development Kit: e.g. c:\Program Files\Java\jdk1.6.0_02\bin; 7. Click OK 8. Click Apply Changes Testing the Speaker class ------------------------- Copy the following files to your c:\Program Files\Java\jdk1.6.0_02\bin folder: http://www.annedawson.net/Speaker.java http://www.annedawson.net/Speaks.java http://www.annedawson.net/SpeakerHelper.java http://www.annedawson.net/setclasspath.bat make sure that http://www.annedawson.net/go.bat is saved to your C:\ folder. In a command prompt Start -> All Programs -> Accessories -> Command Prompt At the command prompt type: cd \ go You will see a file listing for folder: c:\Program Files\Java\jdk1.6.0_02\bin Now type: setclasspath you will see the SET classpath instuction. You now need to compile each of the three java files listed above, by proceeding as follows: At the command prompt, type: javac Speaker.java after a short time the prompt reappears. Now type: javac Speaks.java after a short time the prompt reappears. Now type: javac SpeakerHelper.java after a short time the prompt reappears. To run the compiled version of the Speaker.java test program (which uses the other two java files), make sure your speakers are switched on and working, then type: java Speaker After a short pause you will be asked to enter some text. Enter a sentence and press the Enter key when you've finished. Your sentence will be spoken by the Java Speech Synthesizer FreeTTS Copy and Paste any text into the running java program ----------------------------------------------------- Open up the following files in a text editor: http://www.annedawson.net/JavaSpeechTest.txt In the text editor, highlight all the text and Edit -> Copy Run the running Java program: At the command prompt, type: java Speaker and when the program asks you to "Please enter some text...", right click on the Command Prompt run window's title bar, and select Edit -> Paste. You should hear the written text spoken. ******************************************************************** ******************************************************************** To run the Speaker program when everything is installed and compiled ******************************************************************** ******************************************************************** Start -> All Programs -> Accessories -> Command Prompt At the command prompt type: cd \ go setclasspath java Speaker ******************************************************************** ******************************************************************** ******************************************************************** ********************************************************************