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

Uploaded Python 3

File details

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

File metadata

  • Download URL: gladiaio_sdk-0.3.1.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for gladiaio_sdk-0.3.1.tar.gz
Algorithm Hash digest
SHA256 40d6075ebfa3c7fc4b3b0b7997a23bfb8be9eee203f941767ba6297e7d7928da
MD5 50f8965d35cbef1682225d934a49739d
BLAKE2b-256 caeaba203e06bd91e6e8be79de0594cf5c8a6eed483015ebc11405bfbb1ae8f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gladiaio_sdk-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9309f18f33a18f87366ff5e76363b684bd66dd9bf88b555ebae83ac3dc636cc
MD5 7701e869f1202b337d25dbd96edd9504
BLAKE2b-256 e4cb0452f9ed8bf4ec07c7a87f6e691de220c4e7184c869dd208e7fc24f6e4d7

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