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-remote

v0.0.1

Published

Remote HTTP TTS player for Charivo (client-side)

Readme

@charivo/tts-player-remote

Remote HTTP TTS player for Charivo framework (client-side).

⚠️ Important Security Note

This is a client-side HTTP player that calls your server API endpoint, NOT external TTS APIs directly. This design keeps your API keys secure on the server side.

Architecture

Browser/Client → RemoteTTSPlayer → Your Server API → External TTS API (OpenAI, etc.)

Installation

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

Usage

1. Client-side Setup

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

const player = createRemoteTTSPlayer({
  apiEndpoint: "/api/tts", // Your server endpoint
  defaultVoice: "alloy",
  defaultModel: "tts-1-hd"
});

// Wrap with TTSManager
const ttsManager = createTTSManager(player);
await ttsManager.speak("Hello, world!");

2. Server-side Implementation (Required)

You must implement a server endpoint that handles the actual TTS API calls. Use @charivo/tts-provider-openai for easy setup:

OpenAI TTS Backend Example

// app/api/tts/route.ts (Next.js)
import { NextRequest, NextResponse } from "next/server";
import { createOpenAITTSProvider } from "@charivo/tts-provider-openai";

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

export async function POST(request: NextRequest) {
  try {
    const { text, voice = "alloy", model = "tts-1" } = await request.json();

    const audioBuffer = await provider.generateSpeech(text, { voice, model });

    return new NextResponse(audioBuffer, {
      headers: {
        "Content-Type": "audio/mpeg",
        "Content-Length": audioBuffer.byteLength.toString(),
      },
    });
  } catch (error) {
    console.error("TTS API Error:", error);
    return NextResponse.json(
      { error: "Failed to generate speech" },
      { status: 500 }
    );
  }
}

API Reference

Constructor

new RemoteTTSPlayer(config: RemoteTTSConfig)

Configuration Options

interface RemoteTTSConfig {
  /** Server API endpoint (default: "/api/tts") */
  apiEndpoint?: string;
  /** Default voice (depends on your server implementation) */
  defaultVoice?: string;
  /** Default model (depends on your server implementation) */
  defaultModel?: string;
  /** Request timeout in ms (default: 30000) */
  timeout?: number;
}

Methods

speak(text)

Convert text to speech by calling your server endpoint.

await player.speak("Hello, world!");

stop()

Stop current playback.

await player.stop();

stop()

Stop current playback.

await player.stop();

Backend-specific Usage

For OpenAI TTS Backend

const player = createRemoteTTSPlayer({
  apiEndpoint: "/api/tts",
  defaultVoice: "alloy", // OpenAI voices: alloy, echo, fable, onyx, nova, shimmer
  defaultModel: "tts-1-hd"
});

For Custom Backend

const player = createRemoteTTSPlayer({
  apiEndpoint: "/api/custom-tts",
  defaultVoice: "custom-voice-id",
});

Complete Example

Client-side

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

const charivo = new Charivo();

const player = createRemoteTTSPlayer({
  apiEndpoint: "/api/tts"
});
const ttsManager = createTTSManager(player);

charivo.attachTTS(ttsManager);

// Use it
await charivo.userSay("Hello!", "assistant");

Server-side (Next.js)

// app/api/tts/route.ts
import { NextRequest, NextResponse } from "next/server";
import { createOpenAITTSProvider } from "@charivo/tts-provider-openai";

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

export async function POST(request: NextRequest) {
  const { text, voice, model } = await request.json();
  const audioBuffer = await provider.generateSpeech(text, { voice, model });
  
  return new NextResponse(audioBuffer, {
    headers: { "Content-Type": "audio/mpeg" }
  });
}

Error Handling

try {
  await player.speak("Hello world!");
} catch (error) {
  console.error("TTS failed:", error);
  // Handle network errors, server errors, etc.
}

Why Use Remote Player?

Security ✅

  • API keys stay on server
  • No client-side key exposure
  • Secure token-based authentication possible

Flexibility ✅

  • Switch TTS providers without client changes
  • Server-side caching
  • Rate limiting and monitoring
  • Custom audio processing

Cost Control ✅

  • Monitor and limit usage
  • Implement quotas per user
  • Cache common phrases

Related Packages

License

MIT