如何在提升野兽网络套接字中传递模型类型

How do I pass the model type in boost beast websocket

本文关键字:模型 类型 套接字 网络 野兽      更新时间:2023-10-16

我正在使用c ++ 11,beast库和IBM语音转文本Web服务。

在执行握手时,websocket 接口(用于连接(需要authentication token作为请求标头。

参考 Watson 文档中提供的这段代码,看起来我也必须将模型类型(如果需要(作为请求标头传递

var IAM_access_token = '{access_token}';
var wsURI = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize'
     + '?access_token=' + IAM_access_token
     + '&model=es-ES_BroadbandModel';
var websocket = new WebSocket(wsURI);

还提到了一个 curl 请求格式来设置"模型">

curl -X POST -u "apikey:{apikey}"
--header "Content-Type: audio/flac"
--data-binary @{path}audio-file.flac
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel"

有人可以告诉我如何在我的 websocket 中传递"模型"(在 c++11 中使用 beast(吗?

以下是我传递身份验证令牌的方式:

mWebSocket.async_handshake_ex(mHost, "/speech-to-text/api/v1/recognize",
        [mToken](request_type& reqHead) {
            reqHead.insert(http::field::authorization,mToken);},
        bind(&IbmWebsocketSession::send_start, shared_from_this(), placeholders::_1));
正如

@ALanBirtles所建议

将 url 中的重新model作为

    mWebSocket.async_handshake_ex(mHost, "/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel",...

工程