Examples

Visit our GitHub samples repository for more examples on how to use the Vatis Streams API.

Prerequisites

Create the WebSocket connection

Connect to the Vatis Streams API using the WebSocket protocol. We can configure the stream by using either query parameters of a configuration message.

Specify all the configuration parameters in the query string of the WebSocket URL. (e.g. language)

wss://ws-gateway.vatis.tech/ws-gateway/api/v1/?streamConfigurationTemplateId=670ba9e0efa59fe6aecd56f1&language=en

Send your data

Send your data to the WebSocket server as binary chunks from your data source.

with open('audio_file.wav', 'rb') as file:
    chunk = file.read(1024)
    while chunk:
        ws.send(chunk)
        chunk = file.read(1024)

Receive the results

The first result message you’ll receive is the stream metadata message that will contain all the metadata of the created stream.

The rest of the response stream will consist of either response messages or binary message, if configured so.

If an error is encountered during the processing, an error message will be sent, then the connection will be closed.

Analyzing the result

The response messages will contain a sink message that wraps a processor message. The complete list of processor messages can be found in the API reference.

Let’s take for this example the transcription message that contains the transcription of the audio data.

{
  "type": "RESPONSE",
  "response": {
    "streamId": "e9756f47-3222-4951-b372-15435b787c9f",
    "groupId": "e9756f47-3222-4951-b372-15435b787c9f",
    "tags": [
      "main",
      "transcriber"
    ],
    "sinkTopicName": "e7de18ba",
    "messageId": "CKfpHhAnMAA",
    "processorId": "transcriber",
    "sequenceId": 39,
    "publishTimestamp": 1734449767699000,
    "frameType": "final",
    "payloadSchema": "tech.vatis.schema.stream.processor.messages.transcription.TranscriptionResponseDto",
    "payload": {
      "transcription": " George Washington.",
      "words": [
        {
          "word": " George",
          "start": 30670,
          "end": 31150,
          "confidence": 0.99902344,
          "language": "en",
          "metadata": {}
        },
        {
          "word": " Washington.",
          "start": 31150,
          "end": 31650,
          "confidence": 0.98706055,
          "language": "en",
          "metadata": {}
        }
      ],
      "start": 29150,
      "end": 32229,
      "metadata": {},
      "utterance": false
    },
    "headers": {}
  }
}
type
RESPONSE

The RESPONSE type of the message.

response.streamId
e9756f47-3222-4951-b372-15435b787c9f

The corresponding stream id that emitted this message.

response.frameType
final

The type of the frame. Can be final or partial. A final frame represents the final processing result for a portion of the stream.

response.payloadSchema
tech.vatis.schema.stream.processor.messages.transcription.TranscriptionResponseDto

The schema of the payload.

response.payload
object

The actual payload of type TranscriptionResponseDto.

response.payload.transcription
object

The transcription preview.

Close the connection

To confirm the input data was sent completely, send an end-of-stream message to the WebSocket server. The engine will finish processing, send the final results, followed by a similar end-of-stream message, and then close the connection.

Further reading

Explore the complete WS Gateway API reference and the WebSocket integration.