PageRenderTime 19ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/documentation/tutorial/tutorial.html

http://eyes-free.googlecode.com/
HTML | 162 lines | 135 code | 26 blank | 1 comment | 0 complexity | a9637429dda59bff0261f640d99ddab2 MD5 | raw file
  1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3<html xmlns="http://www.w3.org/1999/xhtml"
  4lang="en" xml:lang="en">
  5<head>
  6<title>Developing Speech Enabled Android Applications</title>
  7<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
  8<meta name="generator" content="Org-mode"/>
  9<meta name="generated" content="2008/12/12 10:20:46"/>
 10<meta name="author" content="Charles L. Chen"/>
 11<style type="text/css">
 12  html {
 13	font-family: Times, serif;
 14	font-size: 12pt;
 15  }
 16  .title { text-align: center; }
 17  .todo  { color: red; }
 18  .done { color: green; }
 19  .timestamp { color: grey }
 20  .timestamp-kwd { color: CadetBlue }
 21  .tag { background-color:lightblue; font-weight:normal }
 22  .target { background-color: lavender; }
 23  pre {
 24	border: 1pt solid #AEBDCC;
 25	background-color: #F3F5F7;
 26	padding: 5pt;
 27	font-family: courier, monospace;
 28  }
 29  table { border-collapse: collapse; }
 30  td, th {
 31	vertical-align: top;
 32	<!--border: 1pt solid #ADB9CC;-->
 33  }
 34</style>
 35</head><body>
 36<h1 class="title">Developing Speech Enabled Android Applications</h1>
 37
 38<h2>1 Introduction</h2>
 39
 40
 41<p>
 42The Text-To-Speech (TTS) library is allows developers to add speech to their applications. Developers give the TTS object a text string, and the TTS will take care of converting that string to text and speaking it to the user.
 43</p>
 44<p>
 45The TTS library is designed such that different underlying speech engines can be used without affecting the higher level application logic. Currently, a port of the <a href="http://espeak.sourceforge.net/">eSpeak engine</a> is available.
 46</p>
 47
 48<h2>2 Requirements</h2>
 49
 50
 51<p>
 52Using the eSpeak engine requires the user to have an SD card with free space available that the phone can access. The voice data for eSpeak will be downloaded and unzipped onto the SD card when the TTS is first run.
 53</p>
 54<p>
 55Note that if the SD card is mounted on the computer, it will not be accessible to the phone. You must unmount the SD card from the computer before the TTS will work properly.
 56</p>
 57
 58<h2>3 Setting Up an Eclipse Project That Uses the TTS</h2>
 59
 60
 61<ol>
 62<li>
 63<a href="http://code.google.com/android/intro/index.html">Setup an Android project as you would normally.</a>
 64
 65</li>
 66<li>
 67Go to Project &gt; Properties &gt; Java Build Path &gt; Libraries and click on "Add External JARs..."  Then add in the <a href="http://eyes-free.googlecode.com/svn/trunk/commonlibs/TTS_library_stub.jar">TTS_library_stub.jar</a> file.
 68
 69</li>
 70<li>
 71Start coding!
 72
 73</li>
 74</ol>
 75
 76<h2>4 A Step-By-Step Tutorial To Get You Started</h2>
 77
 78
 79<p>
 80This tutorial will take you step-by-step through writing a simple Hello World application. <a href="http://code.google.com/android/intro/index.html">It assumes that you have Eclipse setup to work with the Android SDK already.</a> 
 81</p>
 82<ol>
 83<li>
 84<a href="http://code.google.com/p/eyes-free/downloads/list">Get the TTS_library_stub.jar file from the downloads area.</a> If you want to develop against the upcoming release, get the release candidate version by grabbing the _rc.jar and installing the _rc.apk on your phone. If you want to develop against the version of the TTS that is currently on Market, get the _market.jar and install the TTS from the Android Market. You should always build your app using the _market version before you release it on the Market; otherwise, there is a high probability that your app will not work correctly as most users will be on the Market version of the TTS and not the release candidate. 
 85
 86</li>
 87<li>
 88Start Eclipse. Go to "File" &gt; "New Project" &gt; "Project..." and choose "Android Project" under "Android". Fill out the information and click "Finish" to generate the skeleton for a project. The rest of this tutorial assumes that you named your application "HelloWorldTTS".
 89
 90</li>
 91<li>
 92Select your project in the "Package Explorer", then go to "Project" &gt; "Properties". Select "Java Build Path" and click on the "Libraries" tab. Click on "Add external JARs..." and select the TTS_library_stub.jar from step 1.
 93
 94</li>
 95<li>
 96You should see two Java files in your project: HelloWorldTTS.java and R.java. Open HelloWorldTTS.java and do the following:
 97-In the imports section at the top of the file, add this line:
 98<pre>
 99import com.google.tts.TTS;
