About
A lightweight fork of the google_speech library, that replaces sox with pygame-ce 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.,enfor English,esfor 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
- Ensure you have Python 3.10 or newer installed.
- 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
-
Clone the repository:
git clone https://github.com/KarimAziev/google_speech_pyplay.git cd google_speech_pyplay
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate # For Linux/Mac # or .venv\Scripts\activate # On Windows
-
Upgrade core tools inside the virtual environment:
pip install --upgrade pip setuptools wheel
-
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:
-
Install the build tool:
pip install build
-
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_scmto handle versioning, based on the Git tags of the repository. Ensure you use proper semver tags likev1.0.0to manage versions correctly. - Dev dependencies (like
black,isort) are automatically installed when runningpip install -e ".[dev]".
Metadata
Release files for google-speech-pyplay 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| google_speech_pyplay-1.1.0.tar.gz | 29.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| google_speech_pyplay-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.5 kB
Release files / google_speech_pyplay-1.1.0.tar.gz
| Download URL | google_speech_pyplay-1.1.0.tar.gz |
|---|---|
| Size | 29.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f35ae01a2baef310fe7e09df8f4fcc61775d91eabfe94f3310366e148384494
|
|
BLAKE2b-256 checksum How to use checksums |
f34d7a9192966a1437009984700747e3beea66aa33aae66bc001a903514a3d50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / google_speech_pyplay-1.1.0-py3-none-any.whl
| Download URL | google_speech_pyplay-1.1.0-py3-none-any.whl |
|---|---|
| Size | 26.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6151e49fb025805b816dab2bfaadc17415c9858449afc07aa112600a7826ce2
|
|
BLAKE2b-256 checksum How to use checksums |
bbb499ee9c8ad210bc994e3075a7719b17283f55c0110c2ef186dc8a6e949829
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|