Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android中AlwaysOnHotwordDetector示例_Android_Speech Recognition_Android 5.0 Lollipop - Fatal编程技术网

Android中AlwaysOnHotwordDetector示例

Android中AlwaysOnHotwordDetector示例,android,speech-recognition,android-5.0-lollipop,Android,Speech Recognition,Android 5.0 Lollipop,有人能举例说明如何在Android中使用新的AlwaysOnHotwordDetector类吗 我想建立一个应用程序,当应用程序在后台运行时,可以检测到诸如“下一步”、“返回”或“暂停”之类的热门词 除非我有一个巨大的盲点,否则我认为第三方应用程序不能使用这个API。奇怪的是,AlwaysOnHotwordDetector(以及相关的类VoiceInteractionService等)被授予公共访问权 如果您正在构建特权应用程序,请从AOSP查看以下测试项目: 语音交互-基本AlwaysOn

有人能举例说明如何在Android中使用新的AlwaysOnHotwordDetector类吗


我想建立一个应用程序,当应用程序在后台运行时,可以检测到诸如“下一步”、“返回”或“暂停”之类的热门词

除非我有一个巨大的盲点,否则我认为第三方应用程序不能使用这个API。奇怪的是,
AlwaysOnHotwordDetector
(以及相关的类VoiceInteractionService等)被授予公共访问权


如果您正在构建特权应用程序,请从AOSP查看以下测试项目:

  • 语音交互-基本
    AlwaysOnHotwordDetector
    使用/实现
  • 语音注册-

在努力实现这一目标的过程中,我发现:

总是HotWordDetector的构造函数:

/**
 * @param text The keyphrase text to get the detector for.
 * @param locale The java locale for the detector.
 * @param callback A non-null Callback for receiving the recognition events.
 * @param voiceInteractionService The current voice interaction service.
 * @param modelManagementService A service that allows management of sound models.
 *
 * @hide
 */
public AlwaysOnHotwordDetector(String text, Locale locale, Callback callback,
        KeyphraseEnrollmentInfo keyphraseEnrollmentInfo,
        IVoiceInteractionService voiceInteractionService,
        IVoiceInteractionManagerService modelManagementService) {
    mText = text;
    mLocale = locale;
    mKeyphraseEnrollmentInfo = keyphraseEnrollmentInfo;
    mKeyphraseMetadata = mKeyphraseEnrollmentInfo.getKeyphraseMetadata(text, locale);
    mExternalCallback = callback;
    mHandler = new MyHandler();
    mInternalCallback = new SoundTriggerListener(mHandler);
    mVoiceInteractionService = voiceInteractionService;
    mModelManagementService = modelManagementService;
    new RefreshAvailabiltyTask().execute();
}
利益声明如下:

mKeyphraseMetadata = mKeyphraseEnrollmentInfo.getKeyphraseMetadata(text, locale);
KeyphraseEnrollmentInfo\getKeyphraseMetadata(字符串、区域设置)

/**
 * Gets the {@link KeyphraseMetadata} for the given keyphrase and locale, null if any metadata
 * isn't available for the given combination.
 *
 * @param keyphrase The keyphrase that the user needs to be enrolled to.
 * @param locale The locale for which the enrollment needs to be performed.
 *        This is a Java locale, for example "en_US".
 * @return The metadata, if the enrollment client supports the given keyphrase
 *         and locale, null otherwise.
 */
public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, Locale locale) {
    if (mKeyphrases == null || mKeyphrases.length == 0) {
        Slog.w(TAG, "Enrollment application doesn't support keyphrases");
        return null;
    }
    for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
        // Check if the given keyphrase is supported in the locale provided by
        // the enrollment application.
        if (keyphraseMetadata.supportsPhrase(keyphrase)
                && keyphraseMetadata.supportsLocale(locale)) {
            return keyphraseMetadata;
        }
    }
    Slog.w(TAG, "Enrollment application doesn't support the given keyphrase/locale");
    return null;
}
此时,我的示例项目不断告诉我:
注册应用程序不支持关键字短语。因此,进一步挖掘-为了支持关键短语,我们需要提供额外的元数据:

// Taken from class KeyphraseEnrollmentInfo
/**
 * Name under which a Hotword enrollment component publishes information about itself.
 * This meta-data should reference an XML resource containing a
 * <code>&lt;{@link
 * android.R.styleable#VoiceEnrollmentApplication
 * voice-enrollment-application}&gt;</code> tag.
 */
private static final String VOICE_KEYPHRASE_META_DATA = "android.voice_enrollment";

此外,我们还需要android.permission.MANAGE\u VOICE\u关键字短语
权限。这就是示例项目陷入困境的地方:

<!-- Must be required by hotword enrollment application,
     to ensure that only the system can interact with it.
     @hide <p>Not for use by third-party applications.</p> -->
<permission android:name="android.permission.MANAGE_VOICE_KEYPHRASES"
    android:label="@string/permlab_manageVoiceKeyphrases"
    android:description="@string/permdesc_manageVoiceKeyphrases"
    android:protectionLevel="signature|system" />


支持热词检测所需的权限对第三方应用程序不可用。我仍然不明白为什么包
android.service.voice
package具有公共访问权限。也许我这里遗漏了什么。

您试过运行它吗?如果我们能访问这个,那就太好了API@gregm是的,我试过了。我需要
MANAGE\u VOICE\u keyphases
权限,只有系统应用程序才能请求。我同意,如果我们能使用这个API,那就太棒了。关于如何将应用程序安装为系统应用程序,有一些程序已经过测试了吗?我们仍然无法使用它吗?
android。谷歌的文档中甚至没有列出permission.MANAGE\u VOICE\u关键字短语