如何在我的应用程序中实现Google语音输入? [英] How Can I Implement Google Voice Typing In My Application?

查看:79
本文介绍了如何在我的应用程序中实现Google语音输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在应用程序中添加一个按钮,以启动Google语音输入(或默认的语音识别).我已经尝试过本教程.本教程令我感到困惑.我导入了.jar,并向清单中添加了必要的权限,服务和活动.但我似乎无法弄清楚如何将所有内容放在一起".我想知道:

I am trying to add a button in my application that starts Google Voice Typing (or the default speech recognition). I have tried following this tutorial. This tutorial is incredibly confusing to me. I imported the .jar, and added the necessary permissions, services, and activities to my Manifest. But I can't seem to figure out how to "put it all together". I'm wondering:

  1. 我应该从我的主活动中单击按钮来调用inputMethodService吗?还是我的inputMethodService本质上成为我的主要活动?
  2. IME是什么意思?我尝试使用Google,但是它给我的定义对我的理解没有帮助.
  3. 当我尝试将整个DemoInputMethodService代码复制并粘贴到当前活动中时,出现错误消息,提示我无法在此活动中扩展InputMethodService.(这又引出了一个问题.)

我该如何使用它?

推荐答案

如果要遵循所提到的教程,则需要首先实现IME(输入法编辑器),请参见

If you want to follow the tutorial that you mention then you need to implement an IME (input method editor) first, see http://developer.android.com/guide/topics/text/creating-input-method.html

此IME可以具有常规的键盘外观或仅包含一个麦克风按钮.

This IME can have a regular keyboard look-and-feel or contain just a microphone button.

您的应用程序用户首先必须单击文本字段以启动IME.(请注意,设备上可能安装了多个IME,并且必须在设置"中明确启用它们.)然后,用户必须单击麦克风按钮以触发语音识别.

The user of your app will first have to click on a text field to launch the IME. (Note that there can be several IMEs installed on the device and they have to be explicitly enabled in the Settings.) Then the user will have to click on the microphone button to trigger the speech recognition.

本教程提供了一个jar,可让您直接调用Google的识别器.如果您改为通过SpeechRecognizer-interface( http://developer.android.com/reference/android/speech/SpeechRecognizer.html ),这样用户就可以决定是使用Google还是其他产品.

The tutorial provides a jar that lets you directly call Google's recognizer. It would be nicer if instead you called the recognizer via the SpeechRecognizer-interface (http://developer.android.com/reference/android/speech/SpeechRecognizer.html), this way the user can decide whether to use Google's or something else.

SpeechRecognizer 提供了一个侦听器,该侦听器支持方法

The SpeechRecognizer is given a listener which supports the method onPartialResults, which allows you to monitor the recognition hypotheses while the user is speaking. It's up to you how you display them. Note however that the specification of SpeechRecognizer does not promise that this method gets called. This depends on the implementation of the recognizer service. Regarding Google's implementation: what it supports keeps changing unannounced, it does not have a public API nor even release notes.

您也许可以重用我的项目Kõnele( http://kaljurand.github.io/K6nele/about/),其中包含 SpeechRecognizer 的两个实现以及使用它们的IME.其中一种实现方式是使用Kaldi GStreamer服务器( https://github.com/alumae/kaldi-gstreamer-server ).您将需要设置自己的服务器实例,以将其移植到要识别的语言(除非您要使用Kõnele默认使用的爱沙尼亚服务器).

You might be able to reuse my project Kõnele (http://kaljurand.github.io/K6nele/about/), which contains two implementations of SpeechRecognizer and an IME that uses them. One of the implementations offers continuous recognition of arbitrarily long audio input, using the Kaldi GStreamer server (https://github.com/alumae/kaldi-gstreamer-server). You would need to set up your own instance of the server porting it to the language that you want to recognize (unless you want to use the Estonian server that Kõnele uses by default).

这篇关于如何在我的应用程序中实现Google语音输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