LiveKit and Murf

Build voice and multimodal conversational AI applications with Murf TTS

This is an official integration of Murf for LiveKit, a framework for building voice and multimodal conversational AI applications. You can install the Python package livekit-murf to use Murf as a TTS service in your LiveKit Agents, providing high-quality voice synthesis with real-time streaming capabilities.

Introduction to LiveKit

LiveKit is an open-source platform for building scalable, real-time voice and video applications. LiveKit Agents is a framework that simplifies the creation of conversational AI applications by providing a structured way to connect speech-to-text (STT), large language models (LLMs), and text-to-speech (TTS) services.

With the official Murf TTS integration for LiveKit Agents, you can build sophisticated voice applications that combine Murf’s natural-sounding voices with other AI services, creating end-to-end conversational experiences.

Features

The Murf TTS integration for LiveKit Agents provides a comprehensive set of features for building voice applications:

  • High-Quality Voice Synthesis: Leverage Murf’s advanced TTS technology with access to over 150 voices across 35+ languages
  • Real-time Streaming: WebSocket-based streaming for low-latency audio generation, perfect for interactive conversations
  • Voice Customization: Control voice style, rate and pitch to match your application’s needs
  • Multi-Language Support: Multiple languages and locales with native speaker quality
  • Agent Framework Integration: Seamless integration with LiveKit’s Agent framework for building conversational AI
  • Flexible Configuration: Comprehensive audio format and quality options including sample rate, channel type, and output formats

Compatibility

This integration requires livekit-agents >= 1.2.18. The examples use the modern AgentServer pattern which is available in recent versions of LiveKit Agents. For compatibility with other versions, please refer to the LiveKit Agents documentation.

Installation

You can install the Murf TTS integration for LiveKit Agents using several methods:

Using pip

The recommended way to install the package is using pip:

$pip install livekit-murf

Using uv

If you’re using uv as your Python package manager:

$uv add livekit-murf

From source

To install from source, clone the repository and install it in development mode:

$git clone https://github.com/murf-ai/livekit-murf.git
>cd livekit-murf
>pip install -e .

Quick Start

Get Your Murf API Key

Before you can use the integration, you’ll need a Murf API key. Sign up at the Murf API Dashboard and generate your API key from the dashboard.

Basic Usage

Here’s a simple example of how to create a LiveKit Agent Worker with Murf TTS:

1import logging
2import os
3from dotenv import load_dotenv
4from livekit.agents import (
5 Agent,
6 AgentServer,
7 AgentSession,
8 JobContext,
9 JobProcess,
10 MetricsCollectedEvent,
11 cli,
12 metrics,
13 room_io,
14)
15from livekit.plugins import silero, deepgram, murf
16from livekit.plugins import openai as openai_plugin
17
18logger = logging.getLogger("murf-agent")
19load_dotenv()
20
21class MyAgent(Agent):
22 def __init__(self) -> None:
23 super().__init__(
24 instructions="You are a voice agent built using Murf TTS. Keep responses short and natural."
25 )
26
27 async def on_enter(self):
28 await self.session.say(
29 "Hi, I am a voice agent powered by Murf, how can I help you?"
30 )
31
32server = AgentServer()
33
34def prewarm(proc: JobProcess):
35 proc.userdata["vad"] = silero.VAD.load()
36
37server.setup_fnc = prewarm
38
39@server.rtc_session()
40async def entrypoint(ctx: JobContext):
41 ctx.log_context_fields = {"room": ctx.room.name}
42
43 session = AgentSession(
44 stt="deepgram/nova-3",
45 llm="openai/gpt-4o",
46 tts=murf.TTS(voice="Matthew", style="Conversation"),
47 vad=ctx.proc.userdata["vad"],
48 preemptive_generation=True,
49 resume_false_interruption=True,
50 false_interruption_timeout=1.0,
51 )
52
53 usage_collector = metrics.UsageCollector()
54
55 @session.on("metrics_collected")
56 def on_metrics(ev: MetricsCollectedEvent):
57 metrics.log_metrics(ev.metrics)
58 usage_collector.collect(ev.metrics)
59
60 async def log_usage():
61 logger.info(f"Usage: {usage_collector.get_summary()}")
62
63 ctx.add_shutdown_callback(log_usage)
64
65 await session.start(
66 agent=MyAgent(),
67 room=ctx.room,
68 room_options=room_io.RoomOptions(
69 audio_input=room_io.AudioInputOptions()
70 ),
71 )
72
73if __name__ == "__main__":
74 cli.run_app(server)

Complete Example with Custom Configuration

Here’s a more advanced example showing how to customize the Murf TTS configuration with metrics and error handling:

