# 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. ## 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 - 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 - 'null' - 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 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/V1TextToSpeechVoiceIdPostParametersOutputFormat - name: xi-api-key in: header required: true 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: $ref: '#/components/schemas/Body_text_to_speech_full' components: schemas: V1TextToSpeechVoiceIdPostParametersOutputFormat: type: string enum: - value: mp3_22050_32 - value: mp3_24000_48 - value: mp3_44100_32 - value: mp3_44100_64 - value: mp3_44100_96 - value: mp3_44100_128 - value: mp3_44100_192 - value: pcm_8000 - value: pcm_16000 - value: pcm_22050 - value: pcm_24000 - value: pcm_32000 - value: pcm_44100 - value: pcm_48000 - value: ulaw_8000 - value: alaw_8000 - value: opus_48000_32 - value: opus_48000_64 - value: opus_48000_96 - value: opus_48000_128 - value: opus_48000_192 VoiceSettingsResponseModel: type: object properties: stability: type: - number - 'null' format: double use_speaker_boost: type: - boolean - 'null' similarity_boost: type: - number - 'null' format: double style: type: - number - 'null' format: double speed: type: - number - 'null' format: double PronunciationDictionaryVersionLocatorRequestModel: type: object properties: pronunciation_dictionary_id: type: string version_id: type: - string - 'null' required: - pronunciation_dictionary_id BodyTextToSpeechFullApplyTextNormalization: type: string enum: - value: auto - value: 'on' - value: 'off' Body_text_to_speech_full: type: object properties: text: type: string model_id: type: string language_code: type: - string - 'null' voice_settings: oneOf: - $ref: '#/components/schemas/VoiceSettingsResponseModel' - type: 'null' pronunciation_dictionary_locators: type: - array - 'null' items: $ref: >- #/components/schemas/PronunciationDictionaryVersionLocatorRequestModel seed: type: - integer - 'null' previous_text: type: - string - 'null' next_text: type: - string - 'null' previous_request_ids: type: - array - 'null' items: type: string next_request_ids: type: - array - 'null' items: type: string use_pvc_as_ivc: type: boolean apply_text_normalization: $ref: '#/components/schemas/BodyTextToSpeechFullApplyTextNormalization' apply_language_text_normalization: type: boolean required: - text ``` ## SDK Code Examples ```typescript import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js"; async function main() { const client = new ElevenLabsClient({ environment: "https://api.elevenlabs.io", }); 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 client = ElevenLabs( base_url="https://api.elevenlabs.io" ) 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("xi-api-key", "xi-api-key") 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["xi-api-key"] = 'xi-api-key' 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("xi-api-key", "xi-api-key") .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', 'xi-api-key' => 'xi-api-key', ], ]); 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("xi-api-key", "xi-api-key"); 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 = [ "xi-api-key": "xi-api-key", "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() ```