Official Python SDK for the Hudsonly AI API
Project description
Hudsonly AI Python SDK
Official Python SDK for the Hudsonly AI API — Text-to-Speech, Speech-to-Text, Text Embeddings, and Avatar Video Generation.
Installation
pip install hudsonly
Quick Start
from hudsonly import HudsonlyAI
client = HudsonlyAI(api_key="your-api-token")
# Text to Speech
result = client.tts.generate(text="Hello world", voice="af_heart")
print(result.audio_url)
# Speech to Text
result = client.transcription.generate(audio="recording.mp3")
print(result.text)
# Text Embeddings
result = client.embeddings.generate(texts=["Hello", "World"])
print(result.embeddings)
# Avatar Video (auto-polls until complete)
result = client.avatar.generate(
image="photo.jpg",
audio="speech.mp3",
model="sadtalker",
)
print(result.video_url)
Services
Text to Speech
Convert text to natural-sounding speech.
result = client.tts.generate(
text="Hello world",
voice="af_heart", # Voice identifier
format="mp3", # "mp3" or "wav"
speed=1.0, # 0.5 to 2.0
)
print(result.audio_url)
print(result.duration_seconds)
Speech to Text (Transcription)
Transcribe audio files to text with timestamps.
# From a local file
result = client.transcription.generate(
audio="recording.mp3",
model="base", # "tiny", "base", "small", "medium"
language="en", # Optional, auto-detected if omitted
)
print(result.text)
for segment in result.segments:
print(f"[{segment.start:.1f}s - {segment.end:.1f}s] {segment.text}")
# From a URL
result = client.transcription.generate(
audio_url="https://example.com/audio.mp3",
)
Text Embeddings
Generate vector embeddings for text.
result = client.embeddings.generate(texts=["Hello", "World"])
print(result.embeddings) # [[0.1, 0.2, ...], [0.3, 0.4, ...]]
print(result.dimension) # 1024
print(result.model) # "bge-m3"
Avatar Video Generation
Generate animated portrait videos. This is an async service — generate() submits the task and polls until complete.
# Auto-poll (recommended)
result = client.avatar.generate(
image="photo.jpg",
audio="speech.mp3",
model="sadtalker", # "sadtalker" or "liveportrait"
poll_interval=5, # Seconds between polls
timeout=600, # Max wait time
)
print(result.video_url)
# Manual polling
task = client.avatar.create(image="photo.jpg", audio="speech.mp3")
print(task.id, task.status) # "pending"
# Poll manually
task = client.tasks.get(task.id)
if task.is_completed:
print(task.output["video_url"])
LivePortrait (video-driven):
result = client.avatar.generate(
image="photo.jpg",
video="driving_video.mp4",
model="liveportrait",
flag_stitching=True,
flag_relative_motion=True,
)
Resources
Tasks
List and retrieve async tasks.
# List tasks
tasks = client.tasks.list(service="avatar", status="completed")
for task in tasks.data:
print(task.id, task.status)
# Get a specific task
task = client.tasks.get("task-uuid")
print(task.output)
Credits
Check balance and transaction history.
# Get balance
balance = client.credits.balance()
print(balance.balance)
# Transaction history
history = client.credits.history(type="usage", per_page=50)
for txn in history.data:
print(txn.amount, txn.description)
Other Methods
# List available services
services = client.services()
for svc in services:
print(svc.slug, svc.name, svc.min_credits)
# Check rate limits
limits = client.rate_limits()
for limit in limits:
print(f"{limit.service}: {limit.remaining}/{limit.limit}")
Error Handling
from hudsonly import (
HudsonlyAI,
AuthenticationError,
InsufficientCreditsError,
RateLimitError,
ValidationError,
TaskError,
TaskTimeoutError,
)
client = HudsonlyAI(api_key="your-token")
try:
result = client.tts.generate(text="Hello")
except AuthenticationError:
print("Invalid API key")
except InsufficientCreditsError:
print("Not enough credits")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except ValidationError as e:
print(f"Validation failed: {e.errors}")
except TaskError as e:
print(f"Task {e.task_id} failed: {e}")
except TaskTimeoutError:
print("Task polling timed out")
Context Manager
with HudsonlyAI(api_key="your-token") as client:
result = client.tts.generate(text="Hello")
Requirements
- Python 3.9+
- httpx (installed automatically)
License
MIT
Project details
Release history Release notifications | RSS feed
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 hudsonly_ai-0.1.0.tar.gz.
File metadata
- Download URL: hudsonly_ai-0.1.0.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
073cb4c03fd727c04ce60d8aae31c34e3174acf02f879dac40f383b7787f803a
|
|
| MD5 |
584a5dbe0e5983a9d4bb80a8f02063ef
|
|
| BLAKE2b-256 |
9d9dc9f4e44a85b92655bf98b6827642ee19b2d8cb3a8d8975a576c4d63be099
|
File details
Details for the file hudsonly_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hudsonly_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37837ef033901c9de68aaaaa93989839c383d4feebfce400809f6ed52644cd73
|
|
| MD5 |
aa7ec889f91ac1049e251cf16c841eab
|
|
| BLAKE2b-256 |
f08c0b3dae8987665b70d675895a789fe1f743e7d9b896fef7e12940765d5816
|