【问题标题】:Watson speech to text authenticationWatson 语音转文本身份验证
【发布时间】:2020-06-17 09:49:26
【问题描述】:

我试图让Transcribe from Microphone 在我的服务器上工作作为起点。

代码很简单,但我在使用令牌时遇到了问题。

在 IBMcloud 上,我使用访问策略创建了一个 IAM 服务 ID
Viewer、Reader 14 所有资源组中的 Speech to Text 服务

从中创建了一个 apikey

创建令牌文件

    curl -k -X POST  --output token \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --header "Accept: application/json" \
  --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
  --data-urlencode "apikey={apikey}" \
  "https://iam.cloud.ibm.com/identity/token"

响应包含“access_token”,但 javascript SDK 0.38.1 会查找“accessToken”

当我启动麦克风时,我收到一个套接字错误“wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize”

我检查了令牌过期时间。

我确认这是一个身份验证问题:

 curl -X GET "https://stream.watsonplatform.net/speech-to-text/api/v1/models?access_token="{accessToken}"

回应“未经授权”

我已经研究过,但不确定下一步该做什么。我最好的猜测是我生成的令牌不正确。

【问题讨论】:

    标签: authentication browser ibm-cloud ibm-watson ibm-iam


    【解决方案1】:

    我会将令牌生成留给代码。所有的 SDK 都有一个IAMAuthenticator component。完整的documentation for Node.js is here。它有一个非常简单的示例,您可以在其中传递 API 密钥:

    import { IamAuthenticator } from 'ibm-cloud-sdk-core';
    
    const authenticator = new IamAuthenticator({
      apikey: '{apikey}',
    });
    

    然后,实例化服务,例如 STT。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-22
      • 2019-06-23
      • 2016-04-28
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多