1.4.8 • Published 2 years ago

@symblai/symbl-js v1.4.8

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Symbl Javascript SDK

The Symbl Javascript SDK provides convenient access to the Symbl API from applications written in the Javascript language via Node.js or directly in the browser. It includes a pre-defined set of classes for a simple and clear utilization of APIs.

We are working diligently to support every Symbl API. Currently we support the following APIs:

Documentation

See the API docs.

Requirements

  • Node.js 10+

Installation

First make sure that Node.js is installed on your system with the following command in Mac/Linux console or Windows command prompt:

node -v

To install the Node.js, just visit the link below:

You can then install the library directly on your machine using:

npm install @symblai/symbl-js

Configuration

The SDK needs to be initialized with your account's credentials (appId & appSecret) which is available in your Symbl Platform.

You can either provide the credentials by declaring constants before SDK initilization or pass them directly when creating the SDK instance.

Example:

const APP_ID='<app_id>'
const APP_SECRET='<app_secret>'

sdk.init({
    appId: APP_ID,
    appSecret: APP_SECRET
}).then(() => console.log('SDK Initialized.'))
    .catch(err => console.error('Error in initialization.', err));

Transcribing live audio input through the microphone

As a simple test of the Streaming API you can simply setup a live microphone and push the audio stream using the mic npm package and use the uuid package to create a unique meeting ID.

Initialize the SDK and connect via the built-in websocket connector. This will output the live transcription to the console.

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

const APP_ID = '<your App ID>';
const APP_SECRET = '<your App Secret>';

const mic = require('mic')

const sampleRateHertz = 16000

const micInstance = mic({
  rate: sampleRateHertz,
  channels: '1',
  debug: false,
  exitOnSilence: 6,
});

(async () => {
  try {
    // Initialize the SDK
    await sdk.init({
      appId: APP_ID,
      appSecret: APP_SECRET,
      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,
      config: {
        meetingTitle: 'My Test Meeting',
        confidenceThreshold: 0.7,
        timezoneOffset: 480, // Offset in minutes from UTC
        languageCode: 'en-US',
        sampleRateHertz
      },
      handlers: {
        /**
         * This will return live speech-to-text transcription of the call.
         * There are other handlers that can be seen in the full example.
         */
        onSpeechDetected: (data) => {
          if (data) {
            const {
              punctuated
            } = data
            console.log('Live: ', punctuated && punctuated.transcript)
          }
        }
      }
    });

    console.log('Successfully connected. Conversation ID: ', connection.conversationId);

    const micInputStream = micInstance.getAudioStream()
    /** Raw audio stream */
    micInputStream.on('data', (data) => {
      // Push audio from Microphone to websocket connection
      connection.sendAudio(data)
    })

    micInputStream.on('error', function (err) {
      console.log('Error in Input Stream: ' + err)
    })

    micInputStream.on('startComplete', function () {
      console.log('Started listening to Microphone.')
    })

    micInputStream.on('silence', function () {
      console.log('Got SIGNAL silence')
    })

    micInstance.start()

    setTimeout(async () => {
      // Stop listening to microphone
      micInstance.stop()
      console.log('Stopped listening to Microphone.')
      try {
        // Stop connection
        await connection.stop()
        console.log('Connection Stopped.')
      } catch (e) {
        console.error('Error while stopping the connection.', e)
      }
    }, 60 * 1000) // Stop connection after 1 minute i.e. 60 secs
  } catch (e) {
    console.error('Error: ', e)
  }
})();

If you'd like to see a more in-depth examples for the Streaming API, please take a look at the extended Streaming examples here.

Transcribing live audio input through Telephony API

As a simple test of the Telephony API you can call a phone number and see a live transcription of your phone call in the console.

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

const APP_ID = '<your App ID>';
const APP_SECRET = '<your App Secret>';
const PHONE_NUMBER = '<your phone number>';

