> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 音楽をアップロード

POST https://api.elevenlabs.io/v1/music/upload
Content-Type: multipart/form-data

後でインペインティングに使用する音楽ファイルをアップロードします。アップロード料金は楽曲生成と同じです。アップロードされたすべてのコンテンツは著作権侵害について検査されます。著作権で保護されたコンテンツが検出された場合でも、リクエスト費用の半額が請求されます。

Reference: https://elevenlabs.io/docs/api-reference/music/upload

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `file` (file, required) — アップロードするオーディオファイル。
- `extract_composition_plan` (V1MusicUploadPostRequestBodyContentMultipartFormDataSchemaExtractCompositionPlan, optional) — アップロードした曲の構成プランを生成して返すかどうか。返す構成プランの形式を制御するには、モデルID（`music_v1`、`music_v2`、または`music_v2_5`）を渡します。`true`／`false`の指定は非推奨です。`true`の場合はデフォルトで`music_v1`のプラン形式になります。これを有効にするとレイテンシーが増加します。
- `with_timestamps` (boolean, optional) — アップロードした楽曲を文字起こしし、単語レベルのタイムスタンプを返すかどうか。Trueの場合、レスポンスにwords_timestampsが含まれますが、レイテンシーが増加します。
- `with_waveform_visual` (boolean, optional) — アップロードした楽曲の視覚的な波形を返すかどうか。

## Response

### 200

任意の構成プランを含む音楽ファイルを正常にアップロードしました。

- `song_id` (string, required) — アップロードされた曲の一意の識別子
- `composition_plan` (MusicUploadResponseCompositionPlan, optional, nullable) — アップロードした曲から抽出された構成プラン。リクエスト本文で`extract_composition_plan`が指定された場合にのみ存在します。
- `words_timestamps` (list of WordTimestamp, optional, nullable) — アップロードした楽曲から文字起こしされた単語レベルのタイムスタンプ。リクエスト本文で`with_timestamps`がTrueの場合にのみ含まれます。
- `waveform_visual` (list of integer, optional, nullable) — アップロードされた楽曲のプレビュー表示用の低解像度波形です。オーディオ1秒あたり4つの値を保持し、値の範囲は-1000～1000です。ステレオは単一チャンネルにミックスダウンされます。リクエスト本文で`with_waveform_visual`がTrueの場合にのみ含まれます。

## Errors

### 422 Unprocessable Entity Error

検証エラー

- `detail` (list of ValidationError, optional)

## Types

### MusicUploadResponseCompositionPlan

アップロードした曲から抽出された構成プラン。リクエスト本文で`extract_composition_plan`が指定された場合にのみ存在します。

### WordTimestamp

- `word` (string, required)
- `start_ms` (integer, required)
- `end_ms` (integer, required)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### MusicPrompt

`music_v1`モデルの構成プランです。このフィールドを他のモデルで使用するとエラーになります。

- `positive_global_styles` (list of string, required) — 曲全体に含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `negative_global_styles` (list of string, required) — 曲全体に含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `sections` (list of SongSection, required) — 曲のセクション。

### CompositionPlan

`music_v2`および`music_v2_5`モデルの構成プランです。このフィールドを他のモデルで使用するとエラーになります。

- `chunks` (list of CompositionPlanChunksItems, required) — 生成を構成するチャンク。

### ValidationErrorLocItems

### SongSection

- `section_name` (string, required) — セクションの名前。1文字から100文字の範囲で指定します。
- `positive_local_styles` (list of string, required) — このセクションに含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `negative_local_styles` (list of string, required) — このセクションに含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。
- `duration_ms` (integer, required) — セクションの長さ（ミリ秒）。3000ms～120000msである必要があります。
- `lines` (list of string, required) — セクションの歌詞。1セクションあたり最大30行、1行あたり最大200文字です。
- `source_from` (SectionSource, optional, nullable) — セクションの抽出元となる任意のソースです。インペインティングに使用します。

### CompositionPlanChunksItems

### SectionSource

