Initiate Stream
Initiating a stream creates a bidirectional socket from the client and the Marsview Server. The client will stream Audio data in real-time to the Marsview service endpoint, The Marsview server will send Model Outputs and Transcript back to the client on the same socket connection.

Initiate Stream code in Node.js

The example code below uses socket.io to stream data to and from the Marsview Server.
1
const express = require('express');
2
const app = express();
3
const port = 1337;
4
const server = require('http').createServer(app);
5
6
const ioClient = require('socket.io-client')
7
8
const session = require("express-session");
9
const wrap = middleware => (socket, next) => middleware(socket.request, {}, next);
10
11
const io = require('socket.io')(server);
12
const io_client = ioClient.connect('https://streams.marsview.ai/', {
13
auth: {
14
token: <ATUHTOKEN>,
15
txnId: <TRANSACTION ID>,
16
channelId: <CHANNEL ID>
17
}
18
});
19
20
io_client.on('valid-token', function (data) {
21
console.log('Token is valid');
22
});
23
24
io_client.on('invalid-token', function (data) {
25
console.log("Invalid token")
26
});
27
28
io_client.emit('startStream', data)
29
Copied!
The above connection is used to establish a websocket connection with the Marsview Realtime API endpoint. When once the connection is established we can user the io_client object to stream data to and from the Marsview Realtime API endpoint. The websocket call made to startStream is used to open up an end point that can receive the audio input from the client side.
The input data fed into the stream from the client side will be byte data/byte array the client receives from various sources. The input byte array can be streamed to Marsview using the websocket key binaryData .

Code Block for emitting byte array

1
io_client.emit('binaryData', data)
Copied!
This code block would be plugged into a streaming data input. Each time a byte array comes into the client side code this line of code has to be executed. Heredata is the byte array.
Last modified 7d ago