# Egrobots SA Client

Python client for Egrobots Arabic Speech Analysis service.

## Installation

```bash
pip install egrobots-sa-client
```

## Quick Start

```python
from egrobots_sa_client import EgrobotsSSAClient

client = EgrobotsSSAClient()

# Conversation analysis
result = client.analyze(
    audio="audio.mp3",
    enable_translation=False  # Set True for EN + AR
)
```

## Configuration

Create a `.env` file:

```env
BASE_URL=https://your-service.com
```

## Features

- **Conversation Analysis**: Analyze audio conversations with speaker diarization
- **Bilingual Support**: Get responses in both English and Arabic
- **Progress Tracking**: Monitor upload and processing progress
- **Retry Logic**: Automatic retries for failed requests

## Usage

### Basic Analysis

```python
from egrobots_sa_client import EgrobotsSSAClient

client = EgrobotsSSAClient()

# Analyze audio file
result = client.analyze(audio="audio.mp3")
print(result)
```

### With Bilingual Support

```python
result = client.analyze(
    audio="audio.mp3",
    enable_translation=True
)

# Check if bilingual
if client.is_bilingual_response(result):
    en_result = client.extract_language_version(result, 'EN')
    ar_result = client.extract_language_version(result, 'AR')
```

### Using Audio Bytes

```python
with open("audio.mp3", "rb") as f:
    audio_bytes = f.read()

result = client.analyze(
    audio=audio_bytes,
    file_name="audio.mp3"
)
```

### Progress Monitoring

```python
def progress_handler(event_type, data):
    print(f"[{event_type}] {data}")

result = client.analyze(
    audio="audio.mp3",
    progress_callback=progress_handler
)
```

## API Reference

### `analyze()`

Main method for conversation analysis.

**Parameters:**
- `audio` (str | bytes): Path to audio file or audio bytes
- `file_name` (str): Filename when using bytes (default: "audio.wav")
- `enable_translation` (bool): Enable EN + AR bilingual response (default: False)
- `progress_callback` (Callable): Progress handler function
- `max_retries` (int): Maximum retry attempts (default: 3)
- `retry_delay` (int): Delay between retries in seconds (default: 2)

**Returns:** Dict containing analysis results

### Helper Methods

- `is_bilingual_response(result)` - Check if response has EN/AR keys
- `extract_language_version(result, language)` - Extract 'EN' or 'AR' version

## Documentation

See [CLIENT_USAGE.md](https://github.com/Mox301/egrobots-audio-analysis-agent-demo/blob/main/backend_client/CLIENT_USAGE.md) for full documentation.

## License

MIT
