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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gladiaio_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b5fb9d46550ef5a2d59b181a57a4622cfda950f2c8884a2e2a6d2fb72f780725
MD5 fd0a022bb41b9fb069962df664f56da3
BLAKE2b-256 79d63ac52dfaae822591089973b4e251b0b515e05a5107e4e713c3ddefb0fdc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gladiaio_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec93a3465298f7a336f20b29f62eee2637f969dee3ce6004b14dba470824a874
MD5 9f4117c917ccc6342c32399775b1a03e
BLAKE2b-256 a6a608841f29add82f494db80af03a467020072f310e211bd7b673284c8c41d7

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