Android有一个非常酷的功能,仍然有很多开发人员不知道。像Any.DO应用程序使用语音到文本的转换功能相当创造性。在当今世界上的Siri语音命令是非常重要的。Android的原生提供的语音到文本的功能,那么,为什么不把它用在我们的应用程序!
我会告诉你如何使用Android的语音到文本API在应用程序中。
让我们把我们的演示应用程序。
演示程序
应用程序将非常简单。这将有一个带麦克风符号的按钮。点击其中我们触发Android的语音到文本的意向,显示一个对话框,语音输入。的语音输入,然后转换成文本。在文本视图中的文本,然后显示。
第1步:在Eclipse中建立基本的Android项目
创建一个Hello World,Android的Eclipse项目中。转到“新建”>“项目> Android项目。为项目作为SpeechToTextDemo和选择Android运行时2.1 SDK 7 名。我已经给包名net.viralpatel.android.speechtotextdemo
。
一旦你完成了上述步骤,你将有一个基本的Hello World Android应用程序。
第2步:改变布局
在我们的演示,我们需要简单的布局。只有一个图像按钮来触发语音到文本的API和一个TextView的显示结果从语音文本转换。
开放式布局/在你的Android项目的main.xml中,替换现有的内容与以下:
文件:RES /布局/ main.xml中
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
xmlns:tools
=
"http://schemas.android.com/tools"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:layout_above
=
"@+id/textView1"
android:layout_toLeftOf
=
"@+id/textView1"
android:gravity
=
"center"
android:orientation
=
"vertical"
>
<
ImageButton
android:id
=
"@+id/btnSpeak"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:layout_margin
=
"10dp"
|