Skip to main content

Text-to-speech synthesis using the Google Translate TTS API and pygame.

Project description

About

A lightweight fork of the google_speech library, that replaces sox with pygame and removes sound effects for a lightweight and straightforward implementation.

Table of Contents

Installation

pip install google_speech_pyplay

Usage

The library provides both a Command-Line Interface (CLI) and an API for programmatic use.

Command-Line Interface (CLI)

You can use the google_speech_pyplay command directly from the terminal:

python -m google_speech_pyplay "Hello, world!" -l en

Options:

  • -l, --lang: Specify the language (e.g., en for English, es for Spanish).
  • -o, --output: Save the speech output to an MP3 file instead of playing it.

Example: Save to File

Save the text-to-speech output to output.mp3:

python -m google_speech_pyplay "Hello, world!" -l en -o output.mp3

Python Code Examples

Here are some examples of how to use the library in Python scripts.

Example 1: Play Text-to-Speech

from google_speech_pyplay import Speech

# Specify the text and language
text = "Hello, world!"
language = "en"

# Create a Speech object and play the text
speech = Speech(text, language)
speech.play()

Example 2: Save Speech to a File

from google_speech_pyplay import Speech

# Specify the text and language
text = "Hola, mundo!"
language = "es"

# Create a Speech object and save the speech to an MP3 file
speech = Speech(text, language)
speech.save("output.mp3")

Setting Up Development Environment

To set up a fresh development environment for the google_speech_pyplay project, follow these steps:

Prerequisites

  1. Ensure you have Python 3.10 or newer installed.
  2. Install pip (comes bundled with Python) and upgrade it to the latest version:
    python3 -m pip install --upgrade pip
    

Steps to Set Up the Environment

  1. Clone the repository:

    git clone https://github.com/KarimAziev/google_speech_pyplay.git
    cd google_speech_pyplay
    
  2. Create and activate a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate  # For Linux/Mac
    # or
    .venv\Scripts\activate     # On Windows
    
  3. Upgrade core tools inside the virtual environment:

    pip install --upgrade pip setuptools wheel
    
  4. Install the project in editable (development) mode with all dependencies:

    pip install -e ".[dev]"  # Includes dev dependencies like black, pre-commit, isort
    

Building the Project

To build the project for distribution, e.g., creating .tar.gz and .whl files:

  1. Install the build tool:

    pip install build
    
  2. Build the distribution:

    python -m build
    

This will generate a dist/ directory containing the following artifacts:

  • Source distribution (google_speech_pyplay-x.y.z.tar.gz)
  • Wheel file (google_speech_pyplay-x.y.z-py3-none-any.whl)

You can install these locally for testing or upload them to PyPI for publishing.


Common Commands

  • Clean build artifacts:
    rm -rf build dist *.egg-info
    
  • Deactivate virtual environment:
    deactivate
    

Notes

  • This project uses setuptools_scm to handle versioning, based on the Git tags of the repository. Ensure you use proper semver tags like v1.0.0 to manage versions correctly.
  • Dev dependencies (like black, isort) are automatically installed when running pip install -e ".[dev]".

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

google_speech_pyplay-1.0.15.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

google_speech_pyplay-1.0.15-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file google_speech_pyplay-1.0.15.tar.gz.

File metadata

  • Download URL: google_speech_pyplay-1.0.15.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for google_speech_pyplay-1.0.15.tar.gz
Algorithm Hash digest
SHA256 44dbe3bed7935685224bc984fa8261018bcf1cc68c5a92a123e124caf5dc9ef9
MD5 9bd2ccee551e6638ea2a2ad8871f3b1f
BLAKE2b-256 fa1b5c7fc47b8a55a6dd0a57d73c8d75166576ae3bd4cbaef49146960a38bfb3

See more details on using hashes here.

File details

Details for the file google_speech_pyplay-1.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for google_speech_pyplay-1.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 cf58e81974bf9720f2ea3f41463bcfa2bf3d5491ebf806f350123c93ece740c6
MD5 17f31d7407d323aac893727e62e0f56d
BLAKE2b-256 ee3c7af074d635347b0355469a363bc2a95bcf7ebc18d1f269ad1fa82d0c3100

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page