See Headers for details on required headers and their meaning.

This section assumes you have read the Protocol Structure and Message Structure sections.

Query

Create a Query

{
  "type": "request",
  "requestId": "4",
  "method": "POST",
  "restUri": "/queries",
  "headers": {
    "X-Voysis-Audio-Profile-Id": "f8338e44-9d48-11e7-abc4-cec278b6b50a",
    "X-Voysis-Ignore-Vad": false,
    "Accept": "application/vnd.voysisquery.v1+json",
    "Authorization": "Bearer 1.eyJpc3N1ZWRCeSI6IjBkZmI4OGMyLTQ2ZTctNGNjZC05YmZiLTQ3OTQ5NTJmN2I5YyIsImlzc3VlZEF0IjoiMjAxOC0wNC0yN1QwODo0NjozOS40NTRaIiwiZXhwaXJlc0F0IjoiMjAxOC0wNC0yN1QwOTowMTozOS40NTRaIiwiZ2VuZXJhdGlvbiI6MSwicGVybWlzc2lvbnMiOlsiY2VyYmVydXM6bGlvbmVsOmFjY2VzcyJdfQ==.53822ae0527256950896a36570797e3122a1b127e7c3ba85d648a7fce9cc36cd45fa829455579ad6c2ad5ec0ebf958d9bb1680a1e1b322357758c1a70e11b2e6"
  },
  "entity": {
    "locale": "en-US",
    "queryType": "audio",
    "audioQuery": {
      "mimeType": "audio/pcm;bits=16;rate=16000"
    }
  }
}

A sample response to creating a query:

{
  "type": "response",
  "entity": {
    "id": "f35586ca-296f-416c-867c-56ccd9c5419c",
    "locale": "en-US",
    "queryType": "audio",
    "audioQuery": {
      "mimeType": "audio/pcm;bits=16;rate=16000"
    },
    "_links": {
      "self": {
        "href": "/queries/f35586ca-296f-416c-867c-56ccd9c5419c"
      },
      "audio": {
        "href": "/queries/f35586ca-296f-416c-867c-56ccd9c5419c/audio"
      }
    },
    "_embedded": {}
  },
  "requestId": "4",
  "responseCode": 201,
  "responseMessage": "Created"
}

Stream Audio Data

All binary data sent through the WebSocket is expected to be audio data associated with the most recently created query. If there is no currently created query, you will receive an error notification. See Audio Guidelines for information on the expected audio format.

VAD Notification

While your client is streaming audio, the Voysis AI will automatically detect when the user has stopped speaking and send a VAD notification. Voysis will ignore all audio sent to it for the current query after after it has sent the VAD notification, so your client should stop streaming audio once the VAD notification is received.

{
  "type": "notification",
  "notificationType": "vad_stop"
}

Ending Audio Stream

If you wish to end streaming audio data before your receive the vad_stop notification, then you should send a single byte value of 4 through the WebSocket - this single byte must be sent on its own.
This notifies the Voysis AI that you will not send any further audio data, and that it should complete processing based on the audio already received.
Note that you do not need to send this single byte value if you have received the vad_stop notification from the Voysis AI.

For example:

var byteArray = new Int8Array(1);
byteArray[0] = 4;
webSocket.send(byteArray);

Query Complete Notification

Once Voysis has processed the audio, it will send the query results as a query_complete notification to your client.

See Query Responses for details on the structure and meaning of the fields in the query response.

For example:

{
  "type": "notification",
  "entity": {
    "id": "f35586ca-296f-416c-867c-56ccd9c5419c",
    "locale": "en-US",
    "queryType": "audio",
    "textQuery": {
      "text": "show me freshly squeezed orange juice"
    },
    "audioQuery": {
      "mimeType": "audio/pcm;bits=16;rate=16000"
    },
    "intent": "newSearch",
    "reply": {
      "text": "Here's what I found"
    },
    "entities": {
      "keywords": [
        "freshly",
        "squeezed",
        "orange",
        "juice"
      ],
      "products": [],
      "queryString": "freshly squeezed orange juice",
      "sortBy": ""
    },
    "_links": {
      "self": {
        "href": "/queries/f35586ca-296f-416c-867c-56ccd9c5419c"
      },
      "audio": {
        "href": "/queries/f35586ca-296f-416c-867c-56ccd9c5419c/audio"
      }
    },
    "_embedded": {}
  },
  "notificationType": "query_complete"
}