The problem
A text agent produces words, not an audio waveform. It cannot choose a speaker’s voice or render pronunciation and timing by returning more text. A spoken interface needs a speech engine after the agent has decided what to say.
How NativePort helps
NativePort connects the agent’s script to ElevenLabs and returns playable audio. Choose a voice, send the text, and use the result in your app or save it as a file. There is no separate speech-provider account to wire into this flow.
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 and set VOICE_ID.
import os
import requests
BASE = "https://api.nativeport.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['NATIVEPORT_API_KEY']}"}
response = requests.post(
BASE + "/elevenlabs/v1/text-to-speech/" + os.environ["VOICE_ID"],
headers=HEADERS,
json={"text": "Your order is ready for collection.",
"model_id": "eleven_multilingual_v2"},
timeout=120,
)
response.raise_for_status()
with open("reply.mp3", "wb") as audio:
audio.write(response.content)The response contains audio bytes, so save it as binary rather than trying to parse JSON. Play reply.mp3 in your app. For an interactive experience, the /elevenlabs/v1/text-to-speech/{voice_id}/stream route delivers audio as it is generated. See the ElevenLabs gateway reference.
Tool costs
| Tool used in the example | Price 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.