如何使用curl访问IBM语音转文本api ?



我无法使用curl访问IBM Bluemix上的语音转文本API !我尝试了文档中的示例,使用curl进行无会话请求,但它不起作用;我收到一个无效的用户名/密码消息。

下面是我得到的错误:

"{"code": 401, "error": "Not Authorized", "description":"2016-10-08T15:22:37-04:00, Error ERCDPLTFRM-DNLKUPERR发生时访问https://158.85.132.94:443/语音/api/v1/识别?时间戳= true& word_alternatives_threshold = 0.9,连续= true,无效的用户名和/或密码。请确认您的证件匹配您试图访问的端点。一个常见的错误是尝试使用来自实验版或测试版的凭证来对抗GA释放"}"

谁能告诉我一个工作的例子,如何获得一个api无会话请求的语音到文本api与curl?

无会话调用的文档在这里。

确保您创建了Watson Speech-to-Text服务的实例,并使用来自该服务的凭证(而不是您的Bluemix用户id和密码)。

您可以在Bluemix UI中创建服务并获得凭据,或者您可以通过命令行创建它:

$ cf create-service speech_to_text standard my_service

然后你可以创建服务凭据并获取它:

$ cf create-service-key my_service credentials-1
$ cf service-key my_service credentials-1
Getting key credentials-1 for service instance my_service as adasilva@us.ibm.com...
{
 "password": "FJXUG6????",
 "url": "https://stream.watsonplatform.net/speech-to-text/api",
 "username": "147e438e-f633-4e40-8351-aaaaaaaaaa"
}

然后可以在curl脚本中使用上面的用户名和密码。参见下面的curl命令和结果(出于安全考虑,我屏蔽了用户名、密码和其他字段):

$ curl -X POST -v -u '80062070-1f88-4943-9a2a-aaaaaaa':'hwtTg???????' 
> --header 'Content-Type: audio/flac' 
> --data-binary @audio-file1.flac 
> 'https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?timestamps=true&continuous=true'
*   Trying 158.85.132.94...
* Connected to stream.watsonplatform.net (158.85.132.94) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.watsonplatform.net
* Server certificate: GeoTrust SSL CA - G3
* Server certificate: GeoTrust Global CA
* Server auth using Basic with user '80062070-1f88-4943-9a2a-aaaaaaa'
> POST /speech-to-text/api/v1/recognize?timestamps=true&continuous=true HTTP/1.1
> Host: stream.watsonplatform.net
> Authorization: Basic ODAwNjIwNzAtMWY4OC00OTQzLTlhMmEtYzE0OWVmOTJkM2IyOmh3dXXXXXX==
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: audio/flac
> Content-Length: 48363
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
< X-Note: Gateway Ack
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< X-Backside-Transport: OK OK
< Connection: Keep-Alive
< Transfer-Encoding: chunked
< Session-Name: LBBROMXYTJZKKEGE-en-US_BroadbandModel
< X-Content-Type-Options: nosniff
< Content-Disposition: inline; filename="result.json"
< X-XSS-Protection: 1
< Date: Sat, 08 Oct 2016 22:45:02 GMT
< Via: 1.1 c6a59f5, 1.1 022614b, HTTP/1.1 d941b9b
< Content-Type: application/json
< Server: -
< Set-Cookie: Watson-REMOVED; path=/speech-to-text/api; secure; HttpOnly
< X-Client-IP: 71.70.244.18
< X-Global-Transaction-ID: 775715492
< X-DP-Watson-Tran-ID: stream-dp02-775715492
< 
{
   "results": [
      {
         "alternatives": [
            {
               "timestamps": [
                  [
                     "the", 
                     0.03, 
                     0.09
                  ], 
                  [
                     "latest", 
                     0.09, 
                     0.6
                  ], 
                  [
                     "weather", 
                     0.6, 
                     0.85
                  ], 
                  [
                     "report", 
                     0.85, 
                     1.52
                  ]
               ], 
               "confidence": 0.98, 
               "transcript": "the latest weather report "
            }
         ], 
         "final": true
      }
   ], 
   "result_index": 0
* Connection #0 to host stream.watsonplatform.net left intact

我遇到了同样的问题。经过多次尝试,我发现URL是错误的。记住Service Credential信息:

{
"url":"https://stream-fra.watsonplatform.net/text-to-speech/api",
"用户名":"xxxxx-xxxxx-xxxxx-xxxxx",
"密码":"yyyyyyy"
}

那么,您必须使用该信息中提供的URL。以下是对我的好要求:

E:/Curl/Curl .exe -X GET -u "xxxxx-xxxxx-xxxxx-xxxxx -xxxxx":"yyyyyyy"——output hello_world.wav "https://stream-fra.watsonplatform.net/text-to-speech/api/v1/synthesize?accept=audio/wav&text=Hello%20world&voice=en-US_AllisonVoice"

我的问题是我的证书周围有花括号。教程说:

curl -X POST -u {username}:{password}

所以我输入了我的用户名和密码,但我留下了大括号。没有花括号工作得更好!

相关内容

  • 没有找到相关文章

最新更新