New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@speechify/api-sdk

Package Overview
Dependencies
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@speechify/api-sdk

Official Speechify AI API SDK

  • 2.4.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3.9K
increased by60.18%
Maintainers
5
Weekly downloads
 
Created
Source

Speechify API Node.js SDK

This is the official Node.js SDK for the Speechify API.

Read the SDK full reference here.

Read the REST API documentation here.

Installation

npm install @speechify/api-sdk

Usage

Server-Side Audio Generation

import { Speechify } from "@speechify/api-sdk";

const speechify = new Speechify({
	apiKey: "YOUR_API_KEY",
});

const text = "Hello, world!";
const response = await speechify.audioGenerate({
	input: text,
	voiceId: "george",
	audioFormat: "mp3",
});
const audio = response.audioData;

someStorage.saveFile("audio.mp3", audio);

Server-Side Auth Token Generation

import { Speechify } from "@speechify/api-sdk";

const speechify = new Speechify({
	apiKey: "YOUR_API_KEY",
});

webServer.post("/speechify-token", async (req, res) => {
	const user = req.user;
	if (!user) {
		res.status(401).send("Unauthorized");
		return;
	}
	const tokenResponse = await speechify.accessTokenIssue("audio:all");
	res.json(tokenResponse);
});

Client-Side Audio Generation

import { Speechify } from "@speechify/api-sdk";

const speechify = new Speechify();

authSystem.on("login", async () => {
	const res = await fetch("/speechify-token", {
		method: "POST",
	});
	const tokenResponse = await res.json();

	speechify.setAccessToken(tokenResponse.accessToken);
});

generateButton.addEventListener("click", async () => {
	const text = "Hello, world!";
	const response = await speechify.audioGenerate({
		input: text,
		voiceId: "george",
		audioFormat: "mp3",
	});
	const audio = response.audioData;

	const audioElement = new Audio();
	audioElement.src = URL.createObjectURL(
		new Blob([audio], { type: "audio/mpeg" }),
	);
	audioElement.play();
});

Client-Side Access Token Auto-Management

You can use the provided SpeechifyAccessTokenManager class to have the access token fully managed, including the auto-refresh before it expires.

import { Speechify, SpeechifyAccessTokenManager } from "@speechify/api-sdk";

const speechify = new Speechify();

const getToken = async () => {
	const res = await fetch("/speechify-token", {
		method: "POST",
	});
	return res.json();
};

const tokenManager = new SpeechifyAccessTokenManager(speechify, getToken, {
	isAuthenticated: authSystem.isAuthenticated,
});

authSystem.on("login", () => {
	tokenManager.setIsAuthenticated(true);
});

authSystem.on("logout", () => {
	tokenManager.setIsAuthenticated(false);
});

With this setup in place, you can use the speechify client without worrying about the access token management.

Speechify Embeddable UI Package

The Speechify Embeddable UI package provides an intuitive player component that lets you add text-to-speech functionality to your web application with minimal setup. By initializing the Speechify client from the API SDK and then calling the player’s setup function, you can embed a customizable element into your HTML. This player supports both traditional speech generation and real-time streaming, offering flexibility with attributes such as content, voice-id, and generation type.

Here is a complete example of how to integrate the Speechify player into your application:

import { initializePlayer } from "@speechify/embeddable-ui";

// call init function with speechify sdk instance
initializePlayer(speechify);
<speechify-player
	content="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
	voice-id="george"
	generation-type="stream"
/>

Please, refer to the Speechify Embeddable UI package for more information.

Keywords

FAQs

Package last updated on 18 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc