Skip to content

Getting Started

Installation

pip install khaya
uv add khaya

Requires Python 3.11 or later.

Get an API key

Sign up at https://translation.ghananlp.org to get your API key.

Authentication

Pass your key directly to the client, or set the KHAYA_API_KEY environment variable and pass it from there:

export KHAYA_API_KEY=your_api_key_here
import os
from khaya import KhayaClient

client = KhayaClient(os.environ["KHAYA_API_KEY"])

Your first requests

Translate text

import os
from khaya import KhayaClient

with KhayaClient(os.environ["KHAYA_API_KEY"]) as khaya:
    result = khaya.translate("Good morning", "en-tw")
    print(result.text)  # "Maakye"

Transcribe audio

with KhayaClient(os.environ["KHAYA_API_KEY"]) as khaya:
    result = khaya.transcribe("recording.wav", "tw")
    print(result.text)

Synthesize speech

with KhayaClient(os.environ["KHAYA_API_KEY"]) as khaya:
    result = khaya.synthesize("Maakye", "tw")
    with open("output.wav", "wb") as f:
        f.write(result.audio)

Using the context manager

The with statement ensures HTTP connections are closed properly. It is the recommended usage pattern:

with KhayaClient(api_key) as khaya:
    ...

If you manage the lifecycle yourself, call khaya.http_client.close() when you are done.

Next steps