IBM Watson语音对带有IAM API密钥的WebSocket授权文本

贝壳

我正在尝试使用新帐户(仅具有IAM授权)将IBM Watson的讲话连接到文本WebSocket。

我的WS端点是,wss://stream-fra.watsonplatform.net/text-to-speech/api/v1/recognize并且我通过获得了访问令牌https://iam.bluemix.net/identity/token现在,当我打开带有Authorization标头的套接字连接时,Bearer token会得到一个不好的握手响应:websocket: bad handshake, Unauthorized 401语言就是去。

我是在做错什么,还是没有用户名/密码身份验证即不赞成使用Watson的语音连接到文本WebSocket watson-token

编辑:

打开WebSocket的代码:

headers := http.Header{}
headers.Set("Authorization", "Bearer " + access_token)
conn, resp, err := websocket.DefaultDialer.Dial("wss://stream-fra.watsonplatform.net/text-to-speech/api/v1/recognize", headers)

我还尝试了基本授权,apikey:**api_key**结果是相同的:401

编辑2:

获取访问令牌(基于Watson Swift和Python SDK)的代码,该令牌成功并返回访问和刷新令牌:

func getWatsonToken(apiKey string) (string, error) {
    // Base on the Watson Swift and Python SDKs
    // https://github.com/watson-developer-cloud/restkit/blob/master/Sources/RestKit/Authentication.swift
    // https://github.com/watson-developer-cloud/python-sdk/blob/master/watson_developer_cloud/iam_token_manager.py

    const tokenUrl = "https://iam.bluemix.net/identity/token"

    form := url.Values{}
    form.Set("grant_type", "urn:ibm:params:oauth:grant-type:apikey")
    form.Set("apikey", apiKey)
    form.Set("response_type", "cloud_iam")

    // Token from simple "http.PostForm" does not work either
    //resp, err := http.PostForm(tokenUrl, form)

    req, err := http.NewRequest(http.MethodPost, tokenUrl, nil)
    if err != nil {
        log.Printf("could not create HTTP request to get Watson token: %+v", err)
        return "", nil
    }

    header := http.Header{}
    header.Set("Content-Type", "application/x-www-form-urlencoded")
    header.Set("Accept", "application/json")
    // "Yng6Yng=" is "bx:bx"
    header.Set("Authorization", "Basic Yng6Yng=")
    req.Header = header

    req.Body = ioutil.NopCloser(bytes.NewReader([]byte(form.Encode())))

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        log.Printf("problem executing HTTP request to get Watson token: %+v", err)
        return "", err
    }

    defer resp.Body.Close()

    if resp.StatusCode != 200 {
        return "", errors.New(fmt.Sprintf("failed to get Watson token: %d", resp.StatusCode))
    }

    jsonBody, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        log.Printf("problem reading Watson token from response body: %+v", err)
    }

    tokenResponse := &struct {
        AccessToken  string `json:"access_token"`
        RefreshToken string `json:"refresh_token"`
        TokenType    string `json:"token_type"`
        ExpiresIn    int64  `json:"expires_in"`
        Expiration   int64  `json:"expiration"`
    }{}

    err = json.Unmarshal(jsonBody, tokenResponse)
    if err != nil {
        log.Printf("could not parse Watson token response: %+v", err)
        return "", err
    }

    return tokenResponse.AccessToken, err
}
贝壳

我在端点中出错,并使用了文本到语音而不是语音到文本。使用正确的URL,WebSocket API可以使用。

wss://stream-fra.watsonplatform.net/text-to-speech/api/v1/recognize 应该 wss://stream-fra.watsonplatform.net/speech-to-text/api/v1/recognize

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

IBM Watson API Java SDK使用Watson令牌认证失败

IBM Watson语音转文本:无法使用Swift SDK转录文本

使用ibm-watson服务C#进行语音到文本

IBM Watson语音到文本仅使用Java SDK返回第一个单词

使用WebSockets的IBM Watson语音到文本

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

如何检测语音到文本中的句子检测是否已完成(Unity IBM Watson sdk)?

将WAV录制到IBM Watson语音到文本

IBM Watson语音到文本发送麦克风数据关闭了连接

使用ibm watson文本到语音服务处理多个查询

Twilio的IBM Watson语音到文本插件影响一个电话号码

IBM Watson Api视觉识别错误

IBM Watson语音到文本Python,“ DetailedResponse”对象没有属性“ getResult”

IBM Watson使用Postman翻译apikey授权失败

如何为IBM Watson的语音转文本服务Web套接字端点找到必要的访问Web令牌?

使用IBM Watson语音文本NPM模块难以注册回调URL

大于〜7mb的文件将引发“未收到响应”。IBM Watson语音到文本异步createJob调用

具有API密钥访问权限的IBM Cloud Functions

Anaconda与IBM Watson Studio

IBM Watson IAM令牌适合所有服务还是特定于每种服务(例如语音到文本)?

带有承载令牌的IBM Cloud语音到文本SDK身份验证失败

IBM语音文本用户名和密码问题

语音到文本Ibm Watson C#的语音,长音频超过100 MB

IBM Watson语音对文本的单词置信度差异

用于更新IBM Watson Conversation实体的API

如何使用 IBM watson 情感分析分析任何文本

错误:未经授权 - IBM Watson Visual Recognition 的 Python 脚本

如何将 ibm watson 语音中的扬声器标签更改为 android 中的文本 api?

使用 IBM Watson 的语音转文本会导致在识别关键字时多次调用方法