npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elevenlabs-ts

v1.1.0

Published

text to speech and other elevan labs api

Downloads

347

Readme

# elevenlabs-ts

`elevenlabs-ts` is a TypeScript client library for interfacing with the [Eleven Labs](https://elevenlabs.io/?from=partnermorris7332) API,
 which offers a range of services related to voice synthesis and text-to-speech (TTS) capabilities.

Requirements

To use this package you will need an elevanlabs api, if you don't one have one create one:

elevanlabs.io

Then tap on the Profile Image, there you can generate API details elevan labs > profile, API key

Elevan labs has a free tier, with high quality audio and up to 10,000 characters, for commercial use upgrade to paid tier

Installation

To use the elevenlabs-ts package in your project, run:

npm install elevenlabs-ts

Or if you prefer using Yarn:

yarn add elevenlabs-ts

Usage

To get started with the Eleven Labs API client, you need to create an instance of the ElevenLabsAPI class with your API key.

import ElevenLabsAPI from 'elevenlabs-ts';
import fs from 'fs-extra';

const apiKey = 'YOUR_API_KEY';
const elevenLabsAPI = new ElevenLabsAPI(apiKey);

/// to get Voices
    const voices: Voice[] = await elevenLabs.getVoices();
// to get single voice
    const voice: Voice = await elevenLabs.getVoice('voiceId')
// to convert text to speech
    const audio_response: Buffer = await elevenLabs.textToSpeech(VOICE_ID, { text: inputText })
// to save to local disk 
    fs.writeFile('audio.mp3', audio_response)

Methods

Here is an overview of the methods available in the ElevenLabsAPI class:

Text-to-Speech

  • streamTextToSpeech(voiceId: string, options: TextToSpeechOptions): Promise<NodeJS.ReadableStream>
  • textToSpeech(voiceId: string, options: TextToSpeechOptions): Promise<Buffer>

Voice Management

  • getVoices(): Promise<Voice[]>
  • getVoice(voiceId: string, withSettings?: boolean): Promise<Voice>
  • addVoice(data: AddVoiceRequest): Promise<void>
  • editVoice(voiceId: string, data: EditVoiceRequest): Promise<void>
  • deleteVoice(voiceId: string): Promise<void>
  • getVoiceSettings(voiceId: string): Promise<VoiceSettings>
  • editVoiceSettings(voiceId: string, settings: VoiceSettings): Promise<void>

User Information

  • getUserInfo(): Promise<UserInfo>
  • getUserSubscriptionInfo(): Promise<UserSubscriptionInfo>

History

  • getHistoryItemAudio(historyItemId: string): Promise<HistoryAudio>
  • getHistoryItem(historyItemId: string): Promise<HistoryItem>
  • deleteHistoryItem(historyItemId: string): Promise<void>
  • downloadHistoryItems(historyItemIds: string[]): Promise<Buffer>

Models

  • getModels(): Promise<ModelInfo[]>

Default Voice Settings

  • getDefaultVoiceSettings(): Promise<VoiceSettings>

Example

Here's an example of converting text to speech:

async function convertTextToSpeech(text: string) {
  const voiceId = 'voice-id'; // Replace with a valid voice ID
  const writer = fs.createWriteStream('stream.mp3')
  const stream = await elevenLabsAPI.streamTextToSpeech(voiceId, {text: text});
  // Handle the stream, e.g., save to a file or play audio
  writer.pipe(stream)
}
convertTextToSpeech('Hello, world!');
async function textToSpeech(text: string) {
  const voiceId = 'voice-id'; // Replace with a valid voice ID
  const response: Buffer = await elevenLabsAPI.textToSpeech(voiceId, {text: text});
  // Handle the stream, e.g., save to a file or play audio
  fs.createFile('audio.mp3', reponse)
}
textToSpeech('Hello, world!');

Environment Variables

The library uses the following environment variable for the API base URL:

  • API_BASE_URL - The base URL for the Eleven Labs API. If not set, the default is https://api.elevenlabs.io/v1.

Response and Error Handling

All methods return a promise that resolves to the requested data or throws an error in case of failure. Make sure to handle these appropriately in your application.

Contributing

We welcome contributions to the elevenlabs-ts package. Please read the contributing guidelines before submitting your PR.

License

This project is licensed under the MIT License.

Disclaimer

This package is not officially maintained by Eleven Labs. Please use it at your own risk. All links to Eleven Labs may result in an affiliate commission

Make sure to replace `YOUR_API_KEY` with the actual API key provided to you by 

Eleven Labs.