1. android读取英文,是非常简单的,接口为TextToSpeech.OnInitListener,  
  2.   OnClickListener ,实现方法便行。  
  3.  
  4. package com.smart;  
  5.  
  6. import java.util.Locale;  
  7.  
  8. import android.app.Activity;  
  9. import android.content.ComponentName;  
  10. import android.content.Intent;  
  11. import android.os.Bundle;  
  12. import android.speech.tts.TextToSpeech;  
  13. import android.view.View;  
  14. import android.view.View.OnClickListener;  
  15. import android.widget.Button;  
  16. import android.widget.TextView;  
  17. import android.widget.Toast;  
  18.  
  19. public class ReadText extends Activity implements TextToSpeech.OnInitListener,  
  20.   OnClickListener {  
  21.  private TextToSpeech tts;  
  22.  private TextView textView;  
  23.  private Button return_back;  
  24.  private Button button;  
  25.  
  26.  @Override 
  27.  public void onCreate(Bundle savedInstanceState) {  
  28.   super.onCreate(savedInstanceState);  
  29.   setContentView(R.layout.read);  
  30.   tts = new TextToSpeech(thisthis);  
  31.   button = (Button) findViewById(R.id.button);  
  32.   textView = (TextView) findViewById(R.id.textView);  
  33.   button.setOnClickListener(this);  
  34.   return_back = (Button) findViewById(R.id.back);  
  35.  
  36.   return_back.setOnClickListener(new OnClickListener() {  
  37.      
  38.    @Override 
  39.    public void onClick(View v) {  
  40.     Intent intent=new Intent();  
  41. //    intent.setClass(ReadText.this,Main.class);  
  42.     intent.setComponent(new ComponentName(ReadText.this,Main.class));  
  43.    }  
  44.   });  
  45.  
  46.  }  
  47.  //实例化  
  48.  @Override 
  49.  public void onInit(int status) {  
  50.   if (status == TextToSpeech.SUCCESS) {  
  51.    int result = tts.setLanguage(Locale.US);  
  52.    if (result == TextToSpeech.LANG_NOT_SUPPORTED  
  53.      || result == TextToSpeech.LANG_MISSING_DATA) {  
  54.     Toast.makeText(this"Language is not available.",  
  55.       Toast.LENGTH_LONG).show();  
  56.    }  
  57.   }  
  58.  }  
  59.  
  60.  @Override 
  61.  public void onClick(View v) {  
  62.   //得到内容,然后进行读取  
  63.   tts.speak(textView.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);  
  64.     
  65.     
  66.  
  67.  }  
  68.  
  69. }  
  70. <?xml version="1.0" encoding="utf-8"?>  
  71.   xmlns:android="http://schemas.android.com/apk/res/android" 
  72.   android:orientation="vertical" 
  73.   android:layout_width="fill_parent" 
  74.   android:layout_height="fill_parent">  
  75.     
  76.     
  77.     
  78.     
  79.   
  80.   android:id="@+id/button" 
  81.   android:layout_width="fill_parent" 
  82.   android:layout_height="wrap_content" 
  83.   android:text="读取内容" 
  84.   />  
  85.       
  86.   
  87.   android:id="@+id/back" 
  88.   android:layout_width="fill_parent" 
  89.   android:layout_height="wrap_content" 
  90.   android:text="返回" 
  91.   />  
  92.     
  93.   
  94.   android:id="@+id/textView" 
  95.     android:layout_width="fill_parent" 
  96.   android:layout_height="fill_parent" 
  97.   android:text="@string/text" 
  98.     
  99.   />  
  100.  
  101.  
  102.  

 

更多相关文章

  1. Android(安卓)Notification的使用
  2. Android学习札记29:对线程更新UI界面的一些理解(2)
  3. Android下使用Properties文件保存程序设置
  4. Android中读取短信信息
  5. Android读写文件源码
  6. android用sharepreference保存输入框中的内容
  7. Android(安卓)OneDayOneExample-2. 读取电话本
  8. Android验证码读取
  9. Android读取手机短信

随机推荐

  1. Android平台上的计算器APP(付源码)
  2. Android如何发邮件?
  3. 关于android内核移植到YLP2440开发板
  4. 【Android(安卓)系统开发】 编译 Android
  5. Android(安卓)ANR
  6. 第一讲:Android开发环境的搭建
  7. Android实现微信分享及注意事项
  8. android 杀掉进程
  9. Android(安卓)AudioRecord介绍与Android(
  10. listview常用属性记录