代码之家  ›  专栏  ›  技术社区  ›  Hews

IBM Watson语音到文本API

  •  1
  • Hews  · 技术社区  · 6 年前

    我想用 IBM Watson Speech to Text 而且我对curl结构有问题,因为文档似乎显示 username:password 作为身份验证,但这是找不到的。

    我遇到了一个有类似问题的问题 How to get username & password for Watson Text to Speech Service?

    当我包含api密钥而不是 用户名:密码 我被要求输入我的密码。这仍然是正确的curl请求还是已经转移到其他地方了?

    curl -X POST -u <api-key> \
    --header "Content-Type: audio/flac" \
    --data-binary @audio-file.flac \
    "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"
    

    谢谢:)

    1 回复  |  直到 6 年前
        1
  •  1
  •   Daniel Bolanos    6 年前

    如果要坚持基本身份验证方案,可以使用实际的api密钥作为密码 apikey 作为用户名:

    curl https://stream.watsonplatform.net/speech-to-text/api/v1/models -u "apikey:<apikey>"

    也就是说,出于安全原因,建议生产应用程序不要直接使用api密钥,而是使用一个令牌:

    您可以使用API密钥获取令牌,它将在一小时内有效:

    curl -X POST https://iam.ng.bluemix.net:443/oidc/token -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' -H 'grant_type: urn:ibm:params:oauth:grant-type:apikey' -d 'grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey=<apikey>'

    然后,您可以在调用服务时传递该令牌,如下所示:

    curl https://stream.watsonplatform.net/speech-to-text/api/v1/models -header "Authorization: Bearer <token_here>"