# Gtts

Google Text-to-Speech (gTTS) for converting text to audio.

- Repository: https://github.com/benchflow-ai/skillsbench (1888 stars)
- Category: Media
- License: Apache-2.0
- Last updated: 2026-10-24
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add benchflow-ai/skillsbench --skill gtts -g -a claude-code -y`
Codex: `npx skills add benchflow-ai/skillsbench --skill gtts -g -a codex -y`
Cursor: `npx skills add benchflow-ai/skillsbench --skill gtts -g -a cursor -y`
Gemini CLI: `npx skills add benchflow-ai/skillsbench --skill gtts -g -a gemini-cli -y`

## Description

Google Text-to-Speech (gTTS) for converting text to audio. Use when creating audiobooks, podcasts, or speech synthesis from text. Handles long text by chunking at sentence boundaries and concatenating audio segments with pydub.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Google Text-to-Speech (gTTS)

gTTS is a Python library that converts text to speech using Google's Text-to-Speech API. It's free to use and doesn't require an API key.

## Installation

```bash
pip install gtts pydub
```

pydub is useful for manipulating and concatenating audio files.

## Basic Usage

```python
from gtts import gTTS

# Create speech
tts = gTTS(text="Hello, world!", lang='en')

# Save to file
tts.save("output.mp3")
```

## Language Options

```python
# US English (default)
tts = gTTS(text="Hello", lang='en')

# British English
tts = gTTS(text="Hello", lang='en', tld='co.uk')

# Slow speech
tts = gTTS(text="Hello", lang='en', slow=True)
```

## Python Example for Long Text

```python
from gtts import gTTS
from pydub import AudioSegment
import tempfile
import os
import re

def chunk_text(text, max_chars=4500):
    """Split text into chunks at sentence boundaries."""
    sentences = re.split(r'(?<=[.!?])\s+', text)
    chunks = []
    current_chunk = ""

    for sentence in sentences:
        if len(current_chunk) + len(sentence) < max_chars:
            current_chunk += sentence + " "
        else:
            if current_chunk:
                chunks.append(current_chunk.strip())
            current_chunk = sentence + " "

    if current_chunk:
        chunks.append(current_chunk.strip())

    return chunks


def text_to_audiobook(text, output_path):
    """Convert long text to a single audio file."""
    chunks = chunk_text(text)
    audio_segments = []

    for i, chunk in enumerate(chunks):
        # Create temp file for this chunk
        with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as tmp:
            tmp_path = tmp.name

        # Generate speech
        tts = gTTS(text=chunk, lang='en', slow=False)
        tts.save(tmp_path)

        # Load and append
        segment = AudioSegment.from_mp3(tmp_path)
        audio_segments.append(segment)

        # Cleanup
        os.unlink(tmp_path)

The rest: https://github.com/benchflow-ai/skillsbench/blob/HEAD/tasks-extra/pg-essay-to-audiobook/environment/skills/gtts/SKILL.md
