# Generate a customer greeting

Source: https://platform.msingiai.com/docs?page=customer-greeting

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

Create a Swahili welcome message for a phone menu or app. This example saves a WAV file you can play.

## 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
- Generate a customer greeting: https://platform.msingiai.com/docs/customer-greeting.md
- Authentication: https://platform.msingiai.com/docs/auth.md
- Errors: https://platform.msingiai.com/docs/errors.md

Generate a Swahili customer greeting with Msingi in this project. Use voice_id female3 and the message from this guide, save greeting.wav, and make the message easy to change.
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

Example greeting · Swahili · WAV · synthetic speech

Karibu. Tafadhali chagua huduma unayotaka kutumia.

[Download sample WAV](https://platform.msingiai.com/assets/examples/customer-greeting.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 customer-greeting.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

response=$(mktemp)
headers=$(mktemp)
trap 'rm -f "$response" "$headers"' EXIT
if ! curl --fail-with-body --silent --show-error --max-time 120 \
  "$BASE/v1/audio/speech" \
  -H "Authorization: Bearer $MSINGI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Karibu. Tafadhali chagua huduma unayotaka kutumia.","voice_id":"female3"}' \
  --dump-header "$headers" --output "$response"; then
  cat "$response" >&2
  exit 1
fi
if ! grep -Eiq '^content-type:[[:space:]]*audio/(wav|x-wav)' "$headers"; then
  echo "Expected WAV audio; received a different response." >&2
  exit 1
fi
mv "$response" greeting.wav
echo "Saved greeting.wav. Open it in your audio player."
```

### Setup

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

### Run

```bash
bash customer-greeting.sh
```

## Python example

Save as customer_greeting.py.

```python
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("/")

response = requests.post(
    f"{BASE}/v1/audio/speech",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={"text": "Karibu. Tafadhali chagua huduma unayotaka kutumia.", "voice_id": "female3"},
    timeout=(10, 120),
)
if not response.ok:
    raise SystemExit(f"HTTP {response.status_code}: {response.text}")
if response.headers.get("Content-Type", "").split(";")[0] not in ("audio/wav", "audio/x-wav"):
    raise SystemExit("Expected WAV audio; received a different response.")
Path("greeting.wav").write_bytes(response.content)
print("Saved greeting.wav. Open it in your audio player.")
```

### Setup

Use Python 3.12 or newer.

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

### Run

```bash
python customer_greeting.py
```

## JavaScript / Node.js example

Save as customer-greeting.mjs.

```javascript
import { writeFile } from "node:fs/promises";

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;

const response = await fetch(BASE + "/v1/audio/speech", {
  method: "POST",
  headers: { Authorization: "Bearer " + API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({ text: "Karibu. Tafadhali chagua huduma unayotaka kutumia.", voice_id: "female3" }),
  signal: AbortSignal.timeout(120000),
});
if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text());
const type = response.headers.get("content-type")?.split(";")[0];
if (type !== "audio/wav" && type !== "audio/x-wav") throw new Error("Expected WAV audio.");
await writeFile("greeting.wav", Buffer.from(await response.arrayBuffer()));
console.log("Saved greeting.wav. Open it in your audio player.");
```

### Setup

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

### Run

```bash
node customer-greeting.mjs
```

## Check the result

```text
greeting.wav
```

The file appears in the folder where you ran the script. Open it in your audio player to hear your greeting.

## Try your own input

Change text in the script to your own message. To choose another voice, use a voice_id from List voices.

[List available voices](https://platform.msingiai.com/docs/voices.md)

## Next: transcribe your greeting

Use a key permitted for both speech and transcription.

```bash
curl --fail-with-body --silent --show-error \
  "$MSINGI_BASE_URL/v1/audio/transcriptions" \
  -H "Authorization: Bearer $MSINGI_API_KEY" \
  -F "file=@greeting.wav"
```

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.

Try your own message without code.

[Open Text to speech](https://platform.msingiai.com/playground?operation=tts)

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