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 sign up for a free account and generate your first API Key. 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)

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.

1import pyaudio
2from murf import Murf, MurfRegion
3
4client = Murf(
5 api_key="YOUR_API_KEY", # Not required if you have set the MURF_API_KEY environment variable
6 region=MurfRegion.GLOBAL
7)
8
9# For lower latency, specify a region closer to your users
10# client = Murf(region=MurfRegion.IN) # Example: India region
11
12# Audio format settings (must match your API output)
13SAMPLE_RATE = 24000
14CHANNELS = 1
15FORMAT = pyaudio.paInt16
16
17def play_streaming_audio():
18 # Get the streaming audio generator
19 audio_stream = client.text_to_speech.stream(
20 text="Hi, How are you doing today?",
21 voice_id="Matthew",
22 model="FALCON",
23 multi_native_locale="en-US",
24 sample_rate=SAMPLE_RATE,
25 format="PCM"
26 )
27
28 # Setup audio stream for playback
29 pa = pyaudio.PyAudio()
30 stream = pa.open(format=FORMAT, channels=CHANNELS, rate=SAMPLE_RATE, output=True)
31
32 try:
33 print("Starting audio playback...")
34 for chunk in audio_stream:
35 if chunk: # Check if chunk has data
36 stream.write(chunk)
37 except Exception as e:
38 print(f"Error during streaming: {e}")
39 finally:
40 stream.stop_stream()
41 stream.close()
42 pa.terminate()
43 print("Audio streaming and playback complete!")
44
45if __name__ == "__main__":
46 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.

1from murf import Murf
2
3client = Murf()
4
5audio_res = client.text_to_speech.generate(
6 text="Lo and Behold! Speech!",
7 voice_id="en-US-terrell",
8)
9
10print(audio_res.audio_file)