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.
It may work on lower versions but they are not supported / tested.

Installation

Using pip

pip install gladiaio-sdk

Using uv

uv add gladiaio-sdk

Usage

To use the SDK, import GladiaClient and create a new instance of it.

You can also configure api_key, api_url and region through their respective environment variables: GLADIA_API_KEY, GLADIA_API_URL and GLADIA_REGION.

from gladiaio_sdk import GladiaClient

gladia_client = GladiaClient(
  api_key="your_api_key"
)

Live V2

Threaded vs Async

Our Python SDK supports sync/threaded and asyncio versions.
To get the sync/threaded version, do:

live_client = gladia_client.live_v2()

And to get the async version:

live_client = gladia_client.live_v2_async()

Usage

Once you decided between sync and async client, you can use the client to run a Live session:

# Create session
live_session = live_client.start_session(
  LiveV2InitRequest(
    language_config=LiveV2LanguageConfig(
      languages=["en"],
    ),
    messages_config=LiveV2MessagesConfig(
      receive_partial_transcripts=True,
    ),
  )
)


# Add listeners
@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")


# Send audio
live_session.send_audio(audio_bytes)
# ...
live_session.send_audio(audio_bytes)

# Stop the recording when all audio have been sent.
# Remaining audio will be processed and after post-processing,
# the session is ended.
live_session.stop_recording()

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-0.2.0.tar.gz (37.1 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-0.2.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gladiaio_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for gladiaio_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 adb8cb805908f18721115bd7c31ada04e4a46f327e60139daff491c13b326ec1
MD5 1e2432f63e87068f595d9684e76ea422
BLAKE2b-256 74ce05b579b969b34155d11c2dbb00f32ca0e89b0b9c10960f9ca47f32556ac1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gladiaio_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c3d5be39199024096d8bbbb9e156412dfa22743f74b2a54edb912cdbb6f9f98
MD5 69f3faaa95f3b0f961aa5b8ce5214cd8
BLAKE2b-256 6ad9109763ce9459714644e654a97aeeee98a76b1d6dd9130ee85308ac9e6336

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