作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个应该在后台监听启动指令的服务,这样当我打招呼时它应该调用一个 Activity ,我该怎么做,关于 voiceInteractionService 但我读过它不可用,是真的吗?谁能告诉我应该如何解决这个问题?它关于热词检测器
我一直在关注this
试过这个:
public class InteractionService extends VoiceInteractionService {
static final String TAG = "InteractionService" ;
private AlwaysOnHotwordDetector mHotwordDetector;
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "service started");
}
@Override
public void onReady() {
super.onReady();
Log.i(TAG, "Creating " + this);
mHotwordDetector = createAlwaysOnHotwordDetector("Hello"
, Locale.forLanguageTag("en-US"), mHotwordCallback);
Log.i(TAG, "onReady");
}
private final AlwaysOnHotwordDetector.Callback mHotwordCallback =
new AlwaysOnHotwordDetector.Callback() {
@Override
public void onAvailabilityChanged(int status) {
Log.i(TAG, "onAvailabilityChanged(" + status + ")");
hotwordAvailabilityChangeHelper(status);
}
@Override
public void onDetected(AlwaysOnHotwordDetector
.EventPayload eventPayload) {
Log.i(TAG, "onDetected");
}
@Override
public void onError() {
Log.i(TAG, "onError");
}
@Override
public void onRecognitionPaused() {
Log.i(TAG, "onRecognitionPaused");
}
@Override
public void onRecognitionResumed() {
Log.i(TAG, "onRecognitionResumed");
}
};
private void hotwordAvailabilityChangeHelper(int status) {
Log.i(TAG, "Hotword availability = " + status);
switch (status) {
case AlwaysOnHotwordDetector.STATE_HARDWARE_UNAVAILABLE:
Log.i(TAG, "STATE_HARDWARE_UNAVAILABLE");
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNSUPPORTED:
Log.i(TAG, "STATE_KEYPHRASE_UNSUPPORTED");
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_UNENROLLED:
Log.i(TAG, "STATE_KEYPHRASE_UNENROLLED");
Intent enroll = mHotwordDetector.createEnrollIntent();
Log.i(TAG, "Need to enroll with " + enroll);
break;
case AlwaysOnHotwordDetector.STATE_KEYPHRASE_ENROLLED:
Log.i(TAG, "STATE_KEYPHRASE_ENROLLED - starting recognition");
if (mHotwordDetector.startRecognition(0)) {
Log.i(TAG, "startRecognition succeeded");
} else {
Log.i(TAG, "startRecognition failed");
}
break;
}
// final static AlwaysOnHotwordDetector.Callback
}}
最佳答案
豪 pig 的service demo正是这样做的。
关于java - 如何在android中制作热词检测服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43177771/
我是一名优秀的程序员,十分优秀!