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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gladiaio_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 885394c6fc681b1bb974f8b72a66103202d24dd62da338a37d5963ca0d36760c
MD5 f3aecd29ecf5a301e8bd68adc4c98c39
BLAKE2b-256 1a4503cf78c00bc9d23753e58e6e184617c5ba9eaf0efa39047fbd7294657449

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gladiaio_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3fc3c9992e14ec531ee0cb32e3576fbfc6f8cead27c6ec63e3f36cfe2016137
MD5 fe16a4b28ab67d35e874798b0a868dd2
BLAKE2b-256 47cb24ef54835671949a367150162495e23c9bddfd4c8a2c0ed5f9e0fcedbb5b

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