# ODIN Audio Recording Bot Example

This example demonstrates how to create a recording bot that captures audio from other peers in an ODIN room and saves it as WAV files.

## Features

- **Automatic Recording**: Starts recording when peers begin speaking
- **WAV Output**: Saves recordings as standard WAV files (48kHz, stereo, 16-bit)
- **Peer Tracking**: Names recordings based on peer identity
- **Graceful Shutdown**: Properly finalizes recordings on exit
- **E2EE Support**: Optional end-to-end encryption

## Prerequisites

1. **ODIN Access Key**: Get one for free at [4Players ODIN](https://docs.4players.io/voice/introduction/access-keys/)
2. **wav Package**: Already included in package.json dependencies

## Configuration

Edit `index.js` and replace the placeholder values:

```javascript
const accessKey = "__YOUR_ACCESS_KEY__";  // Your ODIN access key
const roomId = "__YOUR_ROOM_ID__";        // Room to record
const userId = "RecorderBot-123";         // Bot's user ID
```

To enable E2EE (must match other peers):

```javascript
const cipherPassword = "shared-secret";
```

## Running the Bot

```bash
cd tests/audio-recording
node index.js
```

Press `Ctrl+C` to stop recording and save all files.

## How It Works

1. **Connects** to the specified ODIN room
2. **Listens** for audio data from all peers
3. **Creates** a new WAV file when a peer starts speaking
4. **Writes** audio samples to the file in real-time
5. **Finalizes** recordings when the peer stops or disconnects

## Output Files

Recordings are saved in the current directory with the naming pattern:

```
recording_{peerName}_media{id}_{timestamp}.wav
```

Example: `recording_Alice_media123_2026-01-14T12-30-45-000Z.wav`

### Audio Format

- **Sample Rate**: 48,000 Hz (ODIN native)
- **Channels**: 2 (stereo, interleaved)
- **Bit Depth**: 16-bit signed integer

## Example Output

```
=== ODIN Audio Recording Bot ===

1. Creating ODIN client...
2. Generating token from access key...
   Token generated successfully.

3. Creating room...
4. E2EE disabled (no password configured).

5. Joining room...
   Join initiated.

Recording bot is running. Press Ctrl+C to stop.

[Connection] State: Connecting
[Connection] State: Joined
[Room] Joined! Room ID: my-room, Own Peer ID: 12345
[Peer] Joined: Alice (ID: 67890)
[Media] Started: Peer 67890, Media ID: 1
[Recording] Started: ./recording_Alice_media1_2026-01-14T12-30-45-000Z.wav

[Media] Stopped: Peer 67890, Media ID: 1
[Recording] Saved: ./recording_Alice_media1_2026-01-14T12-30-45-000Z.wav (480000 samples)

^C
[Shutdown] Stopping...
[Shutdown] Room closed.
```

## Use Cases

- **Meeting Transcription**: Record meetings for later transcription
- **Quality Assurance**: Monitor and review voice communications
- **AI Training**: Collect voice data for machine learning
- **Content Creation**: Capture voice for podcasts or videos

## Related Examples

- [connection-test](../connection-test/) - Basic connection and event handling
- [sending-audio](../sending-audio/) - Send audio to the room
