Getting Started¶
Installation¶
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:
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:
If you manage the lifecycle yourself, call khaya.http_client.close() when you are done.
Next steps¶
- Translation guide — all language pairs and tips
- ASR guide — audio format requirements
- TTS guide — saving and playing audio
- Error handling — catch the right exception
- Async usage —
async withandawait