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

# 音声をアップロード

> 音声ファイルをアップロードして音声関連 API で使用する URL を取得します

> [!NOTE]
>
> **中国本土のユーザー向け:** 中国本土のユーザーは `https://toapis.cn` を API エンドポイント (Base URL) としてご利用ください.本ドキュメント内の例では `https://toapis.com` を `https://toapis.cn` に置き換えてください.

> [!NOTE]
>
> **ドキュメントの Playground はファイルアップロードに対応していません:** テストには下記の cURL,Python,または JavaScript の例をご利用ください.

## なぜ先に音声をアップロードするのか

1. **入力方法の統一** - ローカル音声を一度アップロードして公開 URL を再利用できます
2. **転送の削減** - 同じ音声を複数のリクエストで再利用できます

## Authorizations

**Authorization** `string` *required*

Bearer Token を使用して認証します

API Key は [API Key 管理ページ](https://toapis.com/console/token) から取得できます

```
Authorization: Bearer YOUR_API_KEY
```

## Body

**file** `file` *required*

音声ファイル

**対応形式:**

* MP3 (.mp3)
* WAV (.wav)
* M4A (.m4a)

**制限:**

* 最大ファイルサイズ: 50MB

**purpose** `string`

アップロード目的 (任意)

デフォルト: `generation`

## レスポンス

**success** `boolean`

リクエストが成功したかどうか

**data** `object`

**レスポンス data**

**id** `string`

追跡用のアップロードレコード ID

**url** `string`

アップロードした音声の公開 URL

**mime\_type** `string`

音声の MIME タイプ, 例: `audio/mpeg`

**size** `integer`

ファイルサイズ (バイト)

```bash cURL theme={null}
curl --request POST \
  --url https://toapis.com/v1/uploads/audios \
  --header 'Authorization: Bearer <token>' \
  --form 'file=@/path/to/your/audio.mp3'
```

```python Python theme={null}
import requests

with open('audio.mp3', 'rb') as f:
    response = requests.post(
        "https://toapis.com/v1/uploads/audios",
        headers={
            "Authorization": "Bearer your-ToAPIs-key"
        },
        files={
            "file": f
        }
    )

result = response.json()
audio_url = result['data']['url']
print(f"音声 URL: {audio_url}")
```

```javascript JavaScript theme={null}
(async () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'audio/mpeg,audio/wav,audio/mp4';
fileInput.click();
await new Promise(resolve => fileInput.onchange = resolve);

const formData = new FormData();
formData.append('file', fileInput.files[0]);

const uploadResponse = await fetch('https://toapis.com/v1/uploads/audios', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-ToAPIs-key'
  },
  body: formData
});

const uploadResult = await uploadResponse.json();
console.log('アップロード結果:', uploadResult);
})();
```

```json 200 成功 theme={null}
{
  "success": true,
  "message": "",
  "data": {
    "id": "upload_abc12345",
    "url": "https://files.toapis.com/uploads/123/audios/1737568800_abc12345.mp3",
    "mime_type": "audio/mpeg",
    "size": 1892345
  }
}
```

```json 400 Bad Request theme={null}
{
  "success": false,
  "message": "Unsupported or invalid audio file. Allowed: MP3, WAV, M4A"
}
```

```json 400 File Too Large theme={null}
{
  "success": false,
  "message": "Audio too large. Maximum size is 50MB"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.