是否可以在Google Glass上安装Android语音识别功能(作为自定义服务)?

 黑漆高傲的眼眸 发布于 2023-02-11 18:45

我们有一个演示Android应用程序(Android 4.0.3),它将语音识别作为服务运行,并且(连续地)在视图上记录识别结果.

我们的智能手机一切正常.

我们希望在Google Glass沉浸式应用程序中复制此方案,但是当我们尝试启动服务时,我们始终会收到此错误消息:

没有选定的语音识别服务

有一些已知的限制吗?或者有人想出如何解决这类问题?

提前致谢

这是活动的一些重要代码:

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 mtarget;

       IncomingHandler(SilentVoiceRecognitionService target)
       {
           mtarget = new WeakReference(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;
            }
      } 
   }

}

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有