# AIOZ Stream — Media (Audio)

SDK package: @aiozstream/nodejs-client

## Setup

```typescript
import StreamClient from '@aiozstream/nodejs-client'

const client = new StreamClient({
  publicKey: process.env.AIOZ_PUBLIC_KEY,
  secretKey: process.env.AIOZ_SECRET_KEY
})
```

Note: Audio uses the same `client.video.*` methods as video — the `type` field differentiates them.

---

## Create Audio Object

POST https://api.aiozstream.network/api/media/create

```typescript
const audio = await client.video.create({
  title: 'My Podcast Episode',
  type: 'audio',           // required, must be 'audio'
  description: 'optional',
  isPublic: true,
  tags: ['podcast'],
  qualities: [
    {
      resolution: 'highest', // 'standard'|'good'|'highest'|'lossless'
      type: 'hls',
      containerType: 'mpegts',
      audioConfig: {
        codec: 'aac',       // only 'aac' is supported
        bitrate: 320000,
        channels: '2',      // '2' (stereo)
        sampleRate: 44100,
        language: 'en',
        index: 0
      }
    }
  ]
})
const audioId = audio.data.id
```

Valid sample rates: 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000

---

## Upload Audio File

```typescript
await client.video.uploadPart(audioId, './audio.mp3')
await client.video.uploadVideoComplete(audioId)
```

---

## Full Audio Upload Flow

```typescript
const audio = await client.video.create({ title: 'My Audio', type: 'audio' })
const audioId = audio.data.id

await client.video.uploadPart(audioId, './podcast.mp3')
await client.video.uploadVideoComplete(audioId)

// Poll for done
let status = 'encoding'
while (status !== 'done' && status !== 'failed') {
  await new Promise(r => setTimeout(r, 5000))
  const detail = await client.video.getDetail(audioId)
  status = detail.data.status
}

const detail = await client.video.getDetail(audioId)
console.log(detail.data.assets.hlsUrl)
```
