partai-tts
v1.0.8
Published
PartAI Text-to-Speech (TTS) Node.js & TypeScript Package
Downloads
413
Readme
PartAI Text-to-Speech (TTS) Node.js & TypeScript API
This package provides a simple interface for interacting with the PartAI Text-to-Speech API. It allows you to convert short and long text to speech using various settings and provides functions to track and retrieve the audio files generated from the API.
Installation
npm install partai-tts
Prerequisites
To use this package, you'll need an API key. You can obtain it from the PartAI publisher dashboard.
Documentation
For detailed documentation on the API, please refer to the official service documentation.
Note: This package is not officially maintained by PartAI.
Usage
Here’s how to use the partai-tts
package in your code:
Import and Initialize the Client
import PartaiTTS from 'partai-tts';
const gatewayToken = 'YOUR_API_KEY';
const ttsClient = new PartaiTTS(gatewayToken);
Convert Short Text to Speech
async function shortTextExample() {
try {
const response = await ttsClient.shortTextToSpeech("Hello, world!", 1, 1, true, false, true);
console.log("Short Text Response:", response);
} catch (error) {
console.error("Error converting short text to speech:", error);
}
}
shortTextExample();
Convert Long Text to Speech
async function longTextExample() {
try {
const response = await ttsClient.longTextToSpeech("This is a longer text to convert.", 1, 1);
console.log("Long Text Response:", response);
// Track the status of the conversion process
const status = await ttsClient.checkLongTextStatus(response.token);
console.log("File Status:", status);
// Once complete, retrieve the file link
if (status.status === 'complete') {
const fileLink = await ttsClient.getProcessedLongTextFile(status.endpoint);
console.log("File Link:", fileLink);
}
} catch (error) {
console.error("Error converting long text to speech:", error);
}
}
longTextExample();
API Reference
constructor(gatewayToken: string, baseUrl: string)
- gatewayToken: Your API gateway token.
- baseUrl: The base URL for the API. Defaults to
https://partai.gw.isahab.ir/TextToSpeech/v1
.
shortTextToSpeech(data: string, speaker?: number, speed?: number, filePath?: boolean, base64?: boolean, checksum?: boolean): Promise<SpeechResponse>
Converts short text to speech.
- data: The text to convert to speech.
- speaker: Speaker ID (default is
1
). - speed: Speech speed (default is
1
). - filePath: Whether to return the file path (default is
true
). - base64: Whether to return audio as base64 (default is
false
). - checksum: Whether to include a checksum (default is
true
).
longTextToSpeech(data: string, speaker?: number, speed?: number): Promise<LongTextToSpeechResponse>
Converts long text to speech. Requires tracking status for completion.
checkLongTextStatus(token: string): Promise<FileStatusResponse>
Checks the status of a long text-to-speech conversion.
- token: Token for the conversion job.
getProcessedLongTextFile(endpoint: string): Promise<FileLinkResponse>
Retrieves the download link for a completed long text-to-speech file.
- endpoint: The endpoint or token for the processed file.
License
MIT License