Skip to main content

Authentication (Javascript)

Javascript library for managing access to Speechmatics APIs, including generating JWTs for authentication.

See our guide to temporary keys for more details.

Installation

npm i @speechmatics/auth

Usage

import { RealtimeClient } from '@speechmatics/real-time-client';
import { createSpeechmaticsJWT } from '@speechmatics/auth';

const client = new RealtimeClient();

client.addEventListener('receiveMessage', ({ data }) => {
  // Handle transcription messages
});

async function transcribeFileRealtime () {
  const jwt = await createSpeechmaticsJWT({
    type: 'rt',
    apiKey,
    ttl: 60, // 1 minute
  });

  const fileStream = fs.createReadStream(
    path.join(__dirname, './example.wav'),
    {
      highWaterMark: 4096, //avoid sending faster than realtime
    },
  );

  await client.start(jwt, {
    transcription_config: {
      language: 'en',
      enable_partials: true,
    },
  });

  //send it
  fileStream.on('data', (sample) => {
    client.sendAudio(sample);
  });

  //end the session
  fileStream.on('end', () => {
    client.stopRecognition();
  });
}

transcribeFileRealtime();

Source on GitHub

Source code can be found on GitHub.