Pre-recorded Audio

Your First Transcription

Install the SDK and transcribe your first audio file in under 5 minutes.


Step 1 — Install the SDK

terminal
pip install shunyalabs[ASR]          # ASR only
pip install shunyalabs[all]          # ASR + TTS + extras

Requires Python 3.8+.

Step 2 — Set your API key

terminal
export SHUNYALABS_API_KEY="your-api-key"

Step 3 — Send a transcription request

python
import asyncio
from shunyalabs import AsyncShunyaClient
from shunyalabs.asr import TranscriptionConfig

async def main():
    async with AsyncShunyaClient() as client:
        result = await client.asr.transcribe(
            "audio.wav",
            config=TranscriptionConfig(
                model="zero-indic",
                language_code="auto",
            ),
        )
        print(result.text)
        print(f"Language: {result.detected_language}")
        print(f"Duration: {result.audio_duration}s")

asyncio.run(main())
Audio requirements: Use 16kHz mono WAV for best accuracy. The API accepts MP3, FLAC, OGG, MP4 and more. Files at other sample rates are automatically resampled.

Step 4 — Read the response

TranscriptionResult
{
  "success": true,
  "request_id": "b3f1a2c4-...",
  "text": "नमस्ते मोहम्मद जी, यह एक जरूरी कॉल है",
  "detected_language": "hindi",
  "audio_duration": 5.7,
  "inference_time_ms": 812.3,
  "segments": [
    { "start": 0.51, "end": 5.70, "text": "नमस्ते मोहम्मद जी, यह एक जरूरी कॉल है" }
  ],
  "speakers": [],
  "nlp_analysis": null
}

Step 5 — Handle errors

python
from shunyalabs.exceptions import (
    AuthenticationError, RateLimitError,
    TranscriptionError, ServerError, ShunyalabsError
)

try:
    result = await client.asr.transcribe("audio.wav", config=config)
except AuthenticationError:
    print("Invalid API key — check SHUNYALABS_API_KEY")
except RateLimitError:
    print("Rate limit hit — back off and retry")
except TranscriptionError as e:
    print(f"Transcription failed: {e}")
except ServerError:
    print("Server error — safe to retry")
except ShunyalabsError as e:
    print(f"Unexpected error: {e}")