### Run the Example Bot Source: https://docs.lmnt.com/integrations/pipecat/quickstart Execute the main Python script to start the Pipecat conversational bot. Access the provided URL in your browser to interact with it. ```bash python 07k-interruptible-lmnt.py ``` -------------------------------- ### Start Agent Session with Daily via Python SDK Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Start an agent session using the Pipecat Cloud Python SDK. This example demonstrates creating a session, optionally creating a Daily room, and retrieving the Daily room URL. Replace API_KEY with your actual API key. ```python import asyncio from pipecatcloud.exception import AgentStartError from pipecatcloud.session import Session, SessionParams async def main(): try: # Create session object session = Session( agent_name="lmnt-agent", api_key=API_KEY, # Replace with your actual API key params=SessionParams( use_daily=True, # Optional: Creates a Daily room daily_room_properties={"start_video_off": False}, data={"key": "value"}, ), ) # Start the session response = await session.start() # Get Daily room URL daily_url = f"{response['dailyRoom']}?t={response['dailyToken']}" print(f"Join Daily room: {daily_url}") except AgentStartError as e: print(f"Error starting agent: {e}") except Exception as e: print(f"Unexpected error: {e}") # Run the async function if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Install Project Dependencies Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Install Python dependencies required by the starter project. This ensures all necessary libraries are available for running the agent locally. ```bash pip install -r requirements.txt ``` -------------------------------- ### Create Secrets from Example File Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Copy the example environment file and edit it with your actual API keys. This file will be used to create a secret set for your agent. ```bash # Copy the example file cp env.example .env # Edit the file with your API keys # LMNT_API_KEY=your_lmnt_key # OPENAI_API_KEY=your_openai_key ``` -------------------------------- ### Install LMNT SDK Source: https://docs.lmnt.com/migrations/playht Install the LMNT SDK using pip for Python or npm for Node.js. ```bash pip install -U lmnt ``` ```bash npm install lmnt-node ``` -------------------------------- ### Install LMNT Node.js SDK Source: https://docs.lmnt.com/getting-started/environment-setup Use npm to install the LMNT Node.js SDK. This command installs the package in your project. ```sh npm install lmnt-node ``` -------------------------------- ### Download Example Files (Linux/macOS) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Download the necessary Python example files for your Pipecat project using curl on Linux or macOS. ```bash curl -O https://raw.githubusercontent.com/pipecat-ai/pipecat/main/examples/foundational/07k-interruptible-lmnt.py curl -O https://raw.githubusercontent.com/pipecat-ai/pipecat/main/examples/foundational/run.py ``` -------------------------------- ### Download Example Files (Windows PowerShell) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Download the necessary Python example files for your Pipecat project using curl.exe in PowerShell on Windows. ```powershell curl.exe -O https://raw.githubusercontent.com/pipecat-ai/pipecat/main/examples/foundational/07k-interruptible-lmnt.py curl.exe -O https://raw.githubusercontent.com/pipecat-ai/pipecat/main/examples/foundational/run.py ``` -------------------------------- ### Install LMNT Node SDK with Yarn Source: https://docs.lmnt.com/sdk/node/overview Install the latest version of the lmnt-node package using yarn. ```bash yarn add lmnt-node ``` -------------------------------- ### Other AI Tools Prompts for LMNT API Source: https://docs.lmnt.com/getting-started/ai-tools These example prompts are for various AI tools. Start your prompts with 'Browse https://api.lmnt.com/spec' to ensure the tool references the LMNT API spec for creating mobile apps or Rust programs. ```text Browse https://api.lmnt.com/spec and create a mobile app for text-to-speech with voice selection Browse https://api.lmnt.com/spec and write a rust program to create a new voice ``` -------------------------------- ### Run the LiveKit Agent Source: https://docs.lmnt.com/integrations/livekit/quickstart Start your agent application in development mode using this command. The agent will connect to your LiveKit server. ```bash python agent.py dev ``` -------------------------------- ### Install Project Dependencies Source: https://docs.lmnt.com/integrations/livekit/quickstart Install the necessary Python packages for your LiveKit agent, including LMNT, Deepgram, OpenAI, and others. ```bash pip install livekit-agents[lmnt,deepgram,openai,silero,turn-detector] python-dotenv ``` -------------------------------- ### Start Agent Session with Daily via CLI Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Use this command to start a new active session with your agent using Daily as the WebRTC transport. A URL will be provided to interact with the agent in your browser. ```shell pcc agent start lmnt-agent --use-daily ``` -------------------------------- ### Install LMNT Python SDK Source: https://docs.lmnt.com/getting-started/environment-setup Use pip to install the LMNT Python SDK. Ensure you are using the latest version with the -U flag. ```sh pip install -U lmnt ``` -------------------------------- ### Install Dependencies Source: https://docs.lmnt.com/integrations/pipecat/quickstart Install all required Python packages for the Pipecat application, including LMNT and other integrations. ```bash pip install fastapi uvicorn python-dotenv pipecat-ai[webrtc,deepgram,lmnt] pipecat-ai-small-webrtc-prebuilt ``` -------------------------------- ### Configure Python Environment with uv Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Install uv, create a virtual environment, and activate it. uv is a fast, modern Python package installer and environment manager. ```bash pip install uv uv venv source .venv/bin/activate # On Unix/macOS .venv\Scripts\activate # On Windows ``` -------------------------------- ### Install LMNT Node SDK using yarn Source: https://docs.lmnt.com/sdk/node Install the latest version of the lmnt-node package using yarn. This is an alternative to npm for installing the SDK in your Node.js project. ```bash yarn add lmnt-node ``` -------------------------------- ### Install LMNT Node SDK using npm Source: https://docs.lmnt.com/sdk/node Install the latest version of the lmnt-node package using npm. This is the first step to using the SDK in your Node.js project. ```bash npm install lmnt-node ``` -------------------------------- ### Install Pipecat Cloud CLI Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Install the Pipecat Cloud CLI using pip. This command is used for managing your Pipecat Cloud agents and deployments. ```bash pip install pipecatcloud ``` -------------------------------- ### Scale Agent Deployment Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Scales the agent deployment to a minimum of one instance to avoid cold starts. Note that this may incur charges. ```shell pcc deploy lmnt-agent your-username/lmnt-agent:0.1 --min-agents 1 ``` -------------------------------- ### Install Pipecat with Optional Dependencies Source: https://docs.lmnt.com/integrations/pipecat/installation Install the pipecat-ai Python module, including optional dependencies for WebRTC, Deepgram, OpenAI, and LMNT. This command ensures you have the necessary libraries for common integrations. ```bash pip install "pipecat-ai[webrtc,deepgram,openai,lmnt]" ``` -------------------------------- ### Check Python Version Source: https://docs.lmnt.com/integrations/pipecat/installation Verify your Python installation meets the minimum requirement of Python 3.10 or higher. ```bash python --version ``` -------------------------------- ### Sample Voice Metadata Object (Single) Source: https://docs.lmnt.com/sdk/python/reference/speech Example structure of a single voice metadata object returned by voice_info(). ```javascript { "name": "Morgan", "id": "morgan", "state": "ready", "owner": "system", "starred": false, "gender": "F", "description": "UK. Young adult. Conversational" } ``` -------------------------------- ### Sample Created Voice Metadata Object Source: https://docs.lmnt.com/sdk/python/reference/speech Example structure of a voice metadata object returned after creating a new voice. ```javascript { "id": "123444566422", "name": "new-voice", "owner": "me", "state": "ready", "starred": false, "description": "Totam necessitatibus saepe repudiandae perferendis. Tempora iure provident. Consequatur debitis assumenda. Earum debitis cum.", "type": "instant", "gender": "male" } ``` -------------------------------- ### Sample Voice Metadata Object Source: https://docs.lmnt.com/sdk/python/reference/speech Example structure of a voice metadata object returned by list_voices() and voice_info(). ```javascript [ { "name": "Morgan", "id": "morgan", "state": "ready", "owner": "system", "starred": false, "gender": "F", "description": "UK. Young adult. Conversational" } ] ``` -------------------------------- ### Fetch timing information in a speech session Source: https://docs.lmnt.com/guides/timing-and-synchronization Use the `return_extras` option when creating a speech session to fetch timing information. Note that the option name differs from standard requests. This example demonstrates appending text and processing the returned durations. ```python import asyncio from lmnt import AsyncLmnt async def main(): client = AsyncLmnt() connection = await client.speech.sessions.create(voice='lily', return_extras=True) await connection.append_text('Hello world.') await connection.finish() async for message in connection: for chunk in message.durations: print(f'"' + chunk.text + '" starts at ' + str(chunk.start) + 's and lasts for ' + str(chunk.duration) + 's') asyncio.run(main()) ``` ```javascript const lmnt = require('lmnt-node'); const main = async () => { const params = { voice: 'lily', return_extras: true }; const speech = new lmnt(); const speechConnection = speech.sessions.create(params); speechConnection.appendText('Hello world.'); speechConnection.finish(); for await (const synthesis of speechConnection) { for (const chunk of synthesis.durations) { console.log(`"${chunk.text}" starts at ${chunk.start.toFixed(3)}s and lasts for ${chunk.duration.toFixed(3)}s`); } } }; main(); ``` -------------------------------- ### Update Voice in Python Source: https://docs.lmnt.com/api-reference/voice/update-voice Example of updating a voice using the LMNT Python client. Requires the 'lmnt' package and an API key. ```python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) voice = client.voices.update( id="123", ) print(voice.voice) ``` -------------------------------- ### Synthesize Speech with JavaScript Source: https://docs.lmnt.com/getting-started/text-to-speech-example This JavaScript example shows how to synthesize speech from text using the `leah` voice. It requires the `lmnt-node` library and an LMNT API key, which should be set as an environment variable `LMNT_API_KEY`. The audio is saved as an MP3 file. ```javascript const Lmnt = require('lmnt-node'); const fs = require('fs'); const main = async () => { const lmnt = new Lmnt({ apiKey: process.env['LMNT_API_KEY'] }); const response = await lmnt.speech.generate({ text: 'Hello world.', voice: 'leah', format: 'mp3' }); // We must collect the audio stream as a binary array buffer const audioBuffer = Buffer.from(await response.arrayBuffer()); fs.writeFileSync('hello.mp3', audioBuffer); }; main(); ``` -------------------------------- ### Example Extra Synthesis Data Source: https://docs.lmnt.com/api-reference/speech/streaming This JSON object represents the extra information sent before an audio chunk when `return_extras` is true. It includes token durations, buffer status, and potential warnings. ```JavaScript { "durations": [ { "text": "", "start": 0, "duration": 0.2 }, { "text": "Using", "start": 0.2, "duration": 0.4 }, { "text": " ", "start": 0.6, "duration": 0.025 }, { "text": "LMNT", "start": 0.625, "duration": 0.425 }, { "text": "", "start": 1.05, "duration": 0.025 } ... ], "buffer_empty": false, "warning": "string" } ``` -------------------------------- ### Generate Speech (Binary Stream) - Python Source: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes This Python snippet demonstrates generating speech from text and reading the audio content. Ensure you have the lmnt library installed and provide your API key. The response content is read as bytes. ```Python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) response = client.speech.generate( text="hello world.", voice="leah", ) print(response) content = response.read() print(content) ``` -------------------------------- ### Augment Code Prompts for LMNT API Source: https://docs.lmnt.com/getting-started/ai-tools Use these example prompts with Augment Code to leverage the LMNT API spec for various tasks like creating Rust apps, Python scripts for voice creation, or React components for speech synthesis. ```text Browse https://api.lmnt.com/spec and create a rust app that reads the latest headlines in a newscaster style from https://text.npr.org/ using the 'brandon' voice Browse https://api.lmnt.com/spec and write a Python script to create a new voice Browse https://api.lmnt.com/spec and generate a React component that uses LMNT's WebSocket API for live speech synthesis ``` -------------------------------- ### Start Agent Session via REST API Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Initiate an agent session programmatically using the Pipecat Cloud REST API. This is useful for integrating agent sessions into web interfaces or backend services. Ensure you replace YOUR_PUBLIC_API_KEY with your actual key. ```bash curl --location --request POST 'https://api.pipecat.daily.co/v1/public/lmnt-agent/start' \ --header 'Authorization: Bearer YOUR_PUBLIC_API_KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ "createDailyRoom": true, "body": {"custom": "data"} }' ``` -------------------------------- ### Set up Virtual Environment (Windows) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Create and activate a Python virtual environment for your project on Windows. Choose the appropriate command based on your shell. ```bash python -m venv env source env/Scripts/activate # If using Git Bash # OR .\env\Scripts\activate # If using Command Prompt # OR .\env\Scripts\Activate.ps1 # If using PowerShell ``` -------------------------------- ### Create Project Directory Source: https://docs.lmnt.com/integrations/livekit/quickstart Use this command to create and navigate into your new project directory. ```bash mkdir livekit-lmnt-agent && cd livekit-lmnt-agent ``` -------------------------------- ### Create Project Directory Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Create a new directory for your Pipecat Cloud starter project and navigate into it. ```bash mkdir pipecat-cloud-starter && cd pipecat-cloud-starter ``` -------------------------------- ### Set up Virtual Environment (macOS/Linux) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Create and activate a Python virtual environment for your project on macOS or Linux. ```bash python3 -m venv env source env/bin/activate ``` -------------------------------- ### Configure Environment Variables Source: https://docs.lmnt.com/integrations/livekit/quickstart Create a `.env` file to store your API keys and LiveKit server details. Replace placeholders with your actual credentials. ```env LMNT_API_KEY=your_lmnt_api_key LIVEKIT_URL=wss://your-livekit-server.com LIVEKIT_API_KEY=your_livekit_api_key LIVEKIT_API_SECRET=your_livekit_api_secret DEEPGRAM_API_KEY=your_deepgram_api_key OPENAI_API_KEY=your_openai_api_key ``` -------------------------------- ### Set up Agent Session Pipeline Source: https://docs.lmnt.com/integrations/livekit/quickstart Create an AgentSession pipeline integrating Deepgram for STT, OpenAI for LLM, LMNT for TTS, and Silero for VAD. Enable preemptive generation for faster responses. ```python session = AgentSession( stt=deepgram.STT(model="nova-2"), # Speech-to-text llm=openai.LLM(model="gpt-4o-mini"), # Language model tts=lmnt.TTS(...), # Text-to-speech with LMNT vad=silero.VAD.load(), # Voice activity detection turn_detection=MultilingualModel(), # Contextual turn detection preemptive_generation=True, # Preemptive generation for faster response times ) ``` -------------------------------- ### Configure Environment Variables (Manual Method) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Manually create a .env file in your project directory and add your LMNT, Deepgram, and OpenAI API keys. ```env LMNT_API_KEY=your_lmnt_api_key DEEPGRAM_API_KEY=your_deepgram_api_key OPENAI_API_KEY=your_openai_api_key ``` -------------------------------- ### Clone Starter Project Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Clone the official Pipecat Cloud starter project to begin building your voice AI agent. This repository contains essential files for agent development. ```bash git clone https://github.com/lmnt-com/pipecat-cloud-starter.git ``` -------------------------------- ### Deploy Agent using pcc-deploy.toml Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart If a `pcc-deploy.toml` file is present, you can deploy the agent with default configurations without additional arguments. ```shell pcc deploy ``` -------------------------------- ### GET /v1/ai/voice/{id} Source: https://docs.lmnt.com/api-reference/voice/voice-info Retrieves detailed information about a specific voice, identified by its unique ID. ```APIDOC ## GET /v1/ai/voice/{id} ### Description Returns details of a specific voice. ### Method GET ### Endpoint /v1/ai/voice/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The `id` of the voice, which can be retrieved by a call to `List voices`. ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **description** (string) - A text description of this voice. - **gender** (string) - A tag describing the gender of this voice, e.g. `male`, `female`, `nonbinary`. - **id** (string) - The unique identifier of this voice. - **name** (string) - The display name of this voice. - **owner** (string) - The owner of this voice. Enum: `system`, `me`, `other`. - **starred** (boolean) - Whether this voice has been starred by you or not. - **state** (string) - The state of this voice in the training pipeline (e.g., `ready`, `training`). - **type** (string) - The method by which this voice was created: `instant` or `professional`. - **preview_url** (string) - A URL that returns a preview speech sample of this voice. #### Response Example ```json { "description": "UK. Young adult. Conversational", "gender": "F", "id": "morgan", "name": "Morgan", "owner": "system", "starred": true, "type": "instant", "state": "ready", "preview_url": "https://api.lmnt.com/v1/ai/morgan/preview" } ``` #### Error Responses - **400 Bad Request**: Returned if the request is malformed. - **401 Unauthorized**: Returned if the API key is invalid or missing. ``` -------------------------------- ### Get Voice Deletion Status Source: https://docs.lmnt.com/sdk/python/reference/speech This JavaScript object indicates the success status of a voice deletion operation. ```javascript { "success": "true" } ``` -------------------------------- ### Configure Environment Variables (macOS/Linux) Source: https://docs.lmnt.com/integrations/pipecat/quickstart Create a .env file and set your LMNT, Deepgram, and OpenAI API keys on macOS or Linux. ```bash echo "LMNT_API_KEY=your_lmnt_api_key" > .env echo "DEEPGRAM_API_KEY=your_deepgram_api_key" > .env echo "OPENAI_API_KEY=your_openai_api_key" > .env ``` -------------------------------- ### Configure Python Environment with venv Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Create a virtual environment using Python's built-in venv module and activate it. ```bash python -m venv .venv source .venv/bin/activate # On Unix/macOS .venv\Scripts\activate # On Windows ``` -------------------------------- ### Get Voice Information Source: https://docs.lmnt.com/sdk/python/reference/speech Fetch detailed information about a specific voice using its voice_id. The voice_id can be obtained from the list_voices() method. ```python voice = await speech.voice_info('voice_id') ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://docs.lmnt.com/integrations/pipecat/installation Set up a dedicated virtual environment for your Pipecat project to manage dependencies effectively. Activate it using the appropriate command for your operating system. ```bash mkdir pipecat-project cd pipecat-project python3 -m venv env ``` ```bash source env/bin/activate ``` ```bash source env/Scripts/activate # If using Git Bash # OR .\env\Scripts\activate # If using Command Prompt # OR .\env\Scripts\Activate.ps1 # If using PowerShell ``` -------------------------------- ### Update Voice in JavaScript Source: https://docs.lmnt.com/api-reference/voice/update-voice Example of updating a voice using the LMNT Node.js client. Requires the 'lmnt-node' package and an API key. ```javascript import Lmnt from 'lmnt-node'; const client = new Lmnt({ apiKey: 'My API Key', }); const voice = await client.voices.update('123'); console.log(voice.voice) ``` -------------------------------- ### Retrieve Account Information (Python) Source: https://docs.lmnt.com/api-reference/account-info This Python snippet demonstrates how to retrieve your account information, including plan details and usage, using the lmnt library. Initialize the client with your API key before making the request. ```python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) account = client.accounts.retrieve() print(account.plan) ``` -------------------------------- ### Speech Class Initialization Source: https://docs.lmnt.com/sdk/python/reference/speech Instantiate a Speech object with your API key. It's recommended to use environment variables for your API key. ```APIDOC ## Speech Class Initialization ### Description Instantiate a `Speech` object with your API key. It's recommended to use environment variables for your API key. ### Request Example ```python from lmnt.api import Speech speech = Speech('LMNT_API_KEY') ``` ### Async Context Manager Example ```python async with Speech('LMNT_API_KEY') as speech: pass ``` ### Cleanup Ensure to call the `close()` method when done with the `Speech` instance, or use it as an async context manager. ```python await speech.close() ``` ``` -------------------------------- ### Prefetch Dialogue with LMNTSpeech in Unity Source: https://docs.lmnt.com/sdk/unity/api-reference Call this coroutine in the Start method to prefetch dialogue, reducing perceived network latency for subsequent calls to Talk. ```csharp public class MyScript : MonoBehaviour { private LMNTSpeech speech; void Start() { speech = GetComponent(); StartCoroutine(speech.Prefetch()); } } ``` -------------------------------- ### Synthesize Speech with Python Source: https://docs.lmnt.com/getting-started/text-to-speech-example Use this snippet to synthesize speech from text using the `leah` voice in Python. Ensure you have the `lmnt` library installed and an `AsyncLmnt` client initialized. ```python import asyncio from lmnt import AsyncLmnt async def main(): client = AsyncLmnt() response = await client.speech.generate( text='Hello world', voice='leah', ) with open('output.mp3', 'wb') as f: f.write(await response.read()) asyncio.run(main()) ``` -------------------------------- ### Trigger Dialogue from Script (Unity C#) Source: https://docs.lmnt.com/sdk/unity/getting-started Use this script to get the LMNTSpeech component and trigger dialogue from a GameObject. Ensure the script is attached to the same GameObject as the LMNTSpeech component. ```csharp public class MyScript : MonoBehaviour { private LMNTSpeech speech; void Start() { // ... your code here ... speech = GetComponent(); } void Update() { // ... your code here ... StartCoroutine(speech.Talk()); } } ``` -------------------------------- ### Create Voice with LMNT Node.js SDK Source: https://docs.lmnt.com/api-reference/voice/create-voice Use this snippet to create a new voice using the LMNT Node.js SDK. Ensure you have the 'lmnt-node' package installed and provide your API key. ```javascript import Lmnt from 'lmnt-node'; const client = new Lmnt({ apiKey: 'My API Key', }); const voice = await client.voices.create({ enhance: false, files: [fs.createReadStream('path/to/file')], name: 'new-voice', }); console.log(voice.id); ``` -------------------------------- ### Talk (Play Dialogue) Source: https://docs.lmnt.com/sdk/unity/api-reference The Talk coroutine begins playback of the configured dialogue. If Prefetch was not called, this will initiate a network request. ```APIDOC ## `IEnumerator Talk()` ### Description This coroutine begins playback of the configured dialogue. Note that if `Prefetch` was not called prior to calling `Talk`, this coroutine will start a network request to get the dialogue. ### Method IEnumerator ### Endpoint N/A (Local method) ``` -------------------------------- ### Create Streaming Synthesis Connection Source: https://docs.lmnt.com/sdk/python/reference/streaming Instantiate a StreamingSynthesisConnection using the synthesize_streaming method from the Speech class. Requires an API key. ```python speech = Speech('LMNT_API_API_KEY') connection = await speech.synthesize_streaming('mara-wilson') ``` -------------------------------- ### Create Secret Set Directly via CLI Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Alternatively, create a secret set by providing API keys directly on the command line. This method is useful for quick setup or scripting. ```shell pcc secrets set lmnt-agent-secrets \ LMNT_API_KEY=your_lmnt_key \ OPENAI_API_KEY=your_openai_key ``` -------------------------------- ### Create Voice Assistant Agent Source: https://docs.lmnt.com/integrations/livekit/quickstart Define a `VoiceAssistant` class inheriting from `livekit.agents.Agent` to customize the agent's instructions and personality. ```python from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent from livekit.plugins import ( openai, lmnt, deepgram, silero, ) from livekit.plugins.turn_detector.multilingual import MultilingualModel load_dotenv() class VoiceAssistant(Agent): def __init__(self) -> None: super().__init__( instructions=( "You are a helpful voice assistant. " "Keep your responses concise and conversational. " "Avoid using punctuation that doesn't translate well to speech." ) ) async def entrypoint(ctx: agents.JobContext): session = AgentSession( stt=deepgram.STT(model="nova-2", language="en-US"), llm=openai.LLM(model="gpt-4o-mini"), tts=lmnt.TTS( voice="leah", # Voice ID from LMNT library ), vad=silero.VAD.load(), # Voice activity detection turn_detection=MultilingualModel(), # Contextual turn detection preemptive_generation=True, # Preemptive generation for faster response times ) await session.start( room=ctx.room, agent=VoiceAssistant(), ) await session.generate_reply( instructions="Greet the user and ask how you can help them today." ) if __name__ == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint)) ``` -------------------------------- ### Claude Code Prompts for LMNT API Source: https://docs.lmnt.com/getting-started/ai-tools Example prompts for Claude Code to generate serverless functions for speech synthesis, web applications with real-time capabilities, or Python CLI tools for managing LMNT voices. ```text Generate a serverless function that uses LMNT's API for speech synthesis with proper authentication Build a web application that integrates LMNT's real-time speech capabilities Create a Python CLI tool that manages LMNT voices and synthesizes speech from text files ``` -------------------------------- ### Generate Speech with Durations (Python) Source: https://docs.lmnt.com/api-reference/speech/synthesize-speech-post This Python snippet generates speech from text, returning a base64-encoded audio string and optional word-level durations. Install the 'lmnt' library and substitute 'My API Key' with your valid API key. ```python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) response = client.speech.generate_detailed( text="hello world.", voice="leah", ) print(response.audio) ``` -------------------------------- ### Generate Speech with Durations (JavaScript) Source: https://docs.lmnt.com/api-reference/speech/synthesize-speech-post Use this snippet to generate speech from text and receive a base64-encoded audio string along with word-level durations. Ensure you have the 'lmnt-node' package installed and replace 'My API Key' with your actual API key. ```javascript import Lmnt from 'lmnt-node'; const client = new Lmnt({ apiKey: 'My API Key', }); const response = await client.speech.generateDetailed({ text: 'hello world.', voice: 'leah' }); console.log(response.audio); ``` -------------------------------- ### Configure Local Environment Variables Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Set necessary API keys as environment variables for local testing of your agent. Ensure you replace placeholder values with your actual keys. ```bash # Set environment variables with your API keys export LMNT_API_KEY="your_lmnt_key" export DAILY_API_KEY="your_daily_key" export OPENAI_API_KEY="your_openai_key" ``` -------------------------------- ### Create Project Directory Source: https://docs.lmnt.com/integrations/pipecat/quickstart Use this command to create a new directory for your Pipecat project and navigate into it. ```bash mkdir pipecat-quickstart && cd pipecat-quickstart ``` -------------------------------- ### Generate Speech Stream Source: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes Generates speech from text and streams the audio as binary data chunks in real-time as they are generated. This is the recommended endpoint for most text-to-speech use cases. You can either stream the chunks for low-latency playback or collect all chunks to get the complete audio file. ```APIDOC ## POST /api/speech/stream ### Description Generates speech from text and streams the audio as binary data chunks in real-time. ### Method POST ### Endpoint /api/speech/stream ### Request Body - **text** (string) - Required - The text to convert to speech. - **voice** (string) - Optional - The voice to use for speech generation. Defaults to a standard voice. ### Request Example ```json { "text": "Hello, this is a test.", "voice": "en-US-Wavenet-A" } ``` ### Response #### Success Response (200) - **audio_chunk** (binary) - A chunk of audio data. #### Response Example (Binary audio data stream) ``` -------------------------------- ### List Available Voices (Python) Source: https://docs.lmnt.com/api-reference/voice/list-voices This Python snippet demonstrates how to fetch a list of available voices using the lmnt library. Initialize the Lmnt client with your API key before making the request. ```python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) voices = client.voices.list() print(voices) ``` -------------------------------- ### Stream Text and Receive Speech with LMNT API Source: https://docs.lmnt.com/getting-started/streaming-example Use this snippet to stream text to the LMNT API and receive synthesized speech in real-time. It requires setup with LMNT and OpenAI API keys. The code concurrently reads from ChatGPT and writes to a file, and streams audio data from LMNT. ```python import asyncio from lmnt import AsyncLmnt from openai import AsyncOpenAI DEFAULT_PROMPT = 'Read me an excerpt of a short sci-fi story in the public domain.' VOICE_ID = 'elowen' async def main(): client = AsyncLmnt() connection = await client.speech.sessions.create(voice=VOICE_ID) t1 = asyncio.create_task(reader_task(connection)) t2 = asyncio.create_task(writer_task(connection)) await asyncio.gather(t1, t2) async def reader_task(connection): """Streams audio data from LMNT and writes it to `output.mp3`.""" with open('output.mp3', 'wb') as f: async for message in connection: f.write(message.audio) async def writer_task(connection): """Streams text from ChatGPT to LMNT.""" client = AsyncOpenAI() response = await client.chat.completions.create( model='gpt-4o-mini', messages=[{'role': 'user', 'content': DEFAULT_PROMPT}], stream=True) async for chunk in response: if (not chunk.choices[0] or not chunk.choices[0].delta or not chunk.choices[0].delta.content): continue content = chunk.choices[0].delta.content await connection.append_text(content) print(content, end='', flush=True) # After `finish` is called, the server will close the connection # when it has finished synthesizing. await connection.finish() asyncio.run(main()) ``` ```javascript const Lmnt = require('lmnt-node'); const OpenAI = require('openai').OpenAI; const { createWriteStream } = require('fs'); const DEFAULT_PROMPT = 'Read me an excerpt of a short sci-fi story in the public domain.'; const VOICE_ID = 'elowen'; const main = async () => { const lmnt = new Lmnt({ apiKey: process.env['LMNT_API_KEY'] }); const speechConnection = await lmnt.speech.sessions.create({ voice: VOICE_ID }); const openai = new OpenAI(); const chatConnection = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: [{ role: 'user', content: DEFAULT_PROMPT }], stream: true, }); const writerTask = async () => { // Streams text from ChatGPT to LMNT. for await (const part of chatConnection) { const message = part.choices[0]?.delta?.content || ''; speechConnection.appendText(message); process.stdout.write(message); } // After `finish` is called, the server will close the connection // when it has finished synthesizing. speechConnection.finish(); }; const readerTask = async () => { // Streams audio data from LMNT and writes it to `output.mp3`. const audioFile = createWriteStream('output.mp3'); for await (const message of speechConnection) { audioFile.write(message.audio); } }; await Promise.all([writerTask(), readerTask()]); speechConnection.close(); } main(); ``` -------------------------------- ### Create Voice with LMNT Python SDK Source: https://docs.lmnt.com/api-reference/voice/create-voice This Python snippet demonstrates how to create a voice using the LMNT Python SDK. Replace 'My API Key' with your actual API key and provide the raw file contents for training. ```python from lmnt import Lmnt client = Lmnt( api_key="My API Key", ) voice = client.voices.create( enhance=False, files=[b"raw file contents"], name="new-voice", ) print(voice.id) ``` -------------------------------- ### POST /v1/ai/speech/stream Source: https://docs.lmnt.com/api-reference/speech/streaming Initiates a speech stream session by sending configuration details to the server. ```APIDOC ## POST /v1/ai/speech/stream ### Description Initiates a speech stream session by sending configuration details to the server. This is the first message sent to establish the session. ### Method POST ### Endpoint /v1/ai/speech/stream ### Parameters #### Request Body - **X-API-Key** (string) - Required - Your API key obtained from your account page. - **voice** (string) - Required - The voice ID to use for synthesis, obtained from the 'List voices' API. - **format** (string) - Optional - The desired output format of the audio. Supported formats: `mp3`, `pcm_s16le`, `pcm_f32le`, `ulaw`, `webm`. Defaults to `mp3`. - **language** (string) - Optional - The desired language using a two-letter ISO 639-1 code. Defaults to auto language detection. Supported languages: `auto`, `ar`, `de`, `en`, `es`, `fr`, `hi`, `id`, `it`, `ja`, `ko`, `nl`, `pl`, `pt`, `ru`, `sv`, `th`, `tr`, `uk`, `ur`, `vi`, `zh`. - **sample_rate** (integer) - Optional - The desired output audio sample rate. Supported rates: `24000`, `16000`, `8000`. - **return_extras** (boolean) - Optional - Controls whether the server will return extra information about the synthesis. ### Request Example ```json { "X-API-Key": "YOUR_API_KEY", "voice": "en-US-Standard-C", "format": "mp3", "language": "en", "sample_rate": 24000, "return_extras": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation of session initiation. #### Response Example ```json { "message": "Session established successfully." } ``` ``` -------------------------------- ### Create Secret Set from File Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Create a secret set named 'lmnt-agent-secrets' using the API keys defined in your local '.env' file. This securely manages sensitive credentials for your agent. ```bash pcc secrets set lmnt-agent-secrets --file .env ``` -------------------------------- ### List Agent Deployment History Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Displays a history of deployments for a specific agent. ```shell pcc agent deployments lmnt-agent ``` -------------------------------- ### Receiving Extras Source: https://docs.lmnt.com/api-reference/speech/streaming When `return_extras` is set to `true`, the server sends a JSON string before each audio chunk containing extra synthesis details. ```APIDOC ## Receiving extras If you set the `return_extras` field to `true` in the first message, the server will also send extra information about each synthesized chunk. This information is sent as a serialized JSON object (string) and will be sent **before** its corresponding audio chunk. The extra information includes: ### Response Fields - **durations** (array of duration objects) - Required - An array of objects that detail the duration of each text token in the synthesized chunk. The format of each object is: - **text** (string) - The text itself. - **start** (number) - The time at which the text starts, in seconds. - **duration** (number) - The overall duration of the text, in seconds. *Note: The durations array resets its start time for each chunk of audio.* - **buffer_empty** (boolean) - Required - Indicates whether the server has finished synthesizing all the text that it has received. - **warning** (string) - Optional - Contains any warnings that the server has encountered during synthesis, such as exceeding the number of free characters. ### Request Example ```json { "durations": [ { "text": "", "start": 0, "duration": 0.2 }, { "text": "Using", "start": 0.2, "duration": 0.4 }, { "text": " ", "start": 0.6, "duration": 0.025 }, { "text": "LMNT", "start": 0.625, "duration": 0.425 }, { "text": "", "start": 1.05, "duration": 0.025 } ], "buffer_empty": false, "warning": "string" } ``` *Note: The extra data JSON is always sent **before** the audio chunk that it corresponds to. Take care to interpret incoming data correctly. Audio is sent as `bytes` and extra data is sent as a `string`.* ``` -------------------------------- ### Create Public Access Key Source: https://docs.lmnt.com/integrations/pipecat/cloud-quickstart Creates a public access key for your namespace or organization, which can be used to authenticate requests to your agent. You will be prompted to set it as your default. ```shell pcc organizations keys create ```