SDK: New Typescript SDK

We’ve published a new Typescript SDK. Try it out:

$npm install @speechify/api

Together with the release, the old @speechify/api-sdk package is now deprecated.

Migrating from @speechify/api-sdk

The JWT-based authentication endpoint has been deprecated. This means that the auto-refresh token feature has also been removed in the new SDK.

  • How to call individual endpoints is available in the API Explorer. Switch to the Typescript SDK tab to see the snippet.
  • The full implementation of the new SDK is available in the GitHub repository.

Quick Start Guide

1

Install the SDK

Install the package using npm:

$npm install @speechify/api
2

Initialize the Client

Import the SDK and create a new client instance:

1import { SpeechifyClient } from "@speechify/api";
2
3// API Key can also be set as an environment variable SPEECHIFY_API_KEY
4const client = new SpeechifyClient({ apiKey: "your-api-key" });
3

Fetch Available Voices

Get a list of all available voices:

1const voices = await client.tts.voices.list();
4

Generate Speech

Create a new speech synthesis request using a voice:

1const result = await client.tts.audio.speech({
2 voiceId: voices[0].id,
3 input: "Hello, world!",
4});
5

Save the Audio

This is now an additional required step since the SDK only returns the raw audio data i.e. a string representing the base64 encoded bytes. Convert the audio data and save it to a file:

1const audioData = result.audioData;
2const audioBuffer = Buffer.from(audioData, "base64");
3
4// Write the binary data to a file
5fs.writeFileSync("speech.mp3", audioBuffer);

API: Deprecated POST /v1/auth/token endpoint

The POST /v1/auth/token endpoint is now deprecated. We will only support API Key authentication moving forward.