Go to file
yangxisong 22ff4384ca feat: 初始化 SDK 2025-11-10 17:20:15 +08:00
app feat: 初始化 SDK 2025-11-10 17:20:15 +08:00
gradle Initial commit 2025-11-07 18:20:15 +08:00
.gitignore Initial commit 2025-11-07 15:36:29 +08:00
README.md Initial commit 2025-11-07 18:20:15 +08:00
build.gradle.kts Initial commit 2025-11-07 18:20:15 +08:00
gradle.properties Initial commit 2025-11-07 18:20:15 +08:00
gradlew Initial commit 2025-11-07 18:20:15 +08:00
gradlew.bat Initial commit 2025-11-07 18:20:15 +08:00
settings.gradle.kts Initial commit 2025-11-07 18:20:15 +08:00

README.md

Rokid

准备工作

配置文件

配置文件 init.jsonJSON 格式存储,通过 Key-Value 配置系统功能。

示例:

{
  "launchPackageName":"com.rokid.sample",
  "wifiSsid":"<wifi名称>",
  "wifiPwd":"<wifi密码>"
}

通过 adb push 至目录 /sdcard/init.json

调试连接

adb shell setprop persist.vendor.adb 1

Glasses行业版SDK

0.背景

  • 该插件仅适用于Glasses行业版OS。

1.开发接入

1.1配置

  1. 导入 sprite_dcg_sdk.aar

1.系统服务

行业版SDK提供服务列表

  • 语音指令服务 IInstructService,应用可监听系统固定语音指令
  • 离线TTS服务 ITTSService
  • 系统功能服务 ISystemFuncService 提供系统设置功能
  • 媒体服务 ISpriteMediaService,提供拍照、录像等功能

1.1 异步获取服务

  • 异步获取语音指令服务ServiceManager.getInstructService(Context context, IGetServiceCallback callback)
  • 异步获取TTS服务ServiceManager.getTTSService(Context context, IGetServiceCallback callback)
  • 异步获取系统功能服务ServiceManager.getSystemFuncService(Context context, IGetServiceCallback callback)
  • 异步获取媒体服务ServiceManager.getSpriteMediaService(Context context, IGetServiceCallback callback)

调用异步接口时如果服务没有bind会自动bind

  ServiceManager.getTTSService(this) {
    it.playTtsMsg("让每个人享受科技Leave Nobody Behind!")
  }

1.1 同步获取服务

  • bind 服务ServiceManager.
  • 同步获取服务ServiceManager.getService(Class serviceClass)

调用同步接口时必须提前bind如果服务没有bind或者bind还没完成时将返回 null

  ServiceManager.getService(ITTSService::class.java)?.playTtsMsg("让每个人享受科技Leave Nobody Behind!")

2. 语音指令服务 IInstructService

2.1 可用语音指令

const int INSTRUCT_WAKEUP = 1; // 若琪、乐琪
const int INSTRUCT_VOLUME_UP = 2; // 声音大一点
const int INSTRUCT_VOLUME_DOWN = 3; // 声音小一点
const int INSTRUCT_LIGHT_UP = 4; // 亮一点
const int INSTRUCT_LIGHT_DOWN = 5; // 暗一点
const int INSTRUCT_TAKE_PHOTO = 6; // 拍照
const int INSTRUCT_START_AUDIO_RECORD = 7; // 录音
const int INSTRUCT_STOP_AUDIO_RECORD = 8; // 结束录音
const int INSTRUCT_START_VIDEO_RECORD = 9; // 录像
const int INSTRUCT_STOP_VIDEO_RECORD = 10; // 结束录像
const int INSTRUCT_QUIT = 11; // 退出

2.2 注册/反注册语音指令监听

interface IInstructListener {
    void onInstructReceived(int instruct);
}

void registerListener(IInstructListener listener);
void unregisterListener(IInstructListener listener);

例如:

private val mInstructListener = object : IInstructListener.Stub() {  // 因为通过binder调用服务这里必须是Stub对象
    override fun onInstructReceived(instruct: Int) {
      Log.d("Instruct", "on receive instruct: $instruct")
      // 注意: 服务的回调都不在主线程如果要操作UI请自己切换到主线程
      // textView.text = "收到语音指令: $instruct"
    }
}
      
override fun onResume() {
    super.onResume()
    ServiceManager.getInstructService(this) { it.registerListener(mInstructListener) }
}

