> 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/flows/text-to-speech
Content-Type: application/json

選択したモデルで音声生成を開始します。テキスト読み上げの料金体系に基づき、文字数ごとに課金されます。非同期の生成ライフサイクルを利用する場合や、`/v1/text-to-speech`で提供されていないモデルを使用する場合は、こちらを使用してください。直接的な同期音声合成には、`/v1/text-to-speech`を推奨します。

Reference: https://elevenlabs.io/docs/api-reference/flows/text-to-speech/create

## 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 (application/json)

This endpoint expects a TextToSpeechGenerationRequest.

- `TextToSpeechGenerationRequest`
  - `model_id`: `eleven_flash_v2_5` (ElevenFlashV2_5Request)
    - `text` (string, required) — 音声合成するテキストです。
    - `voice` (string, required) — 発話に使用する音声のID。
    - `language_code` (string, optional, nullable) — 出力に適用するISO 639-1言語コードです。省略するとテキストから言語を検出します。
    - `output_format` (enum, optional, default: mp3_44100_128) — `codec_sampleRateHz_bitrateKbps`形式で指定する出力のオーディオエンコーディング。`mp3_44100_192`にはクリエイター以上のプランが必要です。
      - Allowed values: `mp3_22050_32`, `mp3_24000_48`, `mp3_44100_32`, `mp3_44100_64`, `mp3_44100_96`, `mp3_44100_128`, `mp3_44100_192`
    - `pronunciation_dictionary_locators` (list of PronunciationDictionaryVersionLocator, optional) — テキストに適用する発音辞書。優先順位順に指定します。最大3件。
    - `voice_settings` (ElevenFlashV2_5VoiceSettings, optional, nullable) — 音声の保存済み設定に対するオーバーライド。この生成にのみ適用されます。
    - `webhook` (WebhookTarget, optional, nullable) — 含めると、生成が完了または失敗した時点で、生成結果をワークスペースに設定されたflows Webhookへ送信します。Webhookペイロードは、対応するGETエンドポイントの最終応答と一致します。
  - `model_id`: `eleven_multilingual_v2` (ElevenMultilingualV2Request)
    - `text` (string, required) — 音声合成するテキストです。
    - `voice` (string, required) — 発話に使用する音声のID。
    - `output_format` (enum, optional, default: mp3_44100_128) — `codec_sampleRateHz_bitrateKbps`形式で指定する出力のオーディオエンコーディング。`mp3_44100_192`にはクリエイター以上のプランが必要です。
      - Allowed values: `mp3_22050_32`, `mp3_24000_48`, `mp3_44100_32`, `mp3_44100_64`, `mp3_44100_96`, `mp3_44100_128`, `mp3_44100_192`
    - `pronunciation_dictionary_locators` (list of PronunciationDictionaryVersionLocator, optional) — テキストに適用する発音辞書。優先順位順に指定します。最大3件。
    - `voice_settings` (TtsVoiceSettings, optional, nullable) — 音声の保存済み設定に対するオーバーライド。この生成にのみ適用されます。
    - `webhook` (WebhookTarget, optional, nullable) — 含めると、生成が完了または失敗した時点で、生成結果をワークスペースに設定されたflows Webhookへ送信します。Webhookペイロードは、対応するGETエンドポイントの最終応答と一致します。
  - `model_id`: `eleven_v3` (ElevenV3Request)
    - `text` (string, required) — 音声合成するテキストです。
    - `voice` (string, required) — 発話に使用する音声のID。
    - `language_code` (string, optional, nullable) — 出力に適用するISO 639-1言語コードです。省略するとテキストから言語を検出します。
    - `output_format` (enum, optional, default: mp3_44100_128) — `codec_sampleRateHz_bitrateKbps`形式で指定する出力のオーディオエンコーディング。`mp3_44100_192`にはクリエイター以上のプランが必要です。
      - Allowed values: `mp3_22050_32`, `mp3_24000_48`, `mp3_44100_32`, `mp3_44100_64`, `mp3_44100_96`, `mp3_44100_128`, `mp3_44100_192`
    - `pronunciation_dictionary_locators` (list of PronunciationDictionaryVersionLocator, optional) — テキストに適用する発音辞書。優先順位順に指定します。最大3件。
    - `voice_settings` (ElevenV3VoiceSettings, optional, nullable) — 音声の保存済み設定に対するオーバーライド。この生成にのみ適用されます。
    - `webhook` (WebhookTarget, optional, nullable) — 含めると、生成が完了または失敗した時点で、生成結果をワークスペースに設定されたflows Webhookへ送信します。Webhookペイロードは、対応するGETエンドポイントの最終応答と一致します。

## Response

### 200

成功レスポンス。

