Search code examples
c++boostibm-watsonspeech-to-textboost-beast

How do I pass the model type in boost beast websocket


I am working with c++11, beast library and IBM speech to text web service.

The websocket interface (to connect) needs the authentication token as request header while the handshake is performed.

Refering to this code available in the Watson documents it looks like I have to pass the model type (if I want to) as request header too

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);

Also there is a curl request format mentioned to set the "model"

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"

Can someone hel me figure out How do I pass "model" in my websocket (using beast in c++11)?

Here is how I am passing the authentication token:

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));

Solution

  • As @ALanBirtles suggested

    Putting the resuired model in the url as

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

    Works