The Speechify Text to Speech API SDK allows developers to integrate high-quality, natural-sounding text-to-speech (TTS) capabilities into applications with minimal effort. It offers a streamlined way to convert text into audio on both server and client-side environments.
Try the PlayHT text to speech API for free. With a much lower latency than Speechify, and much higher voice quality, PlayHT is perfect for streaming or anything your business demands.
To use the Speechify SDK, you’ll need:
Install the Speechify API SDK via npm:
npm install @speechify/api-sdk
This package provides tools for interacting with the Speechify API.
Before making any requests, authenticate using the API key:
const Speechify = require('@speechify/api-sdk');
// Initialize the SDK with your API key
const speechify = new Speechify({
apiKey: 'YOUR_API_KEY',
});
Once authenticated, you can easily generate speech from text. Here’s a simple example:
async function textToSpeech() {
const result = await speechify.createAudio({
text: 'Hello, world!',
voice: 'en_us_male', // Specify voice preference
format: 'mp3', // Output format
});
console.log('Audio URL:', result.audioUrl); // URL to download or play the audio
}
textToSpeech();
This code converts the text “Hello, world!” into an MP3 audio file using the selected voice.
Handling potential issues ensures a smooth user experience. Example error handling:
try {
await speechify.createAudio({
text: '',
voice: 'en_us_female',
});
} catch (error) {
console.error('Error generating audio:', error.message);
}
This ensures graceful failures if, for example, no text is provided or the API limit is reached.
The SDK automatically handles authentication token renewal, which simplifies long-running processes that require continuous interaction with the API.
Keep in mind that Speechify API might have rate limits depending on your plan. It’s a good idea to cache or batch your requests when dealing with high volumes of text.
By integrating the Speechify API SDK, you can enhance your application with seamless text-to-speech conversion, offering users an auditory alternative to textual content. For more detailed API reference, visit the official documentation.
This guide introduces the SDK, walks through setup, and offers practical tips for optimal use.