- `id` (string, required) — 生成の一意の識別子です。出力を取得するには、対応するGETエンドポイントに渡します。
- `status` ("pending", required) — 新しく作成された生成は常に`pending`です。

## Errors

### 422 Unprocessable Entity Error

検証エラー

- `detail` (list of ValidationError, optional)

## Types

### PronunciationDictionaryVersionLocator

音声合成中に適用する発音辞書。

- `pronunciation_dictionary_id` (string, required) — `POST /v1/pronunciation-dictionaries/add-from-file`または`POST /v1/pronunciation-dictionaries/add-from-rules`で作成した発音辞書のID。
- `version_id` (string, optional, nullable) — 使用する辞書のバージョンです。省略すると最新バージョンを使用します。

### ElevenFlashV2_5VoiceSettings

音声の保存済み設定に対するオーバーライド。1回の生成に適用されます。

- `stability` (double, optional, nullable) — 生成間で音声の一貫性をどの程度維持するかを指定します。値を低くすると、より表現豊かで変化に富んだ音声になります。
- `similarity_boost` (double, optional, nullable) — 出力が元の音声にどの程度忠実かを指定します。
- `speed` (double, optional, nullable) — 生成音声の速度。1.0は音声本来の速度です。

### WebhookTarget

- `type`: `all` (WebhookTargetAll)
- `type`: `ids` (WebhookTargetIds)
  - `ids` (list of string, required) — 結果の配信先となるワークスペースフローWebhookのID。各IDはワークスペースで設定済みのフローWebhookである必要があります。

### TtsVoiceSettings

音声の保存済み設定に対するオーバーライド。1回の生成に適用されます。

- `stability` (double, optional, nullable) — 生成間で音声の一貫性をどの程度維持するかを指定します。値を低くすると、より表現豊かで変化に富んだ音声になります。
- `similarity_boost` (double, optional, nullable) — 出力が元の音声にどの程度忠実かを指定します。
- `style` (double, optional, nullable) — 話し方のスタイルをどの程度強調するかを指定します。
- `use_speaker_boost` (boolean, optional, nullable) — レイテンシー増加との引き換えに、元の話者との類似性を高めるかどうか。
- `speed` (double, optional, nullable) — 生成音声の速度。1.0は音声本来の速度です。

### ElevenV3VoiceSettings

音声の保存済み設定に対するオーバーライド。1回の生成に適用されます。

- `stability` (double, optional, nullable) — 生成間で音声の一貫性をどの程度維持するかを指定します。値を低くすると、より表現豊かで変化に富んだ音声になります。

### ValidationError

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

### ValidationErrorLocItems

## Examples

**Request**

```json
{
  "model_id": "string",
  "text": "The first move is what sets everything in motion.",
  "voice": "JBFqnCBsd6RMkjVDRZzb"
}
```

**Response**

```json
{
  "id": "JWr5N6X9ZTqf8jD2LmQb",
  "status": "pending"
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/flows/text-to-speech"

payload = {
    "model_id": "string",
    "text": "The first move is what sets everything in motion.",
    "voice": "JBFqnCBsd6RMkjVDRZzb"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/flows/text-to-speech';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"model_id":"string","text":"The first move is what sets everything in motion.","voice":"JBFqnCBsd6RMkjVDRZzb"}'
};

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/flows/text-to-speech"

	payload := strings.NewReader("{\n  \"model_id\": \"string\",\n  \"text\": \"The first move is what sets everything in motion.\",\n  \"voice\": \"JBFqnCBsd6RMkjVDRZzb\"\n}")

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

	req.Header.Add("Content-Type", "application/json")

	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/flows/text-to-speech")

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

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"model_id\": \"string\",\n  \"text\": \"The first move is what sets everything in motion.\",\n  \"voice\": \"JBFqnCBsd6RMkjVDRZzb\"\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/flows/text-to-speech")
  .header("Content-Type", "application/json")
  .body("{\n  \"model_id\": \"string\",\n  \"text\": \"The first move is what sets everything in motion.\",\n  \"voice\": \"JBFqnCBsd6RMkjVDRZzb\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.elevenlabs.io/v1/flows/text-to-speech', [
  'body' => '{
  "model_id": "string",
  "text": "The first move is what sets everything in motion.",
  "voice": "JBFqnCBsd6RMkjVDRZzb"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/flows/text-to-speech");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model_id\": \"string\",\n  \"text\": \"The first move is what sets everything in motion.\",\n  \"voice\": \"JBFqnCBsd6RMkjVDRZzb\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "model_id": "string",
  "text": "The first move is what sets everything in motion.",
  "voice": "JBFqnCBsd6RMkjVDRZzb"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/flows/text-to-speech")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
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()
```