# Create speech POST https://api.elevenlabs.io/v1/text-to-speech/{voice_id} Content-Type: application/json Converts text into speech using a voice of your choice and returns audio. Reference: https://elevenlabs.io/docs/api-reference/text-to-speech/convert ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Create speech version: endpoint_textToSpeech.convert paths: /v1/text-to-speech/{voice_id}: post: operationId: convert summary: Create speech description: >- Converts text into speech using a voice of your choice and returns audio. tags: - - subpackage_textToSpeech parameters: - name: voice_id in: path description: >- ID of the voice to be used. Use the [Get voices](/docs/api-reference/voices/search) endpoint list all the available voices. required: true schema: type: string - name: enable_logging in: query description: >- When enable_logging is set to false zero retention mode will be used for the request. This will mean history features are unavailable for this request, including request stitching. Zero retention mode may only be used by enterprise customers. required: false schema: type: boolean default: true - name: optimize_streaming_latency in: query description: >- You can turn on latency optimizations at some cost of quality. The best possible final latency varies by model. Possible values: 0 - default mode (no latency optimizations) 1 - normal latency optimizations (about 50% of possible latency improvement of option 3) 2 - strong latency optimizations (about 75% of possible latency improvement of option 3) 3 - max latency optimizations 4 - max latency optimizations, but also with text normalizer turned off for even more latency savings (best latency, but can mispronounce eg numbers and dates). Defaults to None. required: false schema: type: integer - name: output_format in: query description: >- Output format of the generated audio. Formatted as codec_sample_rate_bitrate. So an mp3 with 22.05kHz sample rate at 32kbs is represented as mp3_22050_32. MP3 with 192kbps bitrate requires you to be subscribed to Creator tier or above. PCM and WAV formats with 44.1kHz sample rate requires you to be subscribed to Pro tier or above. Note that the μ-law format (sometimes written mu-law, often approximated as u-law) is commonly used for Twilio audio inputs. required: false schema: $ref: >- #/components/schemas/type_textToSpeech:TextToSpeechConvertRequestOutputFormat - name: xi-api-key in: header required: false schema: type: string responses: '200': description: The generated audio file content: application/octet-stream: schema: type: string format: binary '422': description: Validation Error content: {} requestBody: content: application/json: schema: type: object properties: text: type: string description: The text that will get converted into speech. model_id: type: string default: eleven_multilingual_v2 description: >- Identifier of the model that will be used, you can query them using GET /v1/models. The model needs to have support for text to speech, you can check this using the can_do_text_to_speech property. language_code: type: string description: >- Language code (ISO 639-1) used to enforce a language for the model and text normalization. If the model does not support provided language code, an error will be returned. voice_settings: $ref: '#/components/schemas/type_:VoiceSettings' description: >- Voice settings overriding stored settings for the given voice. They are applied only on the given request. pronunciation_dictionary_locators: type: array items: $ref: >- #/components/schemas/type_:PronunciationDictionaryVersionLocator description: >- A list of pronunciation dictionary locators (id, version_id) to be applied to the text. They will be applied in order. You may have up to 3 locators per request seed: type: integer description: >- If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed. Must be integer between 0 and 4294967295. previous_text: type: string description: >- The text that came before the text of the current request. Can be used to improve the speech's continuity when concatenating together multiple generations or to influence the speech's continuity in the current generation. next_text: type: string description: >- The text that comes after the text of the current request. Can be used to improve the speech's continuity when concatenating together multiple generations or to influence the speech's continuity in the current generation. previous_request_ids: type: array items: type: string description: >- A list of request_id of the samples that were generated before this generation. Can be used to improve the speech's continuity when splitting up a large task into multiple requests. The results will be best when the same model is used across the generations. In case both previous_text and previous_request_ids is send, previous_text will be ignored. A maximum of 3 request_ids can be send. next_request_ids: type: array items: type: string description: >- A list of request_id of the samples that come after this generation. next_request_ids is especially useful for maintaining the speech's continuity when regenerating a sample that has had some audio quality issues. For example, if you have generated 3 speech clips, and you want to improve clip 2, passing the request id of clip 3 as a next_request_id (and that of clip 1 as a previous_request_id) will help maintain natural flow in the combined speech. The results will be best when the same model is used across the generations. In case both next_text and next_request_ids is send, next_text will be ignored. A maximum of 3 request_ids can be send. use_pvc_as_ivc: type: boolean default: false description: >- If true, we won't use PVC version of the voice for the generation but the IVC version. This is a temporary workaround for higher latency in PVC versions. apply_text_normalization: $ref: >- #/components/schemas/type_textToSpeech:BodyTextToSpeechFullApplyTextNormalization description: >- This parameter controls text normalization with three modes: 'auto', 'on', and 'off'. When set to 'auto', the system will automatically decide whether to apply text normalization (e.g., spelling out numbers). With 'on', text normalization will always be applied, while with 'off', it will be skipped. apply_language_text_normalization: type: boolean default: false description: >- This parameter controls language text normalization. This helps with proper pronunciation of text in some supported languages. WARNING: This parameter can heavily increase the latency of the request. Currently only supported for Japanese. required: - text components: schemas: type_textToSpeech:TextToSpeechConvertRequestOutputFormat: type: string enum: - value: alaw_8000 - value: mp3_22050_32 - value: mp3_24000_48 - value: mp3_44100_128 - value: mp3_44100_192 - value: mp3_44100_32 - value: mp3_44100_64 - value: mp3_44100_96 - value: opus_48000_128 - value: opus_48000_192 - value: opus_48000_32 - value: opus_48000_64 - value: opus_48000_96 - value: pcm_16000 - value: pcm_22050 - value: pcm_24000 - value: pcm_32000 - value: pcm_44100 - value: pcm_48000 - value: pcm_8000 - value: ulaw_8000 - value: wav_16000 - value: wav_22050 - value: wav_24000 - value: wav_32000 - value: wav_44100 - value: wav_48000 - value: wav_8000 default: mp3_44100_128 type_:VoiceSettings: type: object properties: stability: type: number format: double description: >- Determines how stable the voice is and the randomness between each generation. Lower values introduce broader emotional range for the voice. Higher values can result in a monotonous voice with limited emotion. use_speaker_boost: type: boolean description: >- This setting boosts the similarity to the original speaker. Using this setting requires a slightly higher computational load, which in turn increases latency. similarity_boost: type: number format: double description: >- Determines how closely the AI should adhere to the original voice when attempting to replicate it. style: type: number format: double description: >- Determines the style exaggeration of the voice. This setting attempts to amplify the style of the original speaker. It does consume additional computational resources and might increase latency if set to anything other than 0. speed: type: number format: double description: >- Adjusts the speed of the voice. A value of 1.0 is the default speed, while values less than 1.0 slow down the speech, and values greater than 1.0 speed it up. type_:PronunciationDictionaryVersionLocator: type: object properties: pronunciation_dictionary_id: type: string description: The ID of the pronunciation dictionary. version_id: type: string description: >- The ID of the version of the pronunciation dictionary. If not provided, the latest version will be used. required: - pronunciation_dictionary_id type_textToSpeech:BodyTextToSpeechFullApplyTextNormalization: type: string enum: - value: auto - value: 'on' - value: 'off' default: auto ``` ## SDK Code Examples ```typescript import { ElevenLabsClient, ElevenLabsEnvironment } from "@elevenlabs/elevenlabs-js"; async function main() { const client = new ElevenLabsClient({ environment: ElevenLabsEnvironment.Production, }); await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", { outputFormat: "mp3_44100_128", text: "The first move is what sets everything in motion.", modelId: "eleven_multilingual_v2", }); } main(); ``` ```python from elevenlabs import ElevenLabs from elevenlabs.environment import ElevenLabsEnvironment client = ElevenLabs( environment=ElevenLabsEnvironment.PRODUCTION ) client.text_to_speech.convert( voice_id="JBFqnCBsd6RMkjVDRZzb", output_format="mp3_44100_128", text="The first move is what sets everything in motion.", model_id="eleven_multilingual_v2" ) ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128" payload := strings.NewReader("{\n \"text\": \"The first move is what sets everything in motion.\",\n \"model_id\": \"eleven_multilingual_v2\"\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/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128") 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 \"text\": \"The first move is what sets everything in motion.\",\n \"model_id\": \"eleven_multilingual_v2\"\n}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128") .header("Content-Type", "application/json") .body("{\n \"text\": \"The first move is what sets everything in motion.\",\n \"model_id\": \"eleven_multilingual_v2\"\n}") .asString(); ``` ```php request('POST', 'https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128', [ 'body' => '{ "text": "The first move is what sets everything in motion.", "model_id": "eleven_multilingual_v2" }', 'headers' => [ 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128"); var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"text\": \"The first move is what sets everything in motion.\",\n \"model_id\": \"eleven_multilingual_v2\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Content-Type": "application/json"] let parameters = [ "text": "The first move is what sets everything in motion.", "model_id": "eleven_multilingual_v2" ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/text-to-speech/JBFqnCBsd6RMkjVDRZzb?output_format=mp3_44100_128")! 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() ```