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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dvoice-tts

v1.0.3

Published

Node.js & TypeScript client for DVoice TTS API

Readme

dvoice-tts

A Node.js + TypeScript client for the DVoice TTS API, enabling text-to-speech conversion with support for single audio generation and real-time audio streaming via WebSocket.

🚀 Features

  • Generate audio files in multiple formats (mp3, wav, ogg, aac, flac).
  • Stream audio in real-time for dynamic applications.
  • Simple and intuitive API for quick integration.
  • TypeScript support for type-safe development.

📦 Installation

Install the package using npm:

npm install dvoice-tts

🧠 Usage

Importing the Client

import { TTS } from "dvoice-tts";

Creating a Client

Initialize the TTS client with your API token:

const tts = new TTS({ token: "YOUR_API_TOKEN" });

Replace 'YOUR_API_TOKEN' with your actual API token from the DVoice TTS service.

Obtaining an API Token

To use the DVoice TTS API, you need a valid API token. Visit the main website at dvoice.uz and navigate to profile.dvoice.uz to create an account or log in. Once logged in, you can generate or retrieve your API token from your profile dashboard.

🔊 Generating a Single Audio File

Use the single() method to generate an audio file from text:

import * as fs from "fs";

async function generateAudio() {
  try {
    const audio = await tts.single({
      model: "default",
      text: "Salom!",
      format: "mp3", // Options: 'mp3', 'wav', 'ogg', 'aac', 'flac'
    });
    fs.writeFileSync("output.mp3", audio);
    console.log("Audio file saved as output.mp3");
  } catch (error) {
    console.error("Error generating audio:", error);
  }
}

generateAudio();

🌊 Real-Time Audio Streaming

Use the stream() method to receive audio chunks in real-time:

tts.stream(
  {
    model: "default",
    text: "Davomiy nutqni real vaqtda translatsiya qilish!",
    format: "mp3", // Options: 'mp3', 'wav', 'ogg', 'aac', 'flac'
  },
  (err, chunk, close) => {
    if (err) {
      console.error("Stream error:", err);
      close(); // Close the connection on error
    } else if (chunk) {
      // Process the audio chunk (e.g., feed to an audio player)
      console.log("Received audio chunk:", chunk.length, "bytes");
    } else {
      // Stream has ended
      console.log("Stream completed");
      close(); // Close the connection
    }
  }
);

The close() function can be called to terminate the WebSocket connection manually.

📜 API Reference

new TTS(options)

Creates a new TTS client instance.

  • Parameters:
    • options.token (string): Your API token for DVoice TTS authentication.

tts.single(options)

Generates a single audio file from text.

  • Parameters:
    • options.model (string): The TTS model to use (e.g., 'default').
    • options.text (string): The text to convert to speech.
    • options.format (string): Audio format ('mp3', 'wav', 'ogg', 'aac', 'flac').
  • Returns: Promise<Buffer> - A promise resolving to a Buffer containing the audio data.
  • Throws: Error if the request fails.

tts.stream(options, callback)

Streams audio chunks in real-time over WebSocket.

  • Parameters:
    • options.model (string): The TTS model to use (e.g., 'default').
    • options.text (string): The text to convert to speech.
    • options.format (string): Audio format ('mp3', 'wav', 'ogg', 'aac', 'flac').
    • callback (function): Called with (err, chunk, close):
      • err (Error | null): Any error that occurs.
      • chunk (Buffer | null): Audio data chunk, or null if the stream ends.
      • close (function): Function to close the WebSocket connection.
  • Returns: void

🛠️ Error Handling

Both single() and stream() methods include error handling:

  • For single(), errors are thrown and can be caught using try/catch.
  • For stream(), errors are passed to the callback as the err parameter.

Example:

try {
  const audio = await tts.single({
    model: "default",
    text: "Test",
    format: "mp3",
  });
} catch (error) {
  console.error("Failed to generate audio:", error.message);
}

📝 Notes

  • Ensure a valid API token is provided to authenticate with the DVoice TTS API.
  • The stream() method is ideal for applications requiring low-latency audio, such as live voice assistants or interactive systems.
  • Check the DVoice TTS API documentation for supported models and additional configuration options.

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

🌟 Contributing

Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository for bug reports, feature requests, or improvements.