> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://murf.ai/api/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://murf.ai/api/docs/_mcp/server.

# Quickstart

> Get started with Murf's text to speech API

<head>
  <link rel="canonical" href="https://murf.ai/api/docs/quickstart" />
</head>

This guide will help you get started with the Murf API. You'll learn how to get your API key, and how to make your first TTS API request.

## Generate an API Key

To use the Murf API, you need an API key. If you don't have one yet, you can [create your API Key here](https://murf.ai/api/dashboard?utm_source=murf_api_docs). Store the key in a secure location, as you'll need it to authenticate your requests. Then, save the key as an environment variable in your terminal.

**`macOS / Linux`**

```bash title="macOS / Linux"
# Export an environment variable on macOS or Linux systems
export MURF_API_KEY="your_api_key_here"
```

**`Windows`**

```bash title="Windows"
# Export an environment variable in PowerShell
setx MURF_API_KEY "your_api_key_here"
```

## Make Your First API Request (Streaming) - Falcon 2 Model

To use Murf's streaming API, you can either use the REST API using an HTTP client to receive audio data in real-time, or use one of our official SDKs.

Murf offers a variety of voice IDs for different languages and accents. You can choose a voice ID that best suits your application's needs. You can see the full list of available voice IDs [here](/api/docs/voices-styles/voice-library), or fetch the list programmatically using the [List Voices](/api/docs/api-reference/voices/get-voices) endpoint.

The following code snippets assume that you have exported the `MURF_API_KEY` system environment variable as shown above.

#### Python SDK

### Install the Python SDK and PyAudio

`pyaudio` depends on `PortAudio`, you may need to install it first.

#### Installing PortAudio (for PyAudio)

`PyAudio` depends on `PortAudio`, a cross-platform audio I/O library. You may need to install `PortAudio` separately if it's not already on your system.

#### macOS

```bash
brew install portaudio
```

#### Linux (Debian/Ubuntu)

```bash
sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
```

#### Windows

`PortAudio` is often bundled with Python distributions like Anaconda. If you encounter issues, you might need to download `PortAudio` binaries or install them via a package manager like Chocolatey:

```bash
choco install portaudio
```

Alternatively, refer to the [official PyAudio documentation](https://people.csail.mit.edu/hubert/pyaudio/#downloads) for Windows installation instructions.

Once you have installed `PortAudio`, you can install the required Python packages using the following command:

```bash
pip install murf pyaudio
```

### Make the API Call with Real-Time Playback

Once you have the SDK and PyAudio installed, and the API key set as an environment variable, you are ready to make your first streaming API call with real-time audio playback.

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

#### REST API

**`Javascript`**

```javascript title="Javascript"
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`**

```curl title="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"
}'
```

In the response, you will receive a stream of audio data in real-time. You can save this data to a file or play it directly using an audio library.

## Make Your First API Request (Non Streaming)

To use Murf, you can either us the REST API using an HTTP client, or use one of our official SDKs.

#### Python SDK

### Install the Python SDK

```bash
pip install murf
```

### Make the API Call

Once you have the SDK installed, and the API key set as an environment variable, you are ready to make your first API call.

```python

from murf import Murf

client = Murf()

audio_res = client.text_to_speech.generate(
    text="Lo and Behold! Speech!",
    voice_id="Terrell",
    locale="en-US"
)

print(audio_res.audio_file)


```

#### REST API

Murf offers a variety of voice IDs for different languages and accents. You can choose a voice ID that best suits your application's needs. You can see the full list of available voice IDs [here](/api/docs/voices-styles/voice-library), or fetch the list programmatically using the [List Voices](/api/docs/api-reference/voices/get-voices) endpoint.

The following code snippets assume that you have exported the `MURF_API_KEY` system environment variable as shown above.

**`Javascript`**

```javascript title="Javascript"
import axios from "axios";

const data = {
  text: "Hi, How are you doing today?",
  voiceId: "Natalie",
  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);
  });
```

**`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"
}'
```

You will receive a response with a link to download the generated audio file.

## Next Steps

Explore [API Reference](https://murf.ai/api/docs/api-reference/text-to-speech/stream) for more information.