WEB开发网
开发学院手机开发Android 开发 Android TTS 应用 阅读

Android TTS 应用

 2010-03-24 03:48:00 来源:WEB开发网   
核心提示:most users will be on the Market version of the TTS and not the release candidate.Start Eclipse. Go to "File" > "New Project" > "
most users will be on the Market version of the TTS and not the release candidate.

Start Eclipse. Go to "File" > "New Project" > "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".

Select your project in the "Package Explorer", then go to "Project" > "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.

You should see two Java files in your project: HelloWorldTTS.java and R.java. Open HelloWorldTTS.java and do the following: -In the imports section at the top of the file, add this line:

import com.google.tts.TTS;

-After the line "public class HelloWorldTTS extends Activity {", add this line:

private TTS myTts;

-Add the following as the last line of the onCreate method:

myTts = new TTS(this, ttsInitListener, true);

-After the onCreate method, add these lines:

Java代码

private TTS.InitListener ttsInitListener = new TTS.InitListener() {

public void onInit(int version) {

myTts.speak("Hello world", 0, null);

}

};

private TTS.InitListener ttsInitListener = new TTS.InitListener() {

public void onInit(int version) {

myTts.speak("Hello world", 0, null);

}

};

Now you should have a HelloWorldTTS.java that looks something like this.

Build 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.

If you do not have the TTS library installed on the phone, you will be

Tags:Android TTS 应用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接