Quickstart

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

# Export an environment variable on macOS or Linux systems
export 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, or fetch the list programmatically using the List Voices endpoint.

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

1

Install the Python SDK and PyAudio

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

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.

brew install portaudio

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

pip install murf pyaudio
2

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.

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

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.

1

Install the Python SDK

pip install murf
2

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.

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)

Next Steps

Explore API Reference for more information.