> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Language translation

> Translate text between languages using neural machine translation models running on the Qualcomm NPU.

The translation service converts text between language pairs using neural machine translation models, running fully on the Qualcomm NPU. Batch translation is supported — multiple strings can be translated in a single request.

## Prerequisites

Ensure the Audio Analytics container is deployed and running. See [Running the Audio Analytics container](/ai-workflows/audio-analytics-overview) for setup instructions.

## Available models

Query the models endpoint to get the list of available translation models:

```bash theme={null}
curl http://localhost:8085/audio-analytics/v1/api/translations/models
```

The currently available models are:

| Model        | Translation       |
| ------------ | ----------------- |
| `opus-en-es` | English → Spanish |
| `opus-es-en` | Spanish → English |
| `opus-en-zh` | English → Chinese |
| `opus-zh-en` | Chinese → English |

Use the `name` value from the response in your translation requests.

## Endpoints

| Method | Endpoint                  | Description                       |
| ------ | ------------------------- | --------------------------------- |
| `GET`  | `/translations/models`    | List available translation models |
| `POST` | `/translations/translate` | Translate text                    |

## Translate text

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/translations/translate \
  -H "Content-Type: application/json" \
  -d '{
    "text": ["Hello world", "How are you?"],
    "model": "opus-en-es",
    "source_language": "en",
    "target_language": "es"
  }'
```

**Parameters:**

* `text` (required): Array of strings to translate
* `model` (required): Translation model name
* `source_language` (required): Source language code matching the selected model (e.g. `en` for `opus-en-es`)
* `target_language` (required): Target language code

**Response:**

```json theme={null}
{
  "translations": [
    {
      "translated_text": "Hola mundo",
      "source_language": "en",
      "target_language": "es"
    },
    {
      "translated_text": "¿Cómo estás?",
      "source_language": "en",
      "target_language": "es"
    }
  ]
}
```

## Batch translation

Translate multiple strings in a single request by passing an array of texts:

```bash theme={null}
curl -X POST http://localhost:8085/audio-analytics/v1/api/translations/translate \
  -H "Content-Type: application/json" \
  -d '{
    "text": ["Hello world", "How are you?", "Good morning"],
    "model": "opus-en-es",
    "source_language": "en",
    "target_language": "es"
  }'
```

**Response:**

```json theme={null}
{
  "translations": [
    {"translated_text": "Hola mundo", "source_language": "en", "target_language": "es"},
    {"translated_text": "¿Cómo estás?", "source_language": "en", "target_language": "es"},
    {"translated_text": "Buenos días.", "source_language": "en", "target_language": "es"}
  ]
}
```

Results are returned in the same order as the input array.

## Python example

```python theme={null}
import requests

def translate(texts, model="opus-en-es", source_language="en", target_language="es"):
    url = "http://localhost:8085/audio-analytics/v1/api/translations/translate"
    response = requests.post(url, json={
        "text": texts,
        "model": model,
        "source_language": source_language,
        "target_language": target_language
    }, timeout=30)
    response.raise_for_status()
    return [t["translated_text"] for t in response.json()["translations"]]

results = translate(["Hello world", "How are you?"])
print(results)
```

## Next steps

<CardGroup cols={2}>
  <Card title="Speech recognition" icon="microphone" href="/ai-workflows/asr-container">
    Transcribe audio to text on-device
  </Card>

  <Card title="Text-to-speech" icon="volume-high" href="/ai-workflows/tts-container">
    Synthesize speech from text on-device
  </Card>
</CardGroup>