- `song_id` (string, required) — セクションの元となる楽曲のID。楽曲を生成した際のレスポンスヘッダーで楽曲IDを確認できます。
- `range` (TimeRange, required) — 元の曲から抽出する範囲。
- `negative_ranges` (list of TimeRange, optional) — 「range」から除外する範囲。

### GenerationChunk-Input

- `text` (string, required) — このチャンクに生成するテキスト設定。先頭に任意のセクション名を角括弧で含めることができます（例：\[Verse 1]）。歌詞行や、中括弧で囲んだインライン指示（例：\{scratching}）も含められます。セクション名は1～100文字にする必要があります。最大30行まで指定でき、各行は最大200文字です。
- `duration_ms` (integer, required) — チャンクの長さ（ミリ秒）。3000ms～120000msである必要があります。
- `positive_styles` (list of string, required) — このチャンクに含めるスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。最初のチャンクのスタイルは、全体のトーンとジャンルを決めるため最も重要です。後続のチャンクのスタイルは、ニュアンス、展開、強調を加えたり、曲の方向性を変えたりするために使用できます。方向性が確立するまで、初期のチャンクには少なくとも6～7個のスタイルを含めることを目指してください。「great production quality」のような汎用的なスタイルは、リストに追加するデフォルトスタイルとして適しています。
- `negative_styles` (list of string, optional) — このチャンクに含めないスタイルと音楽的な指示。最良の結果を得るには英語を使用してください。空のままにするのが適切なデフォルトです。特定のスタイルや方向性を明示的に避けたい場合にのみ、このフィールドを使用してください。
- `context_adherence` (enum, optional, default: high) — モデルが周囲のチャンクのコンテキストにどの程度従うかを指定します。忠実度が低い場合、モデルはコンテキストから逸脱してより創造的になります。忠実度が高い場合、モデルはコンテキストとの一貫性をより保ちます。
  - Allowed values: `low`, `medium`, `high`
- `conditioning_ref` (AudioRefChunk, optional, nullable) — 生成の条件付けに使用するオーディオ参照。最初のチャンクは以降のすべてのチャンクの生成に影響するため、最も重要です。曲全体に条件付けを適用する場合は、最初のチャンクから開始してください。
- `condition_strength` (enum, optional, nullable) — モデルが条件付け参照にどの程度忠実に従うかを指定します。強度が低い場合、モデルはより創造的になり、参照から逸脱します。強度が高い場合、モデルは参照との一貫性をより保ちます。
  - Allowed values: `low`, `medium`, `high`, `xhigh`

### AudioRefChunk

- `song_id` (string, required) — チャンクの元となる楽曲のID。楽曲を生成した際のレスポンスヘッダーで楽曲IDを確認できます。
- `range` (TimeRange, required) — 楽曲から抽出する時間範囲です。

### TimeRange

- `start_ms` (integer, required)
- `end_ms` (integer, required)

## Examples

**Request**

```json
{
  "file": "<file: string>"
}
```

**Response**

```json
{
  "song_id": "jR4Xz8kL2mNpQ9wVtY1b"
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/music/upload"

files = { "file": "open('string', 'rb')" }
payload = {
    "extract_composition_plan": ,
    "with_timestamps": ,
    "with_waveform_visual": 
}

response = requests.post(url, data=payload, files=files)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/music/upload';
const form = new FormData();
form.append('extract_composition_plan', '');
form.append('file', 'string');
form.append('with_timestamps', '');
form.append('with_waveform_visual', '');

const options = {method: 'POST'};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.elevenlabs.io/v1/music/upload"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"extract_composition_plan\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_timestamps\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_waveform_visual\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/music/upload")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"extract_composition_plan\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_timestamps\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_waveform_visual\"\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.elevenlabs.io/v1/music/upload")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"extract_composition_plan\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_timestamps\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_waveform_visual\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/music/upload', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ]
  ]
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/music/upload");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"extract_composition_plan\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_timestamps\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"with_waveform_visual\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation
let parameters = [
  [
    "name": "extract_composition_plan",
    "value": 
  ],
  [
    "name": "file",
    "fileName": "string"
  ],
  [
    "name": "with_timestamps",
    "value": 
  ],
  [
    "name": "with_waveform_visual",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/music/upload")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```