Socket
Book a DemoInstallSign in
Socket

gtts

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gtts

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

GTTS Ruby

A Ruby library and CLI tool to interface with Google Translate's Text-to-Speech API. This is a Ruby port of the Python gTTS library.

Installation

Add this line to your application's Gemfile:

gem 'gtts'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install gtts

Usage

As a Library

require 'gtts'

# Simple example
tts = Gtts::GTTS.new("Hello World")
tts.save("hello.mp3")

# More options
tts = Gtts::GTTS.new(
  "Hola Mundo",
  lang: "es",     # Language
  tld: "com.mx",  # Top-level domain
  slow: true      # Slower speed
)
tts.save("hola.mp3")

# Stream the audio data
tts.stream do |audio_chunk|
  # Process audio data chunks
  # For example, write to a file
  File.open("output.mp3", "ab") { |f| f.write(audio_chunk) }
end

# Check supported languages
Gtts.languages.each do |code, name|
  puts "#{code}: #{name}"
end

# Check if a language is supported
puts Gtts.language_supported?("es") # true
puts Gtts.language_supported?("xx") # false

Command Line Tool

The gem comes with a command-line tool called gtts-cli:

# Basic usage
gtts-cli "Hello World" -o hello.mp3

# Specify language
gtts-cli "Hola Mundo" -l es -o hola.mp3

# Read from file
gtts-cli -f input.txt -o output.mp3

# List available languages
gtts-cli --list-langs

# Show all options
gtts-cli --help

CLI Options

  • -f, --file FILE : Read text from file
  • -o, --output FILE : Output file (default: output.mp3)
  • -l, --lang LANG : Language (default: en)
  • -t, --tld TLD : Top-level domain for Google Translate
  • -s, --slow : Speak more slowly
  • --list-langs : List available languages
  • --debug : Debug mode
  • -h, --help : Show help message

Supported Languages

The library supports multiple languages. Use gtts-cli --list-langs to see all available languages or check Gtts.languages in your code.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 04 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.