100</pre>
101-After the line "public class HelloWorldTTS extends Activity {", add this line:
102<pre>
103private TTS myTts;
104</pre>
105-Add the following as the last line of the onCreate method:
106<pre>
107myTts = new TTS(this, ttsInitListener, true);
108</pre>
109
110-After the onCreate method, add these lines:
111<pre>
112    private TTS.InitListener ttsInitListener = new TTS.InitListener() {
113        public void onInit(int version) {
114          myTts.speak("Hello world", 0, null);
115        }
116      };
117</pre>
118
119</li>
120<li>
121<a href="http://eyes-free.googlecode.com/svn/trunk/documentation/tutorial/HelloWorldTTS.java">Now you should have a HelloWorldTTS.java that looks something like this.</a>
122
123</li>
124<li>
125Build this app, install it on your Android device, and run it. You should hear the TTS say "hello world" if you have the TTS library installed on the phone and your SD card contains the needed voice data files. 
126  <ul><li>If you do not have the TTS library installed on the phone, you will be prompted to install it. 
127</li>
128<li>If this is the first time you have used an app that uses the TTS, you will hear the TTS spell out "h e l l o w o r l d" very fast and see a screen that says your device is downloading the voice data files; if you rerun the app, you will hear the TTS say "hello world" as it should.</li>
129</ul>
130
131</li>
132<li>
133Congratulations! You just wrote your first TTS-enabled Android app! Please <a href="http://eyes-free.googlecode.com/svn/trunk/documentation/tts/index.html">see the documentation on the TTS</a> and <a href="http://eyes-free.googlecode.com/svn/trunk/">look at other apps in the eyes-free project</a> to learn more about how to use the TTS.
134</li>
135</ol>
136Notes:
137<ul>
138<li>
139The TTS constructor takes 3 parameters: the application Context, the TTS.InitListener to call upon successful initialization of the TTS, and whether or not to show a message prompting the user to install the TTS from the Market if they have not done so already.
140</li>
141<li>
142The speak call takes 3 parameters: the String of text to be spoken, an int that indicates the queuing strategy (0 for no queuing, 1 for fifo queuing), and an array of Strings that are parameters for how to speak the text.
143</li>
144<li>
145The first time you run an app that uses the TTS, if you do not already have the necessary voice data files on your SD card, they will be downloaded automatically.
146</li>
147</ul>
148
149
150<h2>5 Tips and Tricks on Using the TTS in Your App</h2>
151<p>
152<a href="http://eyes-free.googlecode.com/svn/trunk/documentation/tutorial/usage_notes.html">
153For some tips and tricks on using the TTS in your app, please see the usage notes here.</a>
154</p>
155
156
157<p class="author"> Author: Charles L. Chen
158<a href="mailto:clchen@google.com">&lt;clchen@google.com&gt;</a>
159</p>
160<p class="date"> Date: 2008/12/12 10:20:46</p>
161</body>
162</html>