Voice2Voice Python SDK
A Python SDK for the Voice2Voice Translator API. It provides synchronous and asynchronous clients for discovering supported languages, translating audio, downloading generated audio, checking visitor quotas, and managing administrator quota settings.
Release status:
0.1.1— early release. The SDK interface and server API may evolve.
Features
- Synchronous client:
Voice2VoiceClient - Asynchronous client:
AsyncVoice2VoiceClient - Audio upload and translation
- Download translated audio
- Retrieve supported languages and visitor quota
- Optional administrator operations using a bearer token
- Typed result models and specific API exceptions
- Configurable request timeout
- Reusable HTTPX clients and context-manager support
- Persistent anonymous visitor ID when the server issues the
vt_visitor_idcookie
Requirements
- Python 3.9 or newer
- Access to a running Voice2Voice API server
httpx(installed automatically)
Installation
python -m pip install voice2voice
Quick start
Synchronous client
from voice2voice import Voice2VoiceClient, APIError, QuotaExceededError
with Voice2VoiceClient() as client:
languages = client.languages()
print([(language.code, language.name) for language in languages])
print("Quota:", client.quota())
result = client.translate(
file="sample.mp3",
source_language="en",
target_language="es",
output_format="mp3",
)
print("Recognized:", result.recognized_text)
print("Cleaned:", result.cleaned_text)
print("Translated:", result.translated_text)
audio = client.download_audio(result)
with open(audio.filename, "wb") as output_file:
output_file.write(audio.content)
Handle API-specific errors when needed:
from voice2voice import Voice2VoiceClient, APIError, QuotaExceededError
try:
with Voice2VoiceClient() as client:
result = client.translate(
file="sample.mp3",
source_language="en",
target_language="es",
)
except QuotaExceededError as exc:
print("Quota exceeded:", exc.message)
print("Remaining seconds:", exc.remaining_seconds)
except APIError as exc:
print(f"API request failed ({exc.status_code}): {exc.message}")
Asynchronous client
Use async with to close the asynchronous HTTPX client reliably:
import asyncio
from voice2voice import AsyncVoice2VoiceClient
async def main():
async with AsyncVoice2VoiceClient() as client:
languages = await client.languages()
print([(language.code, language.name) for language in languages])
result = await client.translate(
file="sample.mp3",
source_language="en",
target_language="es",
output_format="mp3",
)
print("Translated:", result.translated_text)
audio = await client.download_audio(result)
with open(audio.filename, "wb") as output_file:
output_file.write(audio.content)
asyncio.run(main())
Configuration
Both clients accept the following configuration options:
from voice2voice import Voice2VoiceClient
client = Voice2VoiceClient(
base_url="https://your-api.example.com",
timeout=120.0,
)
| Option | Description |
|---|---|
base_url |
Base URL of the Voice2Voice API. Defaults to the hosted API configured by the SDK. |
visitor_id |
Optional previously obtained anonymous visitor ID. |
admin_token |
Bearer token used by administrator methods. |
timeout |
HTTPX request timeout in seconds. Set to None to disable the timeout. |
http_client |
Optional existing httpx.Client. The async client accepts an httpx.AsyncClient. |
When an external HTTPX client is injected, the SDK does not close it.
The caller remains responsible for managing its lifecycle. Requests use the
SDK's configured base_url, independently of the injected HTTPX client's
base_url.
Example with an externally managed HTTPX client:
import httpx
from voice2voice import Voice2VoiceClient
transport = httpx.Client(timeout=45.0)
try:
with Voice2VoiceClient(
base_url="https://your-api.example.com",
http_client=transport,
) as client:
print(client.languages())
finally:
transport.close()
Anonymous visitor identity
The API server may issue a vt_visitor_id cookie to identify an anonymous
visitor and track that visitor's quota. The SDK exposes the current value:
visitor_id = client.visitor_id
When the server issues this cookie, the SDK attempts to persist it at:
~/.voice2voice/visitor.json
The SDK continues working if the file cannot be read or written. You can also
pass visitor_id=... explicitly to restore an identity.
Treat visitor IDs as private. Do not publish them, commit them to source control, or expose them in logs.
Administrator operations
Administrator methods require a valid server-issued admin token:
from voice2voice import Voice2VoiceClient
with Voice2VoiceClient(admin_token="YOUR_ADMIN_TOKEN") as client:
current = client.admin_quota()
print(current)
updated = client.update_admin_quota(
quota_seconds=180,
period_type="daily",
)
print(updated)
Keep the token in an environment variable or secret manager rather than hard-coding it.
The async client provides the equivalent methods:
current = await client.admin_quota()
updated = await client.update_admin_quota(
quota_seconds=180,
period_type="daily",
)
The accepted period_type values and quota-update semantics are defined by
the API server. Check the server's current documentation before changing
administrator settings.
API methods
| Method | Description |
|---|---|
languages() |
Return the languages advertised by the API. |
translate(file, source_language, target_language, output_format="mp3") |
Upload audio and return translation data. |
quota() |
Retrieve the current visitor's quota information. |
download_audio(result_or_url) |
Download generated audio and return an AudioDownload. |
admin_quota() |
Retrieve administrator quota settings. |
update_admin_quota(quota_seconds, period_type, custom_period_seconds=86400) |
Update administrator quota settings. |
For AsyncVoice2VoiceClient, use await with each method. It also provides
aclose() and asynchronous context-manager support.
Language codes, supported audio formats, upload limits, and quota behavior
are determined by the API server. Retrieve the current language list with
client.languages() and consult the server's current API documentation for
accepted formats and limits.
Return models
Language:name,codeTranslationResult:recognized_text,cleaned_text,translated_text,audio_url,audio_filename, and the original response dictionary inrawAudioDownload: downloadedcontent(bytes),content_type, andfilename
These models are immutable dataclasses.
Error handling
All SDK-specific exceptions inherit from Voice2VoiceError.
| Exception | Meaning |
|---|---|
Voice2VoiceError |
Base SDK exception. |
APIError |
Unsuccessful HTTP response; includes status_code, message, and detail. |
AuthenticationError |
HTTP 401 or 403 response. |
QuotaExceededError |
HTTP 429 response with the API's quota_exceeded error code. |
QuotaExceededError also exposes quota fields when the server includes them:
limit_seconds, used_seconds, remaining_seconds, requested_seconds,
and reset_at.
Network and file-system errors are not converted into APIError. Handle
exceptions such as httpx.TimeoutException, httpx.ConnectError, and
OSError where appropriate.
Development
Clone the repository:
git clone https://github.com/ehsanulhaqislamyar-star/voice2voice-python.git
cd voice2voice-python
Install the development dependencies:
python -m pip install -e ".[dev]"
Run the test suite:
python -m pytest
Build the source distribution and wheel:
python -m build
Validate the distributions:
python -m twine check dist/*
License
This project is licensed under the MIT License. See LICENSE for the full license text.
Metadata
Release files for voice2voice 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| voice2voice-0.1.1.tar.gz | 8.6 kB | Without provenance | Details for voice2voice-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| voice2voice-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for voice2voice-0.1.1-py3-none-any.whl |
Total release size: 19.6 kB
Release files / voice2voice-0.1.1.tar.gz
| Download URL | voice2voice-0.1.1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be1765f07b0338f8c139ce4b306aa1297dfa47fdeb47d6cb337bd3c1b9e58f2b
|
|
BLAKE2b-256 checksum How to use checksums |
1462472c6b7c9a8e45930634236bb64599ab46d85fda5ac77c4d93cec3bba815
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / voice2voice-0.1.1-py3-none-any.whl
| Download URL | voice2voice-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c32533aae53f127ce1f2fa8e1636270b0ccfbd4433af27a0e6eba2621b890bf5
|
|
BLAKE2b-256 checksum How to use checksums |
546aecbebf7287b40df8107190b5774b6d8199f7be118e0a55a88b454fc6ab03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for voice2voice 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.