Agent skill
gtts
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.
Install this agent skill to your Project
npx add-skill https://github.com/benchflow-ai/skillsbench/tree/main/tasks/pg-essay-to-audiobook/environment/skills/gtts
SKILL.md
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
pip install gtts pydub
pydub is useful for manipulating and concatenating audio files.
Basic Usage
from gtts import gTTS
# Create speech
tts = gTTS(text="Hello, world!", lang='en')
# Save to file
tts.save("output.mp3")
Language Options
# 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
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)
# Concatenate all segments
combined = audio_segments[0]
for segment in audio_segments[1:]:
combined += segment
# Export
combined.export(output_path, format="mp3")
Handling Large Documents
gTTS has a character limit per request (~5000 chars). For long documents:
- Split text into chunks at sentence boundaries
- Generate audio for each chunk using gTTS
- Use pydub to concatenate the chunks
Alternative: Using ffmpeg for Concatenation
If you prefer ffmpeg over pydub:
# Create file list
echo "file 'chunk1.mp3'" > files.txt
echo "file 'chunk2.mp3'" >> files.txt
# Concatenate
ffmpeg -f concat -safe 0 -i files.txt -c copy output.mp3
Best Practices
- Split at sentence boundaries to avoid cutting words mid-sentence
- Use
slow=Falsefor natural speech speed - Handle network errors gracefully (gTTS requires internet)
- Consider adding brief pauses between chapters/sections
Limitations
- Requires internet connection (uses Google's servers)
- Voice quality is good but not as natural as paid services
- Limited voice customization options
- May have rate limits for very heavy usage
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
csv-processing
Use this skill when reading sensor data from CSV files, writing simulation results to CSV, processing time-series data with pandas, or handling missing values in datasets.
pid-controller
Use this skill when implementing PID control loops for adaptive cruise control, vehicle speed regulation, throttle/brake management, or any feedback control system requiring proportional-integral-derivative control.
yaml-config
Use this skill when reading or writing YAML configuration files, loading vehicle parameters, or handling config file parsing with proper error handling.
simulation-metrics
Use this skill when calculating control system performance metrics such as rise time, overshoot percentage, steady-state error, or settling time for evaluating simulation results.
vehicle-dynamics
Use this skill when simulating vehicle motion, calculating safe following distances, time-to-collision, speed/position updates, or implementing vehicle state machines for cruise control modes.
web-interface-guidelines
Vercel's comprehensive UI guidelines for building accessible, performant web interfaces. Use this skill when reviewing or building UI components for compliance with best practices around accessibility, performance, animations, and visual stability.
Didn't find tool you were looking for?