Skip to main content

Gladia SDK for Python

Project description

Gladia Python SDK

A Python SDK for the Gladia API.

Requirements

You need Python 3.10+ for this package.

Installation

pip install gladiaio-sdk

# or with uv

uv add gladiaio-sdk

Usage

Import GladiaClient and create an instance.

Provide an API key with api_key or the GLADIA_API_KEY environment variable. Get your API key in under a minute.

You can also set GLADIA_API_URL and GLADIA_REGION (eu-west / us-west).

Sync client

from gladiaio_sdk import GladiaClient

gladia_client = GladiaClient(api_key="your-api-key")

Pre-recorded transcription

transcribe() accepts a path, Path, binary file object, or http(s) URL. It uploads when needed, then polls until the job completes.

from gladiaio_sdk import GladiaClient

gladia_client = GladiaClient(api_key="your-api-key")

transcription = gladia_client.prerecorded().transcribe(
    "audio.mp3",
    {
        "language_config": {
            "languages": ["en"],
        },
    },
)

print(transcription.result.transcription.full_transcript)

See all the supported languages here!

Pass the options as the second argument to enable all the features from Audio intelligence — diarization, translation, PII redaction, and more.

Async pre-recorded

Use prerecorded_async() and await the same methods. Options match the sync API.

import asyncio

from gladiaio_sdk import GladiaClient


async def main() -> None:
    gladia_client = GladiaClient(api_key="your-api-key")

    transcription = await gladia_client.prerecorded_async().transcribe(
        "audio.mp3",
        {
            "language_config": {
                "languages": ["en"],
            },
        },
    )

    print(transcription.result.transcription.full_transcript)


asyncio.run(main())

Live transcription

Get a live client from your GladiaClient:

live_client = gladia_client.live()

Async version:

live_client = gladia_client.live_async()
from gladiaio_sdk import (
    LiveV2EndedMessage,
    LiveV2InitRequest,
    LiveV2InitResponse,
    LiveV2LanguageConfig,
    LiveV2MessagesConfig,
    LiveV2WebSocketMessage,
)

live_session = live_client.start_session(
    LiveV2InitRequest(
        model="solaria-1",
        encoding="wav/pcm",
        sample_rate=16000,
        bit_depth=16,
        channels=1,
        language_config=LiveV2LanguageConfig(
            languages=["en"],
        ),
        messages_config=LiveV2MessagesConfig(
            receive_partial_transcripts=True,
        ),
    )
)


@live_session.on("message")
def on_message(message: LiveV2WebSocketMessage):
    if message.type == "transcript":
        print(f"{'F' if message.data.is_final else 'P'} | {message.data.utterance.text.strip()}")


@live_session.once("started")
def on_started(response: LiveV2InitResponse):
    print(f"Session {response.id} started")


@live_session.on("error")
def on_error(error: Exception):
    print(f"An error occurred during live session: {error}")


@live_session.once("ended")
def on_ended(ended: LiveV2EndedMessage):
    print(f"Session {live_session.session_id} ended")


live_session.send_audio(audio_bytes)
live_session.stop_recording()

Use LiveV2InitRequest fields for realtime/post-processing options — see Live STT features and the live init API.

Async live

Same session API; use live_async() and run under asyncio.run or your app loop:

import asyncio

from gladiaio_sdk import (
    GladiaClient,
    LiveV2EndedMessage,
    LiveV2InitRequest,
    LiveV2InitResponse,
    LiveV2LanguageConfig,
    LiveV2MessagesConfig,
    LiveV2WebSocketMessage,
)


async def main() -> None:
    gladia_client = GladiaClient(api_key="your-api-key")
    live_client = gladia_client.live_async()
    session_done = asyncio.Event()

    live_session = live_client.start_session(
        LiveV2InitRequest(
            model="solaria-1",
            encoding="wav/pcm",
            sample_rate=16000,
            bit_depth=16,
            channels=1,
            language_config=LiveV2LanguageConfig(languages=["en"]),
            messages_config=LiveV2MessagesConfig(receive_partial_transcripts=True),
        )
    )

    @live_session.on("message")
    def on_message(message: LiveV2WebSocketMessage):
        if message.type == "transcript":
            print(f"{'F' if message.data.is_final else 'P'} | {message.data.utterance.text.strip()}")

    @live_session.once("started")
    def on_started(response: LiveV2InitResponse):
        print(f"Session {response.id} started")

    @live_session.on("error")
    def on_error(error: Exception):
        print(f"An error occurred during live session: {error}")
        session_done.set()

    @live_session.once("ended")
    def on_ended(ended: LiveV2EndedMessage):
        print(f"Session {live_session.session_id} ended")
        session_done.set()

    live_session.send_audio(audio_bytes)
    live_session.stop_recording()

    await session_done.wait()


asyncio.run(main())

When you need the session id from an async session: await live_session.get_session_id(). For a sync session, use live_session.session_id after started.

Documentation

License

MIT

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

gladiaio_sdk-1.0.2.tar.gz (54.0 kB view details)

Uploaded Source

Built Distribution

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

gladiaio_sdk-1.0.2-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

Details for the file gladiaio_sdk-1.0.2.tar.gz.

File metadata

  • Download URL: gladiaio_sdk-1.0.2.tar.gz
  • Upload date:
  • Size: 54.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gladiaio_sdk-1.0.2.tar.gz
Algorithm Hash digest
SHA256 864400881052d0bb40b420d603ae2abe42ae58259d42232d5277f75dc2768143
MD5 a6969b0ce146765ebacd8a11759bdcb6
BLAKE2b-256 9f2316cf18f6a25d2c72358e29ccc33cc6741a821a0a01ae0fd632d072109d81

See more details on using hashes here.

File details

Details for the file gladiaio_sdk-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: gladiaio_sdk-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 47.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gladiaio_sdk-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3fba052b714c799deb4d02dbf358c9359fd2379f9257e08e4fe8781a3e61d654
MD5 b756367a1d60d3f30c820ae30f073dfd
BLAKE2b-256 bb49caeaed2f477e8024b9ad882d6d8e609e9e886508e2692b27acc42872b2fa

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