NativePort
← All use cases

Add spoken replies to Telegram and Discord bots

Turn a bot’s written reply into an audio message its users can listen to.

The problem

A chat bot that generates text does not automatically have a voice. Telegram and Discord deliver messages, but the bot still needs a service that creates speech and application code that attaches the audio to a reply.

How NativePort helps

NativePort provides the speech-generation step through ElevenLabs. Your bot sends its reply text and gets an audio file back. The same file can be attached in Telegram or Discord. Your application continues to handle incoming messages, platform credentials, and delivery.

Technical implementation

Use Python 3 with requests installed (python -m pip install requests). Set NATIVEPORT_API_KEY in your environment to your NativePort key. Run the snippets on your server, where your key stays private.

Choose a voice with GET /elevenlabs/v1/voices, then set VOICE_ID. This function produces the audio bytes to attach in your existing bot handler.

python
import os
import requests

BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}

def spoken_reply(text):
    response = requests.post(
        BASE + "/elevenlabs/v1/text-to-speech/" + os.environ["VOICE_ID"],
        headers=HEADERS,
        json={"text": text, "model_id": "eleven_multilingual_v2"},
        timeout=120,
    )
    response.raise_for_status()
    return response.content

audio_bytes = spoken_reply("Your booking is confirmed for tomorrow at ten.")
with open("reply.mp3", "wb") as audio:
    audio.write(audio_bytes)

In Telegram, attach reply.mp3 using your bot’s sendAudio method. In Discord, attach it to a channel reply through your bot framework. This example creates a spoken message; joining a live voice channel needs a separate playback integration. Keep the speech call off your bot’s event loop if the framework is asynchronous. For incoming voice messages, use the speech-to-text workflow.

Tool costs

Tool used in the examplePrice per call
ElevenLabs — text to speech $0.026375 / call

Prices in USD. Usage-based tools have no fixed per-call price. View pricing.

Let your agent build it

You don’t need to write this code yourself. Copy this page’s link and paste it into your agent. Ask it to follow the guide and implement the feature for you.