openai-fm-tts
v1.0.3
Published
A TypeScript module for generating Text-to-Speech audio via an unofficial, publicly accessible /generate route on https://www.openai.fm/. Supports customizable voices and vibes, with audio output in WAV or MP3 formats.
Readme
openai-fm-tts
A TypeScript module for generating Text-to-Speech (TTS) audio using an unofficial, publicly accessible /generate route on https://www.openai.fm/. This package allows customization of voices and vibes, with support for saving audio in WAV or MP3 formats.
Note: This module uses an undocumented API endpoint, which may not be officially supported or guaranteed to remain available.
Features
- Generate TTS audio with customizable voices (e.g., Alloy, Nova, Shimmer).
- Apply unique "vibes" (e.g., Pirate, Cyberpunk Hacker, Fairy Tale Narrator) to alter tone, emotion, and style.
- Save audio output in WAV or MP3 formats using FFmpeg for MP3 conversion.
- TypeScript support with comprehensive type definitions.
- Modular design compatible with Bun and Node.js environments.
Installation
npm install openai-fm-ttsEnsure you have the following dependencies installed:
- TypeScript (>=5.0.0)
- FFmpeg (required for MP3 output)
Usage
Generating TTS and Saving Audio
import { generateTTS, saveAudio, Voice, VibeList, vibes } from "openai-fm-tts";
const vibePerson = vibes[VibeList.SciFiCommander];
async function example() {
try {
const { audio, filename } = await generateTTS({
input: "Welcome to the future!",
voice: Voice.Echo,
vibe: vibePerson.name,
});
const outputPath = await saveAudio({ audio, filename }, "output", "mp3");
console.log(`Audio saved to: ${outputPath}`);
} catch (error) {
console.error("Error:", error);
}
}
example();API
generateTTS(request: GenerateRequest): Promise<GenerateResponse>
Generates TTS audio by sending a request to the /generate endpoint.
- Parameters:
input: The text to convert to speech.prompt: Optional custom prompt for additional context.voice: Optional voice selection (defaults toVoice.Nova).vibe: Optional vibe to apply (e.g.,VibeList.Pirate).
- Returns: A promise resolving to
{ audio: ArrayBuffer | Uint8Array, filename: string }.
saveAudio(response: GenerateResponse, outputPath: string, format: "wav" | "mp3"): Promise<string>
Saves the generated audio to a file.
- Parameters:
response: The response fromgenerateTTS.outputPath: The desired file path (without extension).format: The output format (wavormp3).
- Returns: A promise resolving to the saved file path.
Voices and Vibes
Voices
Available voices include: Alloy, Ash, Ballad, Coral, Echo, Fable, Onyx, Nova, Sage, Shimmer, Verse.
Vibes
Vibes add personality to the audio, such as:
Medieval Knight: Noble and heroic.Pirate: Boisterous with seafaring charm.Cyberpunk Hacker: Edgy and tech-savvy.Fairy Tale Narrator: Whimsical and magical.- See
VibeListenum for the full list.
Requirements
- Node.js or Bun runtime.
- FFmpeg installed for MP3 conversion.
- TypeScript for development (optional but recommended).
tsupfor building the project (required for thebuildscript).
Building
npm run buildThis compiles the TypeScript source to JavaScript in the dist/ directory and generates type declarations in the dist/index.d.ts file.
Disclaimer
This package relies on an unofficial API endpoint (/generate) from https://www.openai.fm/, which is publicly accessible but not documented. Usage of this endpoint may be subject to change or discontinuation without notice.
License
MIT
