> 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.

# Crea generazione vocale

POST https://api.elevenlabs.io/v1/flows/text-to-speech
Content-Type: application/json

Avvia una generazione vocale con il modello selezionato. Il costo viene calcolato per carattere tramite la fatturazione Text to Speech. Usa questo endpoint anziché `/v1/text-to-speech` per il ciclo di vita della generazione asincrona o per i modelli non disponibili lì; per la sintesi vocale diretta e sincrona, preferisci `/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) — Il testo da sintetizzare in parlato.
    - `voice` (string, required) — L'ID della voce con cui parlare.
    - `language_code` (string, optional, nullable) — Codice lingua ISO 639-1 da applicare all'output. Omettilo per rilevare la lingua dal testo.
    - `output_format` (enum, optional, default: mp3_44100_128) — La codifica audio dell'output, come `codec_sampleRateHz_bitrateKbps`. `mp3_44100_192` richiede il piano Creator o superiore.
      - 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) — Dizionari di pronuncia da applicare al testo, in ordine di precedenza. Fino a 3.
    - `voice_settings` (ElevenFlashV2_5VoiceSettings, optional, nullable) — Sostituzioni delle impostazioni salvate della voce, applicate solo a questa generazione.
    - `webhook` (WebhookTarget, optional, nullable) — Includi questa opzione per inviare il risultato della generazione ai webhook dei flussi configurati nel workspace quando viene completata o non riesce. Il payload del webhook corrisponde alla risposta finale del GET endpoint corrispondente.
  - `model_id`: `eleven_multilingual_v2` (ElevenMultilingualV2Request)
    - `text` (string, required) — Il testo da sintetizzare in parlato.
    - `voice` (string, required) — L'ID della voce con cui parlare.
    - `output_format` (enum, optional, default: mp3_44100_128) — La codifica audio dell'output, come `codec_sampleRateHz_bitrateKbps`. `mp3_44100_192` richiede il piano Creator o superiore.
      - 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) — Dizionari di pronuncia da applicare al testo, in ordine di precedenza. Fino a 3.
    - `voice_settings` (TtsVoiceSettings, optional, nullable) — Sostituzioni delle impostazioni salvate della voce, applicate solo a questa generazione.
    - `webhook` (WebhookTarget, optional, nullable) — Includi questa opzione per inviare il risultato della generazione ai webhook dei flussi configurati nel workspace quando viene completata o non riesce. Il payload del webhook corrisponde alla risposta finale del GET endpoint corrispondente.
  - `model_id`: `eleven_v3` (ElevenV3Request)
    - `text` (string, required) — Il testo da sintetizzare in parlato.
    - `voice` (string, required) — L'ID della voce con cui parlare.
    - `language_code` (string, optional, nullable) — Codice lingua ISO 639-1 da applicare all'output. Omettilo per rilevare la lingua dal testo.
    - `output_format` (enum, optional, default: mp3_44100_128) — La codifica audio dell'output, come `codec_sampleRateHz_bitrateKbps`. `mp3_44100_192` richiede il piano Creator o superiore.
      - 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) — Dizionari di pronuncia da applicare al testo, in ordine di precedenza. Fino a 3.
    - `voice_settings` (ElevenV3VoiceSettings, optional, nullable) — Sostituzioni delle impostazioni salvate della voce, applicate solo a questa generazione.
    - `webhook` (WebhookTarget, optional, nullable) — Includi questa opzione per inviare il risultato della generazione ai webhook dei flussi configurati nel workspace quando viene completata o non riesce. Il payload del webhook corrisponde alla risposta finale del GET endpoint corrispondente.

## Response

### 200

Risposta riuscita

- `id` (string, required) — L'identificatore univoco della generazione. Passalo al corrispondente endpoint GET per recuperare l'output.
- `status` ("pending", required) — Una generazione appena creata è sempre `pending`.

## Errors

### 422 Unprocessable Entity Error

Errore di convalida

- `detail` (list of ValidationError, optional)

## Types

### PronunciationDictionaryVersionLocator

Un dizionario di pronuncia da applicare durante la sintesi vocale.

- `pronunciation_dictionary_id` (string, required) — L'ID di un dizionario di pronuncia creato tramite `POST /v1/pronunciation-dictionaries/add-from-file` o `POST /v1/pronunciation-dictionaries/add-from-rules`.
- `version_id` (string, optional, nullable) — La versione del dizionario da usare. Ometti il valore per usare l'ultima versione.

### ElevenFlashV2_5VoiceSettings

Sostituzioni delle impostazioni salvate della voce, applicate a una generazione.

- `stability` (double, optional, nullable) — Quanto la voce rimane coerente tra le generazioni. Valori più bassi producono un parlato più espressivo e vario.
- `similarity_boost` (double, optional, nullable) — Quanto fedelmente l'output rispecchia la voce originale.
- `speed` (double, optional, nullable) — La velocità del parlato generato, dove 1.0 corrisponde al ritmo naturale della voce.

### WebhookTarget

- `type`: `all` (WebhookTargetAll)
- `type`: `ids` (WebhookTargetIds)
  - `ids` (list of string, required) — Gli ID dei webhook dei flow del workspace a cui inviare il risultato. Ciascuno deve essere uno dei webhook dei flow configurati nel workspace.

### TtsVoiceSettings

Sostituzioni delle impostazioni salvate della voce, applicate a una generazione.

- `stability` (double, optional, nullable) — Quanto la voce rimane coerente tra le generazioni. Valori più bassi producono un parlato più espressivo e vario.
- `similarity_boost` (double, optional, nullable) — Quanto fedelmente l'output rispecchia la voce originale.
- `style` (double, optional, nullable) — Quanto viene enfatizzato lo stile di parlato.
- `use_speaker_boost` (boolean, optional, nullable) — Indica se aumentare la somiglianza con l'interlocutore originale, a fronte di una certa latenza.
- `speed` (double, optional, nullable) — La velocità del parlato generato, dove 1.0 corrisponde al ritmo naturale della voce.

### ElevenV3VoiceSettings

Sostituzioni delle impostazioni salvate della voce, applicate a una generazione.

- `stability` (double, optional, nullable) — Quanto la voce rimane coerente tra le generazioni. Valori più bassi producono un parlato più espressivo e vario.

### 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()
```