Android进阶:Google自带语音播放功能实现


在Android 中使用语音播放功能 只需要使用类 TextToSpeech ,该类实现了很多关于语音的功能,使用该类必须为其设置语言,现在支持五种语言,杯具的是不支持中文

实现很简单 不过首先要安装语言包 这个在设置--》语音输入和输出设置--》文字转语音设置

如下图

左边图中 安装语音数据  我这里已经安装成功了 所以是灰色的 如果没有安装这里就可以点 其他地方都是灰色的

安装文件4.28M  下载安装完成后就可以选择语言了 右图所示的五种语言 没有中文啊

下面来看实现 很简单

首先是layout文件:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <EditText    
  8.     android:id="@+id/EditText01"  
  9.     android:layout_width="fill_parent"   
  10.     android:text="I hope so, because it's time to wake up."  
  11.     android:layout_height="wrap_content"   
  12.     />  
  13. <Button    
  14.     android:id="@+id/Button01"  
  15.     android:text="开始播放"  
  16.     android:layout_width="fill_parent"   
  17.     android:layout_height="wrap_content"   
  18.     />  
  19. </LinearLayout>  
  • 1
  • 2
  • 下一页

相关内容