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

@charivo/tts-player-openai

v0.0.1

Published

OpenAI TTS player for Charivo (local/testing)

Readme

@charivo/tts-player-openai

OpenAI TTS player for Charivo (direct API access).

⚠️ Security Warning

This player directly calls OpenAI TTS API from the client. Only use for development/testing or in trusted environments. For production, use @charivo/tts-player-remote to keep API keys secure on the server.

Installation

pnpm add @charivo/tts-player-openai @charivo/core openai

Usage

Basic Setup

import { createOpenAITTSPlayer } from "@charivo/tts-player-openai";
import { createTTSManager } from "@charivo/tts-core";

// ⚠️ API key will be visible in client code
const player = createOpenAITTSPlayer({
  apiKey: "your-openai-api-key", // NOT SECURE
  voice: "alloy"
});

const ttsManager = createTTSManager(player);
await ttsManager.initialize();
await ttsManager.speak("Hello, world!");

Configuration

const player = createOpenAITTSPlayer({
  apiKey: "your-api-key",
  voice: "nova",        // alloy, echo, fable, onyx, nova, shimmer
  model: "tts-1-hd"     // tts-1 or tts-1-hd
});

API Reference

Constructor

new OpenAITTSPlayer(config: OpenAITTSPlayerConfig)

Config:

  • apiKey: string - Your OpenAI API key (required)
  • voice?: string - Voice to use (default: "alloy")
  • model?: string - Model to use (default: "tts-1")

Methods

initialize()

Initialize the player.

await player.initialize();

speak(text)

Convert text to speech.

await player.speak("Hello!");

stop()

Stop current playback.

await player.stop();

destroy()

Clean up the player.

await player.destroy();

Available Voices

  • alloy - Neutral, balanced
  • echo - Clear, expressive
  • fable - Warm, engaging
  • onyx - Deep, authoritative
  • nova - Bright, energetic
  • shimmer - Gentle, soothing

Available Models

  • tts-1 - Standard quality (faster, cheaper)
  • tts-1-hd - High quality (slower, more expensive)

Security Best Practices

❌ Not Recommended (Client-side)

// API key exposed to users!
const player = createOpenAITTSPlayer({
  apiKey: "sk-..." // Anyone can see this in DevTools
});

✅ Recommended (Server-side)

Use remote player + provider pattern:

Client:

import { createRemoteTTSPlayer } from "@charivo/tts-player-remote";

const player = createRemoteTTSPlayer({
  apiEndpoint: "/api/tts" // No API key here!
});

Server:

import { createOpenAITTSProvider } from "@charivo/tts-provider-openai";

const provider = createOpenAITTSProvider({
  apiKey: process.env.OPENAI_API_KEY // Secure!
});

export async function POST(request) {
  const { text } = await request.json();
  const audioBuffer = await provider.generateSpeech(text);
  return new Response(audioBuffer);
}

When to Use

Use OpenAI TTS Player when:

  • 🧪 Prototyping or testing
  • 🏠 Personal projects
  • 🔒 Running in trusted environment (e.g., Electron app)

Use Remote Player when:

  • 🌐 Production web apps
  • 👥 Multi-user applications
  • 💰 Need to control costs
  • 🔐 Security is important

Pricing

Same as OpenAI TTS API:

  • tts-1: $15.00 per 1M characters
  • tts-1-hd: $30.00 per 1M characters

Error Handling

try {
  await player.speak("Hello!");
} catch (error) {
  if (error.code === "insufficient_quota") {
    console.error("OpenAI quota exceeded");
  } else if (error.code === "invalid_api_key") {
    console.error("Invalid API key");
  } else {
    console.error("TTS error:", error);
  }
}

Related Packages

License

MIT