> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://murf.ai/api/docs/text-to-speech/overview/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://murf.ai/_mcp/server. > Convert text into high-quality speech using Murf’s real-time Streaming API or the Synthesize Speech API. Murf provides a powerful [Text to Speech](/api/docs/api-reference/text-to-speech/generate) API that allows you to generate high-quality, natural-sounding speech from text input. The API supports over 35 languages and 20 speaking styles across 150+ voices to suit your application's needs. ## Quickstart Murf offers two ways to generate speech: * [Streaming API](/api/docs/api-reference/text-to-speech/stream): Real-time, low-latency speech generation for conversational AI and real-time voice agents. It delivers natural speech with time-to-first-audio under 100ms. * [Synthesize Speech](/api/docs/api-reference/text-to-speech/generate) : Designed for studio-quality speech synthesis. Ideal for multimedia applications requiring rich, expressive voiceovers. You can [Generate your API key](https://murf.ai/api/dashboard?utm_source=murf_api_docs) from the Murf API Dashboard and optionally set it as an environment variable. #### Install the SDK If you're using Python, you can install Murf's Python SDK using the following command: ```bash pip install murf ``` #### Using the Streaming API **`Python SDK`** ```python title="Python SDK" import pyaudio from murf import Murf, MurfRegion client = Murf( api_key="YOUR_API_KEY", # Not required if you have set the MURF_API_KEY environment variable region=MurfRegion.GLOBAL ) # For lower latency, specify a region closer to your users # client = Murf(region=MurfRegion.IN) # Example: India region # Audio format settings (must match your API output) SAMPLE_RATE = 24000 CHANNELS = 1 FORMAT = pyaudio.paInt16 def play_streaming_audio(): # Get the streaming audio generator audio_stream = client.text_to_speech.stream( text="Hi, How are you doing today?", voice_id="Gordon", model="falcon-2", locale="en-US", sample_rate=SAMPLE_RATE, format="PCM" ) # Setup audio stream for playback pa = pyaudio.PyAudio() stream = pa.open(format=FORMAT, channels=CHANNELS, rate=SAMPLE_RATE, output=True) try: print("Starting audio playback...") for chunk in audio_stream: if chunk: # Check if chunk has data stream.write(chunk) except Exception as e: print(f"Error during streaming: {e}") finally: stream.stop_stream() stream.close() pa.terminate() print("Audio streaming and playback complete!") if __name__ == "__main__": play_streaming_audio() ``` ```js const axios = require('axios'); const Speaker = require('speaker'); async function playStreamingAudio() { const apiUrl = "https://global.api.murf.ai/v1/speech/stream"; // Global endpoint // const apiUrl = "https://in.api.murf.ai/v1/speech/stream"; // Regional endpoint const apiKey = process.env.MURF_API_KEY; // Use environment variable const requestBody = { text: "Hi, How are you doing today?", voiceId: "Gordon", locale:"en-US", model:"falcon-2", format: "PCM", sampleRate: 24000, }; try { const response = await axios.post(apiUrl, requestBody, { headers: { "Content-Type": "application/json", "api-key": apiKey, }, responseType: "stream", }); // Setup speaker for audio playback const speaker = new Speaker({ channels: 1, bitDepth: 16, sampleRate: 24000 }); console.log("Starting audio playback..."); response.data.pipe(speaker); speaker.on('close', () => { console.log("Audio playback complete!"); }); speaker.on('error', (err) => { console.error("Speaker error:", err); }); } catch (error) { console.error("Error:", error.message); } } playStreamingAudio(); ``` ```curl # Global URL curl -X POST https://global.api.murf.ai/v1/speech/stream \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "Hi, How are you doing today?", "voiceId": "Gordon", "locale":"en-US", "model": "falcon-2" }' # Eg : Regional URL curl -X POST https://in.api.murf.ai/v1/speech/stream \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "Hi, How are you doing today?", "voiceId": "Gordon", "locale":"en-US", "model": "falcon-2" }' ``` #### Using the Non-Streaming API **`Python SDK`** ```python title="Python SDK" from murf import Murf client = Murf( api_key="YOUR_API_KEY" # Not required if you have set the MURF_API_KEY environment variable ) res = client.text_to_speech.generate( text="There is much to be said", voice_id="Terrell", locale="en-US" ) print(res.audio_file) ``` **`Javascript`** ```javascript title="Javascript" import axios from "axios"; const data = { text: "There is much to be said", voiceId: "Terrell", locale:"en-US" }; axios .post("https://api.murf.ai/v1/speech/generate", data, { headers: { "Content-Type": "application/json", Accept: "application/json", "api-key": process.env.MURF_API_KEY, }, }) .then((response) => { console.log(response.data.audioFile); }) .catch((error) => { console.error("Error:", error); }); ``` **`curl`** ```curl title="curl" curl -X POST https://api.murf.ai/v1/speech/generate \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "There is much to be said", "voiceId": "Terrell", "locale":"en-US" }' ``` A link to the audio file will be returned in the response. You can use this link to download the audio file and use it wherever you need it. The audio file will be available for download for 72 hours after generation. #### [Streaming](/api/docs/text-to-speech/streaming) Generate speech in real-time with low latency and high quality using the streaming API #### [WebSockets](/api/docs/text-to-speech/web-sockets) Build responsive, real-time voice applications with low-latency, bidirectional streaming. #### [Voices & Styles](/api/docs/voices-styles/overview) Explore Murf's extensive library of voices and styles #### [Speech Customization](/api/docs/text-to-speech/speech-customization) Craft unique and expressive voiceovers for your application ## Supported Output Formats The API supports multiple output formats for the generated audio - the default output format is **wav**. You can choose from the following formats: | Format | Description | | -------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | **WAV** | Uncompressed audio format, useful for low-latency applications as it eliminates the need for decoding. | | **MP3** | Compressed audio format, widely supported and suitable for applications where file size is a concern. | | **FLAC** | Lossless compressed audio format, ideal for applications requiring high audio fidelity without the large file size of uncompressed formats. | | **ALAW** | Compressed audio format commonly used in telephony, providing a good balance between audio quality and bandwidth usage. | | **ULAW** | Another compressed audio format used in telephony, similar to ALAW but with slightly different compression characteristics. | | **OGG** | Efficient compressed format offering better quality at similar bitrates; ideal for web playback and streaming. | | **PCM** | Raw, uncompressed audio data; useful for telephony, DSP pipelines, and systems requiring raw waveform access. | You can specify the output format using the `format` parameter in the request payload. Furthermore, you can use the `channelType` and `sampleRate` keys to specify the channel type and sample rate for the generated audio. The API supports stereo and mono channels, and sample rates of 8000, 24000, 44100, and 48000 Hz. **`Python SDK`** ```python title="Python SDK" from murf import Murf client = Murf() res = client.text_to_speech.generate( text="Hi, How are you doing today?", voice_id="Julia", locale="en-US", format="MP3", channel_type="STEREO", sample_rate=44100 ) ``` **`Javascript`** ```javascript title="Javascript" import axios from "axios"; const data = { text: "Hi, How are you doing today?", voiceId: "Natalie", locale:"en-US", format: "MP3", channelType: "MONO", sampleRate: 44100, }; axios .post("https://api.murf.ai/v1/speech/generate", data, { headers: { "Content-Type": "application/json", Accept: "application/json", "api-key": process.env.MURF_API_KEY, }, }) .then((response) => { console.log(response.data.audioFile); }); ``` **`curl`** ```curl title="curl" curl -X POST https://api.murf.ai/v1/speech/generate \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "Hi, How are you doing today?", "voiceId": "Natalie", "locale":"en-US", "format": "MP3", "channelType": "MONO", "sampleRate": 44100 }' ``` > **Warning** > > ULAW and ALAW formats only support mono channel type and a sample rate of 8000 > Hz. If you specify a different channel type or sample rate, the API will > default to the supported values. #### Base64 Encoding **Note:** Not available for Streaming API. You can choose to receive the audio file in Base64 encoded format by setting the `encodeAsBase64` parameter to `true` in the request payload. This can be useful when you need to embed the audio file directly into your application or store it in a database. This will also enable zero retention of audio data on Murf's servers. **`Python SDK`** ```python title="Python SDK" from murf import Murf client = Murf() res = client.text_to_speech.generate( text="Hi, How are you doing today?", voice_id="Julia", encode_as_base_64=True ) ``` **`Javascript`** ```javascript title="Javascript" import axios from "axios"; const data = { text: "Hi, How are you doing today?", voiceId: "Natalie", encodeAsBase64: true, }; axios .post("https://api.murf.ai/v1/speech/generate", data, { headers: { "Content-Type": "application/json", Accept: "application/json", "api-key": process.env.MURF_API_KEY, }, }) .then((response) => { console.log(response.data.audioFile); }); ``` **`curl`** ```curl title="curl" curl -X POST https://api.murf.ai/v1/speech/generate \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "text": "Hi, How are you doing today?", "voiceId": "Natalie", "encodeAsBase64": true }' ``` The response will include the audio file encoded in Base64 format, which you can decode and use as needed. **`Response`** ```json title="Response" { ..., "encodedAudio": "U29tZSB0ZXh0IHNob3cgd2l0aCB0aGF0Lg==...", ... } ``` ## gzip Support **Note:** Not supported for Streaming API. Responses from Murf API can be gzipped by including "gzip" in the `accept-encoding` header of your requests. This is especially beneficial if you choose to return the audio response as a Base64 encoded string. **`Python SDK`** ```python title="Python SDK" from murf import Murf client = Murf() client.text_to_speech.generate( text="Hi, How are you doing today?", voice_id="Natalie", encode_as_base_64=True, request_options={ 'additional_headers': { 'accept-encoding': 'gzip' } } ) ``` **`Javascript`** ```javascript title="Javascript" import axios from "axios"; const url = "https://api.murf.ai/v1/speech/generate"; const data = { text: "Hi, How are you doing today?", voiceId: "Natalie", }; axios .post(url, data, { headers: { "api-key": process.env.MURF_API_KEY, "Content-Type": "application/json", "accept-encoding": "gzip", }, }) .then((response) => { console.log(response.data); }) .catch((error) => { console.error("Error:", error); }); ``` **`curl`** ```curl title="curl" curl -X POST https://api.murf.ai/v1/speech/generate \ -H "api-key: $MURF_API_KEY" \ -H "Content-Type: application/json" \ -H "accept-encoding: gzip" \ -d '{ "text": "Hi, How are you doing today?", "voiceId": "Natalie" }' ``` ## FAQ #### What are audio formats, and how do I choose the right one? Audio formats define how sound data is stored and compressed. Choose **MP3** for web streaming due to its small size; **OGG** as an open, efficient option for streaming with better quality at similar bitrates; **WAV** for highest-quality, uncompressed recordings and editing; **FLAC** for lossless compression with reduced size; **ALAW/ULAW** for telephony systems; and **PCM** for raw, uncompressed audio when you need maximum compatibility or low-level processing (note: large files). **Base64** encodes audio as text, making it useful for embedding in APIs or data transfers. #### What are audio channels, and when should I use MONO vs. STEREO? Audio channels define the number of sound signals in a recording. * Mono (1 channel): Best for voice calls, podcasts, and telephony—ensuring clarity. * Stereo (2 channels): Preferred for music, films, and immersive experiences where directional sound matters. #### What is a sample rate, and which one should I choose? The sample rate (measured in Hz) determines audio detail: * 8000 Hz: Telephony & VoIP (mandatory for ALAW/ULAW). * 24000 Hz: Balanced for podcasts and e-learning. * 44100 Hz: CD-quality audio. * 48000 Hz: Industry standard for film and professional audio. Higher sample rates improve quality but increase file size—choose based on your needs. #### What is Base64 audio, and when should I use it? Base64 encodes audio as text, making it useful for embedding in APIs, JSON, XML, or data transfers where binary formats aren't supported. Base64 is useful for transmitting audio files in web-based applications. Since Base64 increases file size compared to its original format, it's best used for compatibility rather than storage efficiency. > Convert text into high-quality speech using Murf’s real-time Streaming API or the Synthesize Speech API.