Skip to main content

Official Python SDK for STT.ai - Speech-to-Text API

Project description

STT.ai Python SDK

Official Python client for the STT.ai Speech-to-Text API.

Transcribe audio and video files with state-of-the-art Whisper models, speaker diarization, real-time streaming, and AI-powered summarization.

Installation

pip install sttai

Quick Start

from sttai import STTClient

client = STTClient("your-api-key")

# Transcribe a file
result = client.transcribe("meeting.mp3")
print(result["text"])

# Transcribe with speaker diarization
result = client.transcribe("interview.wav", diarize=True, speakers=2)
for segment in result["segments"]:
    print(f"[{segment['speaker']}] {segment['text']}")

Authentication

Get your API key from stt.ai/account.

Pass it directly or set the STT_API_KEY environment variable:

export STT_API_KEY="your-api-key"
client = STTClient()  # reads from STT_API_KEY

API Reference

Transcribe a File

result = client.transcribe(
    "audio.mp3",
    model="large-v3-turbo",  # Model to use
    language="auto",          # Language code or "auto"
    diarize=True,             # Enable speaker diarization
    speakers=0,               # Number of speakers (0 = auto-detect)
    response_format="json",   # "json", "text", "srt", "vtt", "verbose_json"
)

Transcribe from URL

result = client.transcribe_url(
    "https://example.com/podcast.mp3",
    model="large-v3-turbo",
    language="en",
)

Summarize Text

summary = client.summarize(
    result["text"],
    style="brief",  # "brief", "detailed", "bullets", "action_items"
)
print(summary["summary"])

List Available Models

models = client.models()
for model in models["models"]:
    print(f"{model['id']}: {model['description']}")

List Supported Languages

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

Health Check

status = client.health()
print(status)

Real-Time Streaming

Stream audio for live transcription over WebSocket:

def on_transcript(data):
    print(data["text"], end="\r")

session = client.stream(on_transcript, model="large-v3-turbo", language="en")

# Send audio chunks (PCM 16-bit, 16kHz, mono)
with open("audio.raw", "rb") as f:
    while chunk := f.read(4096):
        session.send(chunk)

# Get the final result
result = session.finish()
print("\nFinal:", result["text"])

Error Handling

The SDK raises specific exceptions for different error types:

from sttai import STTClient, AuthError, RateLimitError, CreditError, STTError

client = STTClient("your-api-key")

try:
    result = client.transcribe("audio.mp3")
except AuthError:
    print("Invalid API key")
except CreditError:
    print("Insufficient credits - top up at stt.ai/pricing")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except STTError as e:
    print(f"API error ({e.status_code}): {e.message}")

Configuration

client = STTClient(
    api_key="your-api-key",
    base_url="https://api.stt.ai",  # Custom API endpoint
    timeout=300,                      # Request timeout in seconds
)

Requirements

  • Python 3.8+
  • requests
  • websocket-client (for streaming)

License

MIT - see LICENSE 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

sttai-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sttai-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file sttai-0.1.0.tar.gz.

File metadata

  • Download URL: sttai-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sttai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cfb54eb1d2f8f3643652643fcdb069f7e96626b614ebfc4b0af790ac1f4d595d
MD5 4e2d03a61e20636cd75925a2f2d841c1
BLAKE2b-256 134571c0baafd96e7f94e31c978e563ef32abb244f3de0a16e7a4520a5de7985

See more details on using hashes here.

File details

Details for the file sttai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sttai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sttai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6602a67b108bfbaea75f2a4fd7d2ac3af3af17d9f296ee2fc6ed4876861d7a25
MD5 71519ae2600fbc8116e343358509827e
BLAKE2b-256 53b42b0040ceab750d1f2391bf06e8dcf637bae588e036849a4aa8ee2eab7aff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page