`

Android TTS应用(转)

阅读更多
1 Introduction
The 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.

The 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 eSpeak engine is available.

2 Requirements
Using 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.

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

3 Setting Up an Eclipse Project That Uses the TTS
Setup an Android project as you would normally.
Go to Project > Properties > Java Build Path > Libraries and click on "Add External JARs..." Then add in the TTS_library_stub.jar file.
Start coding!
4 A Step-By-Step Tutorial To Get You Started
This tutorial will take you step-by-step through writing a simple Hello World application. It assumes that you have Eclipse setup to work with the Android SDK already.

Get the TTS_library_stub.jar file from the downloads area. 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.
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:
   
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 prompted to install it.
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.
Congratulations! You just wrote your first TTS-enabled Android app! Please see the documentation on the TTS and look at other apps in the eyes-free project to learn more about how to use the TTS.
Notes:

The 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.
The 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.
The 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.
5 Tips and Tricks on Using the TTS in Your App
For some tips and tricks on using the TTS in your app, please see the usage notes here.http://eyes-free.googlecode.com/svn/trunk/documentation/tutorial/usage_notes.html

转自http://eyes-free.googlecode.com/svn/trunk/documentation/tutorial/tutorial.html
分享到:
评论

相关推荐

    AndroidTTS文本转语音

    Android TTS(Text-to-Speech)是Android操作系统中的一项服务,允许应用程序将文本转换成语音输出,用户无需手动输入即可听取设备读出的文字内容。这个技术对于视力障碍者、学习新语言的人或者在驾驶等不便看屏幕的...

    Android TTS 文字转语音实例

    本实例将详细介绍如何在Android应用中实现一个简单的TTS文字转语音的功能。 首先,我们需要在AndroidManifest.xml文件中添加必要的权限,用于访问TTS服务: ```xml <uses-permission android:name="android....

    Android-tts.rar_android_android TTS_tts_tts Android_语音 tts

    Android TTS(Text-to-Speech)系统是Android操作系统中的一个重要组成部分,它允许应用程序将文本转换为可听见的语音输出,从而实现文字的语音合成。在Android应用开发中,TTS功能广泛应用于各种场景,如阅读电子书...

    android TTS语音引擎包

    总的来说,这个“android TTS语音引擎包”为Android开发者提供了丰富的选择,以适应各种应用场景,无论是教育应用、导航应用还是阅读应用,都可以利用这些引擎实现自然、流畅的语音输出。通过合理选择和集成,开发者...

    Android-一个基于Java的粤语发音TTS文字转语音.

    本项目"Android-一个基于Java的粤语发音TTS文字转语音"显然旨在提供这样的功能,它可能包含了一个自定义的TTS引擎或者接口,以便在Android应用中集成粤语的语音合成。 在Android开发中,TTS服务是通过Android SDK...

    Android TTs 文本转语音朗读源码

    Android的文本转语音(Text-to-Speech,简称TTS)技术是一种将文本数据转换为可听见的语音输出的系统,广泛应用于各种应用中,如阅读器、导航、语音助手等。在Android Studio环境下,开发者可以方便地利用Android...

    android tts 中文转语音

    Android TTS(Text-to-Speech)是Android系统提供的一个服务,允许应用程序将文本转换为语音输出。这个功能在很多场景下都非常有用,比如辅助阅读、导航提示或者为视力障碍者提供帮助。在Android平台上实现中文转...

    Android TTS 支持中文

    Android TTS(Text-to-Speech)是Android系统提供的一个核心功能,它允许应用程序将文本转换为语音输出。这个功能在很多场景下非常有用,比如帮助视力障碍用户阅读屏幕上的文字,或者在驾驶时提供导航指引。本文将...

    Android_tts项目源码 demo

    Android TTS(Text-to-Speech)是Android系统中用于将文本转换为语音输出的功能,它允许应用程序以语音的形式朗读出屏幕上的文字。这个“Android_tts项目源码 demo”显然是一个示例项目,用于展示如何在Android应用...

    Android TTS实现简单阅读器

    在Android平台上,文本转语音(Text-to-Speech, 简称TTS)技术是一种将文字信息转化为可听见的语音输出的重要功能。Android TTS实现简单阅读器是开发者利用此技术构建的一个应用示例,旨在帮助用户理解如何在Android...

    android TTS jar

    总之,Android TTS jar和TTS_library_stub_3.0_market jar是针对Android系统TTS功能的增强解决方案,它们解决了原生TTS在中文支持上的不足,提供了更稳定、兼容性更强的文本转语音服务。开发者可以利用这些资源创建...

    android studio tts 离线中文语音播放

    在Android开发中,Text-to-Speech (TTS) 技术是将文本转换为语音输出的重要功能,尤其适用于辅助视力障碍者或者在驾驶等不便查看屏幕的场景。本主题聚焦于如何在Android Studio中实现离线中文语音播放,支持男声和...

    android中文语音tts

    在Android平台上,TTS系统是为开发者提供的一种服务,它允许应用程序将文字转换成自然语言的语音,使得用户无需查看屏幕也能获取信息,这对于视觉障碍者或者在驾驶、做家务等不便看屏幕的场景下尤其有用。...

    tts.rar_TTS java_android TTS_google GetSampleText_tts android_中

    标题中的“tts.rar_TTS java_android TTS_google GetSampleText_tts android_中”表明这是一个关于Android平台上的文本转语音(Text-to-Speech,简称TTS)技术的压缩包,涉及Java编程语言,可能包含了Google的TTS...

    TTS.zip_android_surface5nn_离线TTS_科大讯飞 Android TTS

    科大讯飞作为国内领先的语音技术提供商,其在Android平台上的离线TTS解决方案——"TTS.zip_android_surface5nn",为开发者提供了高效、高质量的文本转语音服务,无需依赖网络连接即可实现流畅的语音合成。...

    Google TTS中文语言包,Android原生TTS服务

    某些场景下,部分安卓设备并没有自带安装Google TTS服务,若是从商店下载应用后,需要翻墙下载语言包,为了跨过这个翻墙的闹心事,通过两天的收集,现将已收集到的中文语言包分享给大家,其中也有其他语种的,可自行...

    android tts示例

    Android TTS(Text-to-Speech)是Android系统提供的一个服务,允许应用程序将文本转换为语音输出,从而实现让设备“朗读”文本的功能。在Android应用开发中,TTS技术常用于帮助视障用户或者在驾驶、烹饪等不便查看...

    基于android的TTs

    在Android平台上,Text-to-Speech(TTS)技术是一种将文本转换为语音输出的功能,它使得应用程序能够“读出”屏幕上的文字,这对于视力障碍的用户或者在不方便阅读时非常有用。本项目“基于Android的TTs”显然是一个...

    android 文字转语音 tts 实现 支持中文

    在Android平台上,实现“文字转语音”(Text-to-Speech, TTS)功能是一项常见的需求,尤其对于有读屏需求的用户或者希望增加互动性的应用来说。本篇将详细讲解如何在Android应用中实现文字转语音功能,特别关注对...

    delphi_xe5_android_tts(Text_To_Speech).ZIP

    综上所述,这个项目展示了如何在Delphi XE5环境中利用Android的TTS服务,为Android应用程序添加文本转语音的功能。通过阅读和分析`Unit1.pas`和`Unit1.fmx`,我们可以深入了解具体的实现细节,如事件处理、TTS引擎的...

Global site tag (gtag.js) - Google Analytics