A library for downloading pronunciation MP3 files from Google's dictionary service
Project description
Google Pronouncer
A Python library for downloading pronunciation MP3 files from Google's dictionary service.
Installation
pip install google-pronouncer
Command Line Usage
The package provides a command-line interface with several commands:
Download Pronunciations
# Download all accents for words
google-pronouncer download hello world
# Download specific accent (gb/us)
google-pronouncer download hello -a gb
# Force fresh download (ignore cache)
google-pronouncer download hello --force-download
# Disable cache usage
google-pronouncer download hello --no-cache
# Specify output directory
google-pronouncer download hello -o ./my-pronunciations
Cache Management
# Show cache information for all words
google-pronouncer cache-info
# Show cache info for specific words
google-pronouncer cache-info hello world
# Clear all cache
google-pronouncer clear-cache
# Clear cache for specific words
google-pronouncer clear-cache hello world
Global Options
-o, --output-dir PATH Directory to save pronunciations (default: ./pronunciations)
-t, --timeout SECONDS Request timeout in seconds (default: 10)
-v, --verbose Enable verbose logging
--no-cache Disable cache usage
--force-download Force download even if cached
Python Library Usage
Basic Usage
from google_pronouncer import GooglePronunciationDownloader, DownloadConfig, AccentType
# Create configuration
config = DownloadConfig(
output_dir="pronunciations",
use_cache=True, # Enable caching (default: True)
force_download=False # Force fresh download (default: False)
)
# Initialize downloader
downloader = GooglePronunciationDownloader(config)
# Download single word with specific accent
path = downloader.download_pronunciation("hello", AccentType.BRITISH)
print(f"Downloaded to: {path}")
# Download all accents for a word
paths = downloader.download_all_accents("world")
print(f"Downloaded files: {paths}")
# Download multiple words
words = ["hello", "world", "python"]
paths = downloader.download_words(words)
print(f"Downloaded files: {paths}")
Cache Management
# Get cache information
info = downloader.get_cache_info() # All words
info = downloader.get_cache_info("hello") # Specific word
# Clear cache
downloader.clear_cache() # All words
downloader.clear_cache("hello") # Specific word
Configuration Options
config = DownloadConfig(
output_dir="pronunciations", # Directory to save files
timeout=10, # Request timeout in seconds
user_agent="Custom User Agent", # Optional custom user agent
use_cache=True, # Whether to use cached files
min_file_size=1024, # Minimum valid file size in bytes
force_download=False # Force fresh download
)
Available Accents
AccentType.BRITISH- British English pronunciation (gb)AccentType.AMERICAN- American English pronunciation (us)
Error Handling
from google_pronouncer import DownloadError, CacheError
try:
path = downloader.download_pronunciation("word", AccentType.BRITISH)
except DownloadError as e:
print(f"Download failed: {e}")
except CacheError as e:
print(f"Cache error: {e}")
Features
- Download pronunciations in British and American English
- Configurable output directory and request settings
- Smart caching system with validation
- Cache management tools (info, clear)
- Command-line interface
- Proper error handling and logging
- Type hints for better IDE support
- Support for downloading multiple words and accents
- Clean and simple API
Cache System
The library includes a smart caching system that:
- Automatically caches downloaded files
- Validates cached files before use
- Provides cache information and management
- Supports forced fresh downloads
- Includes file size validation
- Maintains cache metadata
Requirements
- Python 3.7+
- requests library (>=2.31.0)
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file google_pronouncer-0.2.1.tar.gz.
File metadata
- Download URL: google_pronouncer-0.2.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bcc4db32a514520c4564f827fe8d69b205011c697500eecad1c639ef69e431c
|
|
| MD5 |
bf9970f4ef76da56f74e2bffe5b80765
|
|
| BLAKE2b-256 |
410c5dddb8e095f3612a290eb943a4fa7ce0bbbdbb3ccf23c67f0a548fcc0dc4
|
Provenance
The following attestation bundles were made for google_pronouncer-0.2.1.tar.gz:
Publisher:
publish-to-pypi.yml on HachiroSan/google-pronouncer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
google_pronouncer-0.2.1.tar.gz -
Subject digest:
6bcc4db32a514520c4564f827fe8d69b205011c697500eecad1c639ef69e431c - Sigstore transparency entry: 166657922
- Sigstore integration time:
-
Permalink:
HachiroSan/google-pronouncer@93d4ea678b05212696ec2a42ea7b9a5f6793f640 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/HachiroSan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@93d4ea678b05212696ec2a42ea7b9a5f6793f640 -
Trigger Event:
push
-
Statement type:
File details
Details for the file google_pronouncer-0.2.1-py3-none-any.whl.
File metadata
- Download URL: google_pronouncer-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48d311275e2c4694ab90d9496dd16ead9fa7d888bafbcd267a600f259724e017
|
|
| MD5 |
21d7da066c8ed5299c1ecf4036d4641f
|
|
| BLAKE2b-256 |
3bfb87cfe5460c6b5f84e4007701bed4c557a3641c0e1deabe79834b7f1c4468
|
Provenance
The following attestation bundles were made for google_pronouncer-0.2.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on HachiroSan/google-pronouncer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
google_pronouncer-0.2.1-py3-none-any.whl -
Subject digest:
48d311275e2c4694ab90d9496dd16ead9fa7d888bafbcd267a600f259724e017 - Sigstore transparency entry: 166657928
- Sigstore integration time:
-
Permalink:
HachiroSan/google-pronouncer@93d4ea678b05212696ec2a42ea7b9a5f6793f640 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/HachiroSan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@93d4ea678b05212696ec2a42ea7b9a5f6793f640 -
Trigger Event:
push
-
Statement type: