Start and stop Streaming API connection

Start Connection

Use this code to start a connection to the Streaming API using JavaScript WebSockets. This example uses both the Symbl.ai Web SDK and JS SDK, which is meant to be run using Node.js.

Web SDK

// import {Symbl} from '@symblai/symbl-web-sdk'; // ES6 Import
const {Symbl} = window;

// Authenticate with Symbl.ai

(async () => {
    try {

        const symbl = new Symbl({
            appId: "<YOUR APP ID>",
            appSecret: "<YOUR APP SECRET>",
            // accessToken: "<YOUR ACCESS TOKEN>" // Alternatively use an access token to authenticate.
        });

        // Will open and start a new Symbl connection and attempt to grab audio
        // using the default connected input device.
        const connection = await symbl.createAndStartNewConnection({
            insightTypes: ['action_item', 'question'],
            disconnectOnStopRequest: false,
            disconnectOnStopRequestTimeout: 300,
            config: {
                meetingTitle: 'My Test Meeting',
                confidenceThreshold: 0.7,
                timezoneOffset: 480, // Offset in minutes from UTC
                languageCode: 'en-US',
                sampleRateHertz: 48000,
                encoding: "OPUS"
            },
            speaker: {
                // Optional, if not specified, will simply not send an email in the end.
                userId: 'emailAddress', // Update with valid email
                name: 'My name'
            }
        });

        /**
         * This will return live speech-to-text transcription of the call.
         */
        connection.on("speech_recognition", (data) => {
            console.log(JSON.stringify(data))
            if (data) {
                const {punctuated} = data
                console.log('Live: ', punctuated && punctuated.transcript)
            }
        });

        /**
         * When processed messages are available, this callback will be called.
         */
        connection.on("message", (data) => {
            console.log('onMessageResponse', JSON.stringify(data, null, 2))
        });

        /**
         * When Symbl detects a topic, this callback will be called.
         */
        connection.on("topic", (data) => {
            console.log('onTopicResponse', JSON.stringify(data, null, 2))
        });

        /**
         * Various callbacks for Symbl insights
         */
        connection.on("follow_up", (data) => {
            console.log('onMessageResponse', JSON.stringify(data, null, 2))
        });

        connection.on("action_item", (data) => {
            console.log('onMessageResponse', JSON.stringify(data, null, 2))
        });

        connection.on("question", (data) => {
            console.log('onMessageResponse', JSON.stringify(data, null, 2))
        });


        // This is a helper method for testing purposes.
        // It waits 60 seconds before continuing to the next API call.
        await Symbl.wait(60000);

                  
        // Stops processing audio, but keeps the WebSocket connection open.
        await connection.stopProcessing();

        // Closes the WebSocket connection.
        connection.disconnect();


    } catch(e) {
      // Handle errors here.
    }

})();

Testing

Look at the Install or import Web SDK section of the Web SDK documentation for more details on how to test this snippet.

JS SDK (Node.js)

const {sdk} = require('@symblai/symbl-js');
const uuid = require('uuid').v4;

(async () => {
  try {
    // Initialize the SDK. You can find the appId and appSecret at https://platform.symbl.ai.
    await sdk.init({
      appId: appId,
      appSecret: appSecret,
      basePath: 'https://api.symbl.ai',
    })

    // Need unique Id
    const id = uuid()

    // Start Real-time Request (Uses Real-time WebSocket API behind the scenes)
    const connection = await sdk.startRealtimeRequest({
      id,
      insightTypes: ['action_item', 'question'],
      config: {
        meetingTitle: 'My Test Meeting',
        confidenceThreshold: 0.7,
        timezoneOffset: 480, // Offset in minutes from UTC
        languageCode: 'en-US',
        sampleRateHertz: 44100,
      },
      speaker: {
        // Optional, if not specified, will simply not send an email in the end.
        userId: 'emailAddress', // Update with valid email
        name: 'My name'
      },
      handlers: {
        /**
         * This will return live speech-to-text transcription of the call.
         */
        onSpeechDetected: (data) => {
          console.log(JSON.stringify(data))
          if (data) {
            const {punctuated} = data
            console.log('Live: ', punctuated && punctuated.transcript)
          }
        },
        /**
         * When processed messages are available, this callback will be called.
         */
        onMessageResponse: (data) => {
          console.log('onMessageResponse', JSON.stringify(data, null, 2))
        },
        /**
         * When Symbl detects an insight, this callback will be called.
         */
        onInsightResponse: (data) => {
          console.log('onInsightResponse', JSON.stringify(data, null, 2))
        },
        /**
         * When Symbl detects a topic, this callback will be called.
         */
        onTopicResponse: (data) => {
          console.log('onTopicResponse', JSON.stringify(data, null, 2))
        }
      }
    });

    micInstance.start()

  } catch (e) {
    console.error(e);
  }
})();

Testing

Create a JavaScript file named app.js and copy this code into the file. Fill in the placeholder values with the proper values. Use npm to install the required libraries: npm install @symblai/symbl-js uuid. Then in the terminal run:

$ node app.js

If successful, you should receive a response in the console.

📘

Backward Compatibility

The previous endpoint wss://api.symbl.ai/v1/realtime/insights/ is now updated to wss://api.symbl.ai/v1/streaming/ to standardize our API nomenclature. This change is backward compatible. However, we recommend you use the new endpoint.

📘

Termination due to elongated silence

If the meeting is silent for more than 30 minutes, it will be automatically terminated. The charges towards the silent minutes apply.