我們有一個運行語音識別作爲服務的演示Android應用程序(Android 4.0.3),並且(連續地)在視圖上記錄識別結果。是否可以在Google Glass上安裝Android語音識別(作爲自定義服務)?
在我們的智能手機中,一切正常。
我們想在谷歌眼鏡浸泡應用程序複製這種情況下,但是,當我們嘗試啓動該服務,我們總是有這樣的錯誤消息:
沒有選擇的語音識別服務
是否有一些已知的限制?或者有人想出瞭如何解決這類問題?提前
由於這是活動的一些顯著代碼:
public class MainActivity extends Activity implements Observer {
...
@Override
protected void onStart() {
super.onStart();
//Toast.makeText(this, "Hi guys", Toast.LENGTH_LONG);
startService(new Intent(this, SilentVoiceRecognitionService.class));
}
...
}
這是服務的代碼:
public class SilentVoiceRecognitionService extends Service {
protected AudioManager mAudioManager;
protected SpeechRecognizer mSpeechRecognizer;
protected Intent mSpeechRecognizerIntent;
protected final Messenger mServerMessenger = new Messenger(new IncomingHandler(this));
private Model model = Model.getInstance();
static final String TAG = "SilentRecognizer";
static final int MSG_RECOGNIZER_START_LISTENING = 1;
static final int MSG_RECOGNIZER_CANCEL = 2;
protected boolean mIsListening;
@Override
public void onCreate()
{
super.onCreate();
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());
mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("LocalService", "Received start id " + startId + ": " + intent);
// We want this service to continue running until it is explicitly
// stopped, so return sticky.
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
return START_STICKY;
}
@Override
public void onDestroy()
{
super.onDestroy();
if (mSpeechRecognizer != null)
{
mSpeechRecognizer.destroy();
}
}
protected class SpeechRecognitionListener implements RecognitionListener
{
...
}
protected static class IncomingHandler extends Handler
{
private WeakReference<SilentVoiceRecognitionService> mtarget;
IncomingHandler(SilentVoiceRecognitionService target)
{
mtarget = new WeakReference<SilentVoiceRecognitionService>(target);
}
@Override
public void handleMessage(Message msg)
{
final SilentVoiceRecognitionService target = mtarget.get();
switch (msg.what)
{
case MSG_RECOGNIZER_START_LISTENING:
if (!target.mIsListening)
{
target.mSpeechRecognizer.startListening(target.mSpeechRecognizerIntent);
target.mIsListening = true;
//Log.d(TAG, "message start listening"); //$NON-NLS-1$
}
break;
case MSG_RECOGNIZER_CANCEL:
target.mSpeechRecognizer.cancel();
target.mIsListening = false;
//Log.d(TAG, "message canceled recognizer"); //$NON-NLS-1$
break;
}
}
}
}
您是否在應用程序的清單中添加了用戶權限標記? –
確定:<使用權限android:name =「android.permission.RECORD_AUDIO」/> –
此外,現在是否有可能擁有一副眼鏡?好的,忘記了。我認爲語音識別在GG中的工作方式有點不同。請參閱[這裏](https://developers.google.com/glass/develop/gdk/input/voice)。 –