如何使用亚马逊语音服务或 Alexa 对我的应用进行语音查询

How to get voice query to my app with Amazon Voice Service or Alexa

在开发与 Android 应用程序集成的物联网设备时,我遇到了这个问题。

我希望实现的是与我的应用对话,例如"Alexa, What is the temperature inside the cooker?"。为了检索此信息,我有一个 android 应用程序通过蓝牙连接到智能炊具,并且该应用程序可以从炊具读取温度信息。

现在如何在我的 android 应用程序中获取查询以及如何 return 我的响应 "The current temperature in cooker is 100 degree celsius"。 Alexa 可以用语言表达出来。

这是我到目前为止所做的。

  1. 我使用亚马逊开发者控制台创建了一个帐户
  2. 在那里注册了我的应用程序并将 API 密钥复制到我的 android 项目中
  3. 在我的 android 项目中添加了他们的库
  4. 使用 Login With Amazon 服务获取 accessToken

    requestContext = RequestContext.create(this)
    requestContext.registerListener(object : AuthorizeListener() {
        override fun onSuccess(authorizeResult: AuthorizeResult) {
            accessToken = authorizeResult.accessToken
            Timber.d("Access Token: %s", accessToken)
        }
    
        override fun onCancel(auth: AuthCancellation?) {
            Timber.e(auth?.description)
        }
    
        override fun onError(error: AuthError) {
            Timber.e(error, error.localizedMessage)
        }
    })
    
    signInBtn.setOnClickListener {
        AuthorizationManager.authorize(
            AuthorizeRequest.Builder(requestContext)
                .addScopes(ProfileScope.profile(), ProfileScope.postalCode())
                .build()
        )
    }
    

这里是manifest的相关声明

<activity android:name="com.amazon.identity.auth.device.workflow.WorkflowActivity"
    android:theme="@android:style/Theme.NoDisplay"
    android:allowTaskReparenting="true"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <!-- android:host must use the full package name found in Manifest General Attributes -->
        <data android:host="${applicationId}" android:scheme="amzn"/>
    </intent-filter>
</activity>

我一直在关注 this 文档。

我需要做什么才能让我的应用程序中的查询得到处理并 return 结果?或者有可能吗?

你需要创造一个智能家居技能才能做到,你需要前进的方式是

  1. 创建智能家居技能,参考文档here

  2. 一旦你创建了一个智能家居技能(你会在这个过程中创建一个后端服务器)并且用户在他的 Alexa 账户中启用了这个技能,每当用户询问时 "Alexa, What is the temperature inside the cooker?" 你会得到一个指令请求到你的服务器,然后你可以将它路由到 android 应用程序并让 android 应用程序直接或通过你的服务器向 AVS 发送响应。