目录

电视语音识别对接

ASR会话接口(AIDL)

桌面控制电视(IAsrApi)
  // IAsrApi.aidl
  package com.morequick.asr;
  
  import com.morequick.asr.IAsrListener;
  
  interface IAsr {
  
      /**
       * 开启语音会话功能
       */
      void startAsr();
  
      /**
       * 关闭语音会话功能
       */
      void closeAsr();
  
      /**
       * 语音会话是否开启
       */
      boolean isStartAsr();
  
      /**
       * 设置唤醒词
       */
      void setCustomWakeUpWord(String wakeUpWord);
  
      /**
       * 设置回调监听
       */
      void registerAsrListener(IAsrListener iAsrListener);
  
      /**
       * 取消回调监听
       */
      void unRegisterAsrListener();
  }
电视回调桌面(IAsrApiListener)
  // IAsrApiListener.aidl
  package com.morequick.asr;
  
  // Declare any non-default types here with import statements
  
  interface IAsrListener {
  
      /**
       * 语音识别文字开始
       * startType:
       * 1 纯文本(START_TYPE_PLAIN_TEXT)
       * 2 近场语音(START_TYPE_NEAR_FIELD)
       * 3 远场场语音(START_TYPE_FAR_FIELD)
       */
      void sessionStart(int startType);
  
      /**
       * 识别到唤醒词
       * info: 唤醒词
       */
      void wakeupInfo(String info);
  
      /**
       * 识别中
       * text: 识别中的文字,识别中增加纠错
       * '我'
       * '我要'
       * '我要看'
       * '我要看中央'
       * '我要看中央三台'
       * isEnd: 是否结束,识别完成为true,识别中文false
       */
      void textFlow(String text, boolean isEnd);
  
      /**
       * 语音识别文字结束
       * endType:
       * 0 正常结束(END_TYPE_NORMAL)
       * 1 取消会话(END_TYPE_CANCEL)
       * 2 发生错误(END_TYPE_ERROR)
       * 3 短暂会话无文字(END_TYPE_SHORT_CLICK)
       * 4 其他(END_TYPE_OTHER)
       * endMessage: 识别文字的结果
       */
      void sessionEnd(int endType, String endMessage);
  }

电视端提供service

代码示例
  package com.morequick.asr;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.os.RemoteException;
  
  import androidx.annotation.Nullable;
  
  public class AsrService extends Service {
  
  
      @Nullable
      @Override
      public IBinder onBind(Intent intent) {
          return new IAsr.Stub(){
  
              @Override
              public void startAsr() throws RemoteException {
  
              }
  
              @Override
              public void closeAsr() throws RemoteException {
  
              }
  
              @Override
              public boolean isStartAsr() throws RemoteException {
                  return false;
              }
  
              @Override
              public void setCustomWakeUpWord(String wakeUpWord) throws RemoteException {
  
              }
  
              @Override
              public void registerAsrListener(IAsrListener iAsrListener) throws RemoteException {
  
              }
  
              @Override
              public void unRegisterAsrListener() throws RemoteException {
  
              }
          };
      }
  }
AndroidManifest.xml示例
      <service
          android:name=".AsrService"
          android:enabled="true"
          android:exported="true">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <action android:name="com.morequick.asr.action" />
          </intent-filter>
      </service>

桌面绑定service

  Intent intent = new Intent("com.morequick.asr.action");
  intent.setPackage("com.morequick.asr");
  boolean result = bindService(intent, ServiceConnection, Context.BIND_AUTO_CREATE);