override fun onPause() {
    super.onPause()
    ServiceManager.getInstructService(this) { it.unregisterListener(mInstructListener) }
}

3. TTS服务 ITTSService

3.1 播放TTS

void playTtsMsg(String ttsMsg);

4. 系统基础功能服务 ISystemFuncService

4.1 获取/设置系统音量,音量值范围 [0, 15]

int getVolumeSpecified();
void setVolumeSpecified(int value);

4.2 获取/设置屏幕亮度,亮度值范围 [0, 15]

int getBrightnessSpecified();
void setBrightnessSpecified(int value);

4.3 获取设备序列号

String getSn();

4.4 获取/设置自动休眠时间(单位:毫秒)

long getScreenAutoSleepTime();
void setScreenAutoSleepTime(long ms);

4.5 唤醒设备

void wakeUp();

4.6 设备休眠

void goToSleep();

4.7 设备重启

void reboot();

4.8 设备关机

void shutdown();

5. 多媒体服务 ISpriteMediaService

5.1 多媒体Listener

interface ISpriteMediaListener {
    void onTakePicture(int errorCode, String path); // 拍照回调
    void onVideoRecord(int errorCode, String path); // 录像回调
    void onAudioRecord(int errorCode, String path); // 录音回调
}

// 错误码
interface ISpriteMediaService {
    const int ERROR_NONE = 0;
    const int ERROR_CAMERA_EXCEPTION = 1;
    const int ERROR_P_SENSOR_NEAR = 2;
}

5.2 设置监听

void setMediaListener(ISpriteMediaListener listener);

5.3 设置拍照分辨率

void setPictureSize(int width, int height);
/* 可用分辨率
[4032x3024, 4000x3000, 4032x2268, 3264x2448, 3200x2400, 2268x3024, 2876x2156, 2688x2016, 2582x1936, 2400x1800, 1800x2400, 2560x1440, 2400x1350, 2048x1536, 2016x1512, 1920x1080, 1600x1200, 1440x1080, 1280x720, 720x1280, 1024x768, 800x600, 648x648, 854x480, 800x480, 640x480, 480x640, 352x288, 320x240, 320x180, 176x144]
*/

5.4 设置录像分辨率

void setVideoSize(int width, int height);

5.5 拍照结果通过Lisener获取

void takePicture();

5.6 录像结果通过Lisener获取

void startVideoRecord();  // 开始录像
void stopVideoRecord();   // 停止录像
boolean isVideoRecording(); // 是否正在录像

5.7 录音结果通过Lisener获取

void startAudioRecord();
void stopAudioRecord();
boolean isAudioRecording();

6. 自定义按键

6.1 触控板标准按键

标准按键可通过onKeyDown、onKeyUp监听。可用键值如下

  • 点击KeyEvent.KEYCODE_ENTER
  • 前滑KeyEvent.KEYCODE_DPAD_DOWN、KeyEvent.KEYCODE_DPAD_RIGHT
  • 后滑KeyEvent.KEYCODE_DPAD_UP、KeyEvent.KEYCODE_DPAD_LEFT
  • 双击KeyEvent.KEYCODE_BACK

6.2 特殊按键

特殊按键需通过广播注册监听,可监听事件:

  • 长按触摸板SysKeyAction.TOUCH_BAR_LONG_PRESS
  • 点击拍照键SysKeyAction.SPRITE_BUTTON_CLICK
  • 按下/弹起拍照键SysKeyAction.SPRITE_BUTTON_DOWN、SysKeyAction.SPRITE_BUTTON_UP
  • 长按拍照键SysKeyAction.SPRITE_BUTTON_LONG_PRESS

例如监听拍照键和触摸板长按事件:

private final BroadcastReceiver mSysKeyReceiver = new BroadcastReceiver() {
    @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (SysKeyAction.SPRITE_BUTTON_CLICK.equals(action)) {
            } else if (SysKeyAction.TOUCH_BAR_LONG_PRESS.equals(action)) {
            }
        }
};

private void registerSysKeyReceiver() {
    try {
        IntentFilter filter = new IntentFilter();
        filter.addAction(SysKeyAction.SPRITE_BUTTON_CLICK);
        filter.addAction(SysKeyAction.TOUCH_BAR_LONG_PRESS);
        registerReceiver(mSysKeyReceiver, filter)
    } catch (Exception e) {
        e.printStackTrace();
    }
}