(async () => {
    try {
        // Initialize the SDK
        await sdk.init({
            appId: APP_ID,
            appSecret: APP_SECRET,
            basePath: 'https://api.symbl.ai',
        })

        // Start Real-time Request (Uses Real-time WebSocket API behind the scenes)
        const connection = await sdk.startEndpoint({
            endpoint: {
                type: 'pstn',
                phoneNumber: PHONE_NUMBER,
            },
            insightTypes: ['action_item', 'question'],
            data: {
                session: {
                    name: 'My Test Meeting',
                },
            },
        });

        const { connectionId } = connection;
        console.log('Successfully connected. Connection Id: ', connectionId);

        // Subscribe to connection using connectionId.
        sdk.subscribeToConnection(connectionId, (data) => {
            const { type } = data;
            if (type === 'transcript_response') {
                const { payload } = data;

                // You get live transcription here
                console.log(`Live: ${payload && payload.content}`);

            } else if (type === 'message_response') {
                const { messages } = data;

                // You get any messages here
                messages.forEach(message => {
                  console.log(`Message: ${message.payload.content}`)
                })
            } else if (type === 'insight_response') {
                const { insights } = data;
                // You get any insights here!!!
                insights.forEach(insight => {
                    console.log(`Insight: ${insight.type} - ${insight.text}`);
                });
            }
        });

        // Stop call after 60 seconds to automatically.
        setTimeout(async () => {
            const connection = await sdk.stopEndpoint({
                connectionId
            });
            console.log('Stopped the connection');
            console.log('Conversation ID:', connection.conversationId);
        }, 60 * 1000); // Change the 60 to however many seconds you want.
    } catch (e) {
        console.error('Error: ', e)
    }
})();

If you'd like to see a more in-depth examples for the Telephony API, please take a look at the extended Telephony examples here.

Need support?

If you are looking for some specific use cases and more in-depth examples do check our examples folder.

If you can't find your answers, do let us know at support@symbl.ai or join our slack channel here.

1.4.9-beta.1

2 years ago

1.4.9-beta.2

2 years ago

1.4.9-beta.4

2 years ago

1.4.8-beta.3

2 years ago

1.4.8-beta.2

2 years ago

1.4.8-beta.1

2 years ago

1.4.8

2 years ago

1.4.7-beta.7

2 years ago

1.4.7-beta.8

2 years ago

1.4.7-beta.5

2 years ago

1.4.7-beta.6

2 years ago

1.4.7-beta.3

2 years ago

1.4.7-beta.4

2 years ago

1.4.7-beta.1

2 years ago

1.4.7-beta.2

2 years ago

1.4.7-beta.9

2 years ago

1.4.7-beta.15

2 years ago

1.4.7-beta.14

2 years ago

1.4.7-beta.17

2 years ago

1.4.7-beta.16

2 years ago

1.4.7-beta.11

2 years ago

1.4.7-beta.10

2 years ago

1.4.7-beta.13

2 years ago

1.4.7-beta.12

2 years ago

1.4.7-beta.19

2 years ago

1.4.7-beta.18

2 years ago

1.4.7

2 years ago

1.1.6-labs.7

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.4

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.2-alpha.1

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.4.2-alpha.3

2 years ago

1.4.2-alpha.2

2 years ago

1.4.5-alpha.1

2 years ago

1.4.6-alpha.1

2 years ago

1.2.0

2 years ago

1.4.0-alpha.1

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.3.0-alpha.2

2 years ago

1.3.0-alpha.1

2 years ago

1.3.0-alpha.4

2 years ago

1.3.0-alpha.3

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.3.0

2 years ago

1.1.10

2 years ago

1.1.8-labs.2

2 years ago

1.1.6-labs.3

2 years ago

1.1.8-labs.1

2 years ago

1.1.6-labs.4

2 years ago

1.1.6-labs.5

2 years ago

1.1.6-labs.6

2 years ago

1.1.6-labs.1

2 years ago

1.1.6-labs.2

2 years ago

1.1.5-alpha.13

2 years ago

1.1.5-alpha.14

2 years ago

1.1.5-alpha.15

2 years ago

1.1.5-alpha.16

2 years ago

1.1.5-alpha.11

2 years ago

1.1.5-alpha.12

2 years ago

1.1.5-alpha.18

2 years ago

1.1.5-alpha.19

2 years ago

1.1.5-labs.6

3 years ago

1.1.5-labs.3

3 years ago

1.1.5-labs.5

3 years ago

1.1.5-labs.4

3 years ago

1.1.5-labs.2

3 years ago

1.1.5-alpha.9

3 years ago

1.1.5-alpha.10

3 years ago

1.1.5-alpha.6

3 years ago

1.1.5-alpha.7

3 years ago

1.1.5-alpha.8

3 years ago

1.1.5-alpha.2

3 years ago

1.1.5-alpha.3

3 years ago

1.1.5-alpha.4

3 years ago

1.1.5-alpha.5

3 years ago

1.1.5-labs.1

3 years ago

1.1.3-c

3 years ago

1.1.3-b

3 years ago

1.1.5-beta.0

3 years ago

1.1.5-alpha.0

3 years ago

1.1.5-alpha.1

3 years ago

1.1.5

3 years ago

1.1.3-a

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago