Skip to main content

Installation

pip install 60db

Initialization

from sixtydb import SixtyDBClient

# Simple initialization
client = SixtyDBClient('your-api-key')

# With custom configuration

### Get all voices
voices = await client.getVoices();

### Get all lanuages
lanuages = await client.getLanguages();

### audio is an ArrayBuffer containing the audio data

Text-to-Speech

Basic TTS

audio = client.text_to_speech(
    text='Hello, world!',
    voice_id='default-voice',
    enhance=True,
    speed=1.0,
    language='en-us'
)

# Save to file
with open('output.mp3', 'wb') as f:
    f.write(audio)

Streaming TTS

def handle_chunk(chunk):
    print(f"Received {len(chunk)} bytes")
    # Process or save chunk

def handle_complete():
    print("Streaming complete!")

def handle_error(error):
    print(f"Error: {error}")

client.text_to_speech_stream(
    text='This is a longer text that will be streamed',
    on_chunk=handle_chunk,
    on_complete=handle_complete,
    on_error=handle_error,
    voice_id='default-voice'
)

Speech-to-Text

Transcribe Audio

with open('audio.mp3', 'rb') as audio_file:
    result = client.speech_to_text(audio_file, language='en')
    print(result['text'])

Get Supported Languages

languages = client.get_languages()
for lang in languages:
    print(f"{lang['name']} ({lang['code']})")

Voice Management

List All Voices

voices = client.get_voices()
for voice in voices:
    print(f"{voice['name']} ({voice['id']})")

Get Specific Voice

voice = client.get_voice('voice-id')
print(voice)

Create Custom Voice

files = [
    open('sample1.mp3', 'rb'),
    open('sample2.mp3', 'rb'),
    open('sample3.mp3', 'rb')
]

new_voice = client.create_voice(
    name='My Custom Voice',
    files=files,
    description='A custom voice for my brand'
)

print(f"Created voice: {new_voice['id']}")

# Close files
for f in files:
    f.close()

Update Voice

client.update_voice(
    voice_id='voice-id',
    name='Updated Voice Name',
    description='Updated description'
)

Delete Voice

client.delete_voice('voice-id')

Authentication

Sign Up

user = client.sign_up(
    email='user@example.com',
    password='secure-password',
    name='John Doe'
)

Sign In

session = client.sign_in(
    email='user@example.com',
    password='secure-password'
)

print(f"Token: {session['token']}")

Get Profile

profile = client.get_profile()
print(profile)

Update Profile

client.update_profile(
    name='Jane Doe',
    company='Acme Inc'
)

Workspace Management

List Workspaces

workspaces = client.get_workspaces()

Create Workspace

workspace = client.create_workspace(
    name='My Workspace',
    description='Team workspace'
)

Billing

Get Available Plans

plans = client.get_plans()
for plan in plans:
    print(f"{plan['name']}: ${plan['price']}/month")

Get Current Plan

current_plan = client.get_current_plan()
print(f"Current plan: {current_plan['name']}")

Subscribe to Plan

client.subscribe('plan-id')

Analytics

Get Usage Statistics

usage = client.get_usage()
print(f"Characters used: {usage['characters']}")
print(f"API calls: {usage['api_calls']}")

API Key Management

List API Keys

api_keys = client.get_api_keys()

Create API Key

new_key = client.create_api_key('Production Key')
print(f"New API key: {new_key['key']}")

Delete API Key

client.delete_api_key('key-id')

Webhooks

List Webhooks

webhooks = client.get_webhooks()

Create Webhook

webhook = client.create_webhook(
    url='https://example.com/webhook',
    events=['tts.completed', 'stt.completed']
)

Delete Webhook

client.delete_webhook('webhook-id')

Error Handling

from requests.exceptions import HTTPError

try:
    audio = client.text_to_speech(
        text='Hello, world!',
        voice_id='invalid-voice'
    )
except HTTPError as e:
    print(f"HTTP Error: {e.response.status_code}")
    print(f"Message: {e.response.json()['message']}")
except Exception as e:
    print(f"Error: {str(e)}")

Type Hints

The SDK includes type hints for better IDE support:
from sixtydb import SixtyDBClient
from typing import Dict, List, Any

client: SixtyDBClient = SixtyDBClient('your-api-key')
voices: List[Dict[str, Any]] = client.get_voices()

Async Support

For async applications, you can use the SDK with asyncio:
import asyncio
from sixtydb import SixtyDBClient

async def main():
    client = SixtyDBClient('your-api-key')

    # Run in executor for async compatibility
    loop = asyncio.get_event_loop()
    audio = await loop.run_in_executor(
        None,
        client.text_to_speech,
        'Hello, world!',
        'default-voice'
    )

    with open('output.mp3', 'wb') as f:
        f.write(audio)

asyncio.run(main())