penguinTTS v1

Text-to-Speech API

A lightweight, client-side TTS library that turns text into natural speech using your browser's built-in Web Speech API. No API keys, no servers, no install—just include one script and call tts.speak().


Getting Started

Include the script anywhere in your page:

<script src="https://penguinai.pages.dev/api/tts.js"></script>

Initialize voices and speak:

<script>
  await tts.init();
  await tts.speak('Hello, world!');
</script>

That's it. The library auto-selects the most natural-sounding voice available on the user's system (Google, Apple, or Microsoft neural voices).


API Reference

await tts.init()

Loads available voices and picks the best default. Call once before speaking. Returns the voice array.

await tts.speak(text, options?)

Speaks the given text. Returns a Promise that resolves when speech ends. Options:

  • voice — a SpeechSynthesisVoice object
  • rate — speaking rate (0.1–10, default 0.9)
  • pitch — voice pitch (0.2–2, default 1.0)
  • volume — output volume (0–1, default 0.85)
tts.stop()

Immediately stops any ongoing speech and cancels queued utterances.

tts.pause() · tts.resume()

Pause and resume speech mid-utterance.

tts.getVoices(locale?)

Returns all available voices, optionally filtered by locale (e.g. "en-US").

tts.setVoice(voice)

Sets the default voice for subsequent speak() calls. Pass a SpeechSynthesisVoice object.

tts.setRate(n) · tts.setVolume(n)

Set default rate (0.1–10) or volume (0–1).

tts.setPreset(name)

Applies a voice preset that sets rate, pitch, volume and auto-selects the best matching voice. Presets: penguinAI-david (warm, clear US male) and penguinAI-leo (authoritative British male).

tts.getPresets()

Returns an array of all available preset objects with their id, label, rate, pitch, and volume values.


Examples

Basic usage

<script src="https://penguinai.pages.dev/api/tts.js"></script>
<script>
  (async function () {
    var voices = await tts.init();
    await tts.speak('Welcome to penguinTTS.');
  })();
</script>

Custom voice and rate

var voices = await tts.getVoices('en-GB');
var british = voices.find(function (v) {
  return v.name.includes('Female');
});
await tts.speak('Hello from London!', {
  voice: british,
  rate: 0.85,
  pitch: 1.1
});

Play button

<button id="speak-btn">Speak</button>
<script>
  tts.init();
  document.getElementById('speak-btn')
    .addEventListener('click', function () {
      tts.speak('Hello, world!');
    });
</script>

Playground

Try penguinTTS live with human-like speech. Choose between the penguinAI David preset (warm, clear US male) or penguinAI Leo (authoritative British male). Text is automatically processed for natural-sounding speech with contractions and proper pacing.

Ready
Loading available voices from your browser...