# Transcribe a Swahili voice note

Source: https://platform.msingiai.com/docs?page=voice-note

API base URL: https://api.msingiai.com

Turn a recorded service enquiry into text. Start with the sample below, then use your own recording.

## Coding with an agent?

Copy a prompt into your coding agent to build this example in your project.

```text
Read the Msingi API documentation before writing code:
- Documentation index: https://platform.msingiai.com/llms.txt
- Transcribe a Swahili voice note: https://platform.msingiai.com/docs/voice-note.md
- Authentication: https://platform.msingiai.com/docs/auth.md
- Errors: https://platform.msingiai.com/docs/errors.md

Build a Msingi transcription example in this project. Download the sample WAV from this guide, send it as a multipart file, and display the returned transcript. Make it easy to use my own recording afterwards.
Use this project's language and framework. Follow the documented endpoints, formats and limits; do not invent SDKs or routes.
Use https://api.msingiai.com as the default API base URL. Read MSINGI_API_KEY from a server environment variable. Keep credentials out of browser code, URLs and logs.
Handle non-success responses before treating output as audio or a transcript. Follow the documented streaming protocol when applicable.
Prepare the code and explain how to run it. Ask before making a billable API request.
```

## Sample audio

Sample service enquiry · Swahili · WAV · synthetic speech

Habari! Naomba kujua kama huduma ya trekta inapatikana kesho asubuhi.

[Download sample WAV](https://platform.msingiai.com/assets/examples/swahili-voice-note.wav)

## Set up

Use a confirmed account, a funded workspace and an API key with permission for this operation. See [Authentication](https://platform.msingiai.com/docs/auth.md) and [Pricing](https://platform.msingiai.com/docs/pricing.md).

Replace the key placeholder below. Keep your key on your computer or server.

```bash
export MSINGI_API_KEY="msk_replace_with_your_key"
export MSINGI_BASE_URL="https://api.msingiai.com"
```

## Bash / cURL example

Save as voice-note.sh.

```bash
#!/usr/bin/env bash
set -eo pipefail
if [ -z "$MSINGI_API_KEY" ]; then
  echo "Set MSINGI_API_KEY before running this example." >&2
  exit 1
fi
BASE="$MSINGI_BASE_URL"
if [ -z "$BASE" ]; then BASE="https://api.msingiai.com"; fi

audio="voice-note.wav"
if [ "$#" -gt 0 ]; then
  audio="$1"
elif [ ! -f "$audio" ]; then
  curl --fail --silent --show-error \
    "https://platform.msingiai.com/assets/examples/swahili-voice-note.wav" --output "$audio"
fi

curl --fail-with-body --silent --show-error --max-time 120 \
  "$BASE/v1/audio/transcriptions" \
  -H "Authorization: Bearer $MSINGI_API_KEY" \
  -F "file=@$audio"
printf '\n'
```

### Setup

Use Bash and cURL in your terminal. No extra packages are needed.

### Run

```bash
bash voice-note.sh
```

### Your recording

```bash
bash voice-note.sh ./my-recording.wav
```

## Python example

Save as voice_note.py.

```python
import sys
import os
from pathlib import Path
import requests

API_KEY = os.environ.get("MSINGI_API_KEY")
if not API_KEY:
    raise SystemExit("Set MSINGI_API_KEY before running this example.")
BASE = os.environ.get("MSINGI_BASE_URL", "https://api.msingiai.com").rstrip("/")

audio = Path(sys.argv[1] if len(sys.argv) > 1 else "voice-note.wav")
if len(sys.argv) == 1 and not audio.exists():
    sample = requests.get("https://platform.msingiai.com/assets/examples/swahili-voice-note.wav", timeout=30)
    sample.raise_for_status()
    audio.write_bytes(sample.content)

with audio.open("rb") as recording:
    response = requests.post(
        f"{BASE}/v1/audio/transcriptions",
        headers={"Authorization": f"Bearer {API_KEY}"},
        files={"file": (audio.name, recording)},
        timeout=(10, 120),
    )
if not response.ok:
    raise SystemExit(f"HTTP {response.status_code}: {response.text}")
print(response.json()["text"])
```

### Setup

Use Python 3.12 or newer.

```bash
python3 -m venv .venv
source .venv/bin/activate
python -m pip install requests
```

### Run

```bash
python voice_note.py
```

### Your recording

```bash
python voice_note.py ./my-recording.wav
```

## JavaScript / Node.js example

Save as voice-note.mjs.

```javascript
import { readFile, writeFile } from "node:fs/promises";
import { basename } from "node:path";

const API_KEY = process.env.MSINGI_API_KEY;
if (!API_KEY) throw new Error("Set MSINGI_API_KEY before running this example.");
const configuredBase = process.env.MSINGI_BASE_URL ?? "https://api.msingiai.com";
const BASE = configuredBase.endsWith("/") ? configuredBase.slice(0, -1) : configuredBase;

let audio;
let filename = process.argv[2];
if (filename) {
  audio = await readFile(filename);
} else {
  filename = "voice-note.wav";
  const sample = await fetch("https://platform.msingiai.com/assets/examples/swahili-voice-note.wav", { signal: AbortSignal.timeout(30000) });
  if (!sample.ok) throw new Error("Sample download failed: HTTP " + sample.status);
  audio = Buffer.from(await sample.arrayBuffer());
  await writeFile(filename, audio);
}

const form = new FormData();
form.append("file", new Blob([audio]), basename(filename));
const response = await fetch(BASE + "/v1/audio/transcriptions", {
  method: "POST",
  headers: { Authorization: "Bearer " + API_KEY },
  body: form,
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text());
console.log((await response.json()).text);
```

### Setup

Use Node.js 22 or newer. No npm packages are needed.

### Run

```bash
node voice-note.mjs
```

### Your recording

```bash
node voice-note.mjs ./my-recording.wav
```

## Check the result

```text
habari naomba kujua kama huduma ya trekta inapatikana kesho asubuhi
```

Python and Node.js print the transcript. cURL returns JSON containing text. Wording and punctuation may vary.

## Try your own input

Replace the sample with a recording on your computer. Pass its path when you run the script.

See [Errors](https://platform.msingiai.com/docs/errors.md): 401 means check your key, 402 means check your available balance, and 403 means check the key's permissions.

Prefer to upload a recording without code?

[Open Speech to text](https://platform.msingiai.com/playground?operation=asr)

[Documentation index](https://platform.msingiai.com/llms.txt)