1import logging
2import os
3from dotenv import load_dotenv
4from livekit.agents import (
5 Agent,
6 AgentServer,
7 AgentSession,
8 JobContext,
9 JobProcess,
10 MetricsCollectedEvent,
11 cli,
12 metrics,
13 room_io,
14)
15from livekit.plugins import silero, deepgram, murf
16from livekit.plugins import openai as openai_plugin
17
18logger = logging.getLogger("murf-agent")
19load_dotenv()
20
21class CustomAgent(Agent):
22 def __init__(self) -> None:
23 super().__init__(
24 instructions="You are a helpful assistant with a natural speaking style. Provide detailed but concise responses."
25 )
26
27 async def on_enter(self):
28 await self.session.say(
29 "Hello! I'm powered by Murf's high-quality voice synthesis. How can I assist you today?"
30 )
31
32server = AgentServer()
33
34def prewarm(proc: JobProcess):
35 proc.userdata["vad"] = silero.VAD.load()
36
37server.setup_fnc = prewarm
38
39@server.rtc_session()
40async def entrypoint(ctx: JobContext):
41 ctx.log_context_fields = {"room": ctx.room.name}
42
43 session = AgentSession(
44 stt="deepgram/nova-3",
45 llm="openai/gpt-4o",
46 tts=murf.TTS(
47 voice="Matthew",
48 style="Conversation",
49 rate=5,
50 pitch=0,
51 model="FALCON",
52 sample_rate=24000,
53 ),
54 vad=ctx.proc.userdata["vad"],
55 preemptive_generation=True,
56 resume_false_interruption=True,
57 false_interruption_timeout=1.0,
58 )
59
60 usage_collector = metrics.UsageCollector()
61
62 @session.on("metrics_collected")
63 def on_metrics(ev: MetricsCollectedEvent):
64 metrics.log_metrics(ev.metrics)
65 usage_collector.collect(ev.metrics)
66
67 async def log_usage():
68 summary = usage_collector.get_summary()
69 logger.info(f"Session usage: {summary}")
70
71 ctx.add_shutdown_callback(log_usage)
72
73 await session.start(
74 agent=CustomAgent(),
75 room=ctx.room,
76 room_options=room_io.RoomOptions(
77 audio_input=room_io.AudioInputOptions()
78 ),
79 )
80
81if __name__ == "__main__":
82 cli.run_app(server)

💡 Try it out: For complete working examples and deployment guides, check out the LiveKit Agents documentation. You can use the examples above as a starting point to build your own voice agents with Murf TTS.

Configuration

The murf.TTS class provides extensive configuration options to customize the voice output according to your needs.

TTS Parameters Reference

ParameterTypeDefaultRange/OptionsDescription
voicestr"Matthew"Any valid Murf voice IDVoice identifier for TTS synthesis
stylestr"Conversation"Voice-specific stylesVoice style (e.g., “Conversation”, “Narration”)
rateint0-50 to 50Speech rate adjustment
pitchint0-50 to 50Pitch adjustment
modelstr"FALCON""FALCON", "GEN2"The model to use for audio output
sample_rateint240008000, 24000, 44100, 48000Audio sample rate in Hz
formatstr"PCM""MP3", "WAV", "FLAC", "ALAW", "ULAW", "PCM", "OGG"Audio output format
languagestrNoneLanguage codes (e.g., "en-US")Language for Gen2 model audio

Example with Custom Configuration

You can customize various aspects of the voice output to match your application’s requirements:

1from livekit.plugins import murf
2
3tts = murf.TTS(
4 voice="Matthew",
5 style="Conversation",
6 rate=10,
7 pitch=-5,
8 model="FALCON",
9 sample_rate=24000,
10 format="PCM",
11 language="en-US",
12)

Available Voices

Environment Variables

To keep your API keys secure, it’s recommended to use environment variables. Create a .env file in your project root:

1LIVEKIT_URL=wss://your-livekit-server.livekit.cloud # Your LiveKit server URL
2LIVEKIT_API_KEY=your_livekit_api_key_here # Your LiveKit API key
3LIVEKIT_API_SECRET=your_livekit_api_secret_here # Your LiveKit API secret
4MURF_API_KEY=your_murf_api_key_here
5DEEPGRAM_API_KEY=your_deepgram_api_key_here # Required for STT
6OPENAI_API_KEY=your_openai_api_key_here # Required for LLM

Then load these variables in your Python code using python-dotenv:

1from dotenv import load_dotenv
2load_dotenv()

Requirements

The Murf TTS integration for LiveKit Agents has the following requirements:

  • Python >= 3.9
  • livekit-agents >= 1.2.18

Make sure you have these dependencies installed before using the integration.

Support

If you encounter any issues or have questions about the integration:

Contributing

Contributions to the integration are welcome! If you’d like to contribute, please feel free to submit a Pull Request on the GitHub repository.

License

This project is licensed under the MIT License. See the LICENSE file for details.