android wear那些事--添加语音功能
来源:互联网 发布:app软件用什么编程 编辑:程序博客网 时间:2024/06/05 07:53
Adding Voice Capabilities
语音操作对于穿戴式应用的体验非常重要.可以让使用者不用手就可以快速的操作.wear提供了两种类型的语音操作:
1.系统提供的
这类语音操作依赖系统平台.当语音操作的时候你可以通过过滤来启动你想启动的页面.比如:记笔记或者设置闹钟.
2.应用提供的
这类语音操作依赖于你的应用,你可以像声明一个启动图标一样声明它们.用户说`Start`去使用语音操作启动你想启动的activity.
声明系统提供的语音操作
android wear 平台系统本身提供了一些语音操作比如Take a note
,Set an alarm
.这样用户说出他们希望做的事情系统会进行辨别相应的activity去启动.
当用户说语音操作时,你的应用可以过滤你想启动页面的意图.如果你想启动一个服务在后台做一些事情,应该先显示一个页面然后在这个页面中启动服务.当你想退出这个页面的时候记得调用finish()方法.
举个列子,将Take a note
命令声明在MyNoteActivity
页面中.
<activity android:name="MyNoteActivity"> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="com.google.android.voicesearch.SELF_NOTE" /> </intent-filter> </activity>
下面是Wear平台支持的一些系统语音操作列表.
声明应用提供的语音操作
如果系统提供的语音操作没有适合你的,你可以声明自己的语音操作.
注册一个启动操作和在手机上注册一个启动图标一样.此时你的应用会启动语音操作而不是启动应用.
要指定Start
之后说出的文本需要为你想启动的activity指定一个label
属性.例如,意图过滤器识别Start MyRunningApp
语音操作并启动StartRunActivity
.
<application> <activity android:name="StartRunActivity" android:label="MyRunningApp"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity></application>
获取自由形式的语音输入
除了使用语音操作去启动activity,你也可以调用系统内置的语音识别器获取用户的语音输入.这获取用户的输入是非常有用的,比如搜索或者发信息.
在你的应用中可以调用startActivityForResult()设置ACTION_RECOGNIZE_SPEECH.启动识别语音的页面,你就可以在onActivityResult()这个方法里处理结果.
private static final int SPEECH_REQUEST_CODE = 0;// Create an intent that can start the Speech Recognizer activityprivate void displaySpeechRecognizer() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);// Start the activity, the intent will be populated with the speech text startActivityForResult(intent, SPEECH_REQUEST_CODE);}// This callback is invoked when the Speech Recognizer returns.// This is where you process the intent and extract the speech text from the intent.@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) { List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); // Do something with spokenText } super.onActivityResult(requestCode, resultCode, data);}
- android wear那些事--添加语音功能
- <等待翻译>Android Wear 进阶 2.4 Adding Voice Capabilities 添加语音功能
- android wear那些事--创建自定义布局
- android wear那些事--通过蓝牙调试
- #android wear那些事--使你的应用可见
- android wear那些事--打包穿戴式应用
- 添加语音播报功能
- 国行的Moto 360 语音口令 ,Android Wear 的口令,语音命令,语音控制
- android集成语音功能
- Android添加语音交互
- Android Wear
- 【Android Wear】
- Android Wear开发-----为watchface添加设置界面
- Android Wear Preview- 从通知上接收语音输入(Receiving Voice Input from a Notification)
- Android Wear 在可穿戴设备中使用语音进行交互
- Android Wear开发之录一段可以被百度媒体云识别的语音文件
- 在WinForm上添加语音朗读功能
- 树莓派添加中文语音合成功能
- LinearLayout和RelativeLayout绘制过程的对比
- 二级缓存和QBC查询
- 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- Mini-Notes: LaTex的相关工具和文档
- Android Service完全解析,关于服务你所需知道的一切(下)
- android wear那些事--添加语音功能
- 不可能的出栈序列--思想
- 机智云支持的wifi模组,Gagent模组
- TopCoder SRM 701 div1. 900 FibonacciStringSum - 矩阵乘法
- Android产品研发(十三)-->App轮询操作
- HTTP协议详解
- eclipse优化
- 随记
- 函数指针