How to Integrate Our Text-to-Speech API into Chatbots?

By BotVoice editorial team · Updated 2026-11-18

BotVoice API helps product teams generate high-quality speech audio from text programmatically. We provide a reliable, cost-effective TTS endpoint designed specifically for automated voice workflows and conversational AI. If you are building a chatbot that needs to speak back to users, this guide shows you exactly how to connect our TTS-1 engine to your existing infrastructure without adding complexity.

You will learn how to handle character limits, manage audio delivery, and optimize for latency in real-world bot scenarios. We cover practical steps like caching responses for FAQs, splitting long texts, and handling rate limits with USDT top-ups. Whether you are using the OpenAI SDK or plain HTTP, this page gives you the concrete code examples and best practices needed to ship voice features confidently.

...

How to Integrate Our Text-to-Speech API into Chatbots?

Frequently asked questions

Can I use TTS for real-time chat?

No streaming or WebSocket support exists. You send a POST request and wait for the full audio file. Typical speed is roughly real-time, generating about 25 characters per second. Short phrases may take a few seconds. Requests are processed sequentially, so latency depends on queue load during peak times.

How do I handle long bot responses?

Split text into parts of up to 4096 characters per request. Generate audio for each part, then join the files. This ensures you stay within the character limit while maintaining continuous playback for your users.

Which voice is best for assistants?

Q: Which voice is suitable for assistants? A: Sage offers a calm, instructional tone, while Milo provides a friendly, conversational style. Both are well-suited for automated voice workflows. Choose based on whether you prefer a neutral instructional approach or a warmer conversational experience.

Do I need a backend server?

A backend is recommended to securely store your Bearer key and manage rate limits. While you can call the API directly, handling the 60 requests per minute limit and splitting long texts is easier server-side.

How do I play audio in a browser bot?

Receive the audio file via the POST response. Support formats include mp3, wav, opus, flac, and pcm. Use standard HTML5 audio players to play the returned file directly in the user's browser.

Can I change voices dynamically?

Yes, include the voice parameter in each request. You can switch between any of the eight presets dynamically per request, allowing you to vary tone or character without changing your integration logic.

Is the API suitable for IVR?

Yes, the API provides reliable audio generation for automated workflows. With support for multiple languages and formats, it fits well into IVR systems. Ensure you handle the sequential processing queue to maintain call flow timing.

How do I cache audio files?

Store generated audio files locally or in object storage. Since input text determines the output, you can cache results for identical inputs. This reduces API calls and costs, especially for frequent, static bot responses.

What is the latency like?

Typical speed is roughly real-time, generating about 25 characters per second. Short phrases take a few seconds. Requests are processed one after another, so under load, a request may wait in a queue, increasing latency.

Do I need to download the full audio?

The API returns the audio file in the response. You can save it or play it directly. Supported formats include mp3, wav, opus, flac, and pcm, allowing flexible handling based on your needs.

Can I use this with WhatsApp bots?

Yes, generate audio files via the API and send them as voice notes. Use supported formats like mp3 or opus. Ensure your bot handles the file transmission correctly within WhatsApp's voice message constraints.

How do I handle accents?

Set the language parameter to an ISO code. If omitted, Latin text defaults to English. For non-English Latin text, explicitly setting the language ensures correct pronunciation. Voices can speak any of the 23 supported languages.

Is SSML supported for bots?

No, SSML is not supported. You cannot use phoneme dictionaries or custom pronunciation lexicons. Adjust pacing and tone by changing the speed parameter (0.25–4.0) or switching between different voice presets.

Do I need to pay for each user?

No, you pay per character generated, not per user. The rate is $10 per 1 million characters. Failed requests are free. There are no monthly plans, seats, or minimum spend requirements.

Why add voice to your chatbot?

Sound wave illustration for: Why add voice to your chatbot?

Adding voice transforms static text interactions into dynamic conversations. Synthetic speech captures attention more effectively than plain text, keeping users engaged longer in your bot’s workflow.

Voice also enables hands-free usage, allowing users to interact while driving or cooking. It creates a more natural, conversational tone that feels less robotic than traditional message bubbles.

Enhance user engagement

Voice adds a natural tone to automated responses. Users respond better to a warm, clear narrator like Aria or an energetic voice like Felix, making the bot feel more present and attentive during conversations.

  • Higher retention rates through auditory engagement
  • Natural conversational flow with preset voices

Support hands-free interaction

Users can consume bot responses without looking at their screen. This is critical for mobile workflows, driving scenarios, or multi-tasking environments where visual attention is limited.

Audio output allows users to listen while performing other tasks, reducing the friction of switching apps or focusing solely on reading text.

  • Hands-free consumption in mobile or driving contexts
  • Reduced visual dependency for quick info retrieval

Improve accessibility for users

Voice support aids users with visual impairments or reading difficulties. Providing audio options ensures your bot is inclusive and usable by a wider audience, complying with modern accessibility standards.

Text-to-speech removes barriers for users who prefer listening over reading, especially for longer bot responses or complex instructions.

  • Support for visually impaired users
  • Inclusive design for diverse reading preferences

Choosing the right voice

Sound wave illustration for: Choosing the right voice

Selecting the correct voice preset ensures your bot sounds consistent with your brand’s personality. Each of the eight available voices offers a distinct tone, allowing you to tailor the audio experience to specific conversational contexts without needing complex configuration.

Select a tone matching your brand

Choose a voice that aligns with your product’s identity. Whether you need a calm narrator for instructions or an energetic voice for promotions, the presets cover common conversational needs out of the box.

  • Match voice personality to brand values
  • Test multiple voices with sample text
  • Ensure consistency across all bot interactions

Use Aria for calm narration

Aria provides a warm, clear narration style ideal for instructional content or storytelling. Her voice is well-suited for guiding users through complex workflows or explaining features in a relaxed manner.

  • Warm and clear tone
  • Ideal for instructional content
  • Supports natural pacing

Use Felix for energetic promos

Felix delivers an energetic, promo-style voice that captures attention quickly. Use him for announcements, short calls to action, or upbeat updates where high energy is required to engage users.

  • High-energy delivery
  • Best for promotional content
  • Clear and engaging

Technical integration steps

Sound wave illustration for: Technical integration steps

BotVoice API helps product teams generate high-quality speech audio from text programmatically. We provide a reliable, cost-effective TTS endpoint designed specifically for automated voice workflows and conversational AI.

Obtain API key from dashboard

Sign in at /get-api-key/ via Google or email to retrieve your single active API key. This key authenticates all requests, so store it securely in your environment variables. You can issue a new key at any time, which instantly invalidates the old one.

Set base_url in your SDK

Configure your OpenAI SDK or HTTP client to point to https://api.playuubd.com/v1. This endpoint shape matches the standard speech interface, allowing you to use familiar libraries without rewriting your integration logic. Ensure your library sends the Authorization: Bearer header with your key.

Send POST request with text

Post a JSON body to /v1/audio/speech containing the model, input text, voice, and response_format. The API returns the audio file directly in the response body. For chatbots, use formats like opus or mp3 to minimize bandwidth while maintaining quality for playback.

  • Model: "tts-1" or "tts-1-hd"
  • Input: text up to 4096 characters
  • Voice: e.g., "aria", "felix"
  • Format: mp3, wav, opus, flac, pcm

Handling asynchronous responses

Sound wave illustration for: Handling asynchronous responses

When the API returns a response, you receive a binary audio file that your bot must download and store temporarily before playback. Since synthesis is not instant, ensure your code waits for the full file to arrive before attempting to play it, avoiding truncated audio streams.

Wait for audio file download

Treat the response as a complete file, not a stream. Wait for the download to finish before passing the audio data to your player. This prevents choppy playback and ensures the bot’s voice sounds natural.

Use OPUS for efficient playback

OPUS offers a good balance of quality and file size for web and mobile bots. Request response_format: opus to reduce bandwidth usage and speed up playback initialization, especially on slower mobile networks.

  • Set response_format to opus in your JSON body.
  • OPUS files are significantly smaller than WAV or FLAC.

Cache responses for common phrases

Store generated audio for frequent bot responses (e.g., "Welcome," "How can I help?") in your database or CDN. Reuse the same audio file for identical inputs to save characters and reduce latency for users.

  • Cache audio by hashing the input text.
  • Invalidate cache when voice or speed settings change.

Managing character limits

Sound wave illustration for: Managing character limits

Text-to-speech requests have a strict 4,096-character limit per call. If your bot generates a long response, you must split the text into chunks, send each chunk to the API, and join the resulting audio files. This ensures you stay within the per-request constraint while concatenating the audio files for playback.

You can also adjust the speed parameter between 0.25 and 4.0 to reduce generation time and effective length. Faster speeds process text quicker, which helps with latency, but ensure the voice remains clear for your users.

Split long bot responses

Break your input text into segments of up to 4,096 characters. Send each segment as a separate POST request to the speech endpoint. Once all audio files are generated, concatenate them in order to play a single, continuous response for the user.

This approach keeps each request within the defined limit and prevents truncation. It is the standard way to handle lengthy conversational turns or detailed explanations in your chatbot.

  • Max 4,096 characters per input field.
  • Concatenate resulting audio files sequentially.
  • Maintains context across multiple API calls.

Use speed control for brevity

Adjust the speed parameter to control how fast the voice speaks. Increasing the speed reduces the total duration of the audio file, which can help with bandwidth and playback time. Use this for quick confirmations or short updates.

Be cautious with high speeds (above 2.0) as they may reduce clarity. Test different speeds to find the balance between efficiency and comprehensibility for your specific use case.

  • Range: 0.25 to 4.0.
  • Higher speed reduces audio duration.
  • Test for clarity at higher speeds.

Optimize text for voice output

Simplify your bot's written responses before sending them to the API. Remove unnecessary punctuation or complex structures to improve the natural flow of the spoken response. This reduces the character count and improves the natural flow of the spoken response.

Consider rewriting long sentences into shorter, clearer phrases. This not only helps with character limits but also enhances the listening experience for users interacting with your voice bot.

  • Simplify punctuation for better flow.
  • Shorten sentences for clarity.
  • Reduce character count naturally.

Error handling in bots

Sound wave illustration for: Error handling in bots

When your chatbot hits the rate limit, it receives a 429 response. Since requests are processed sequentially, under load your request may wait in a queue. Implementing an exponential backoff strategy prevents your bot from spamming the API during these pauses.

For synthesis failures, the API returns a clear error without charging you. Ensure your bot treats these as retryable or fallback events, preserving the user experience while the engine resolves the issue.

Retry on 429 rate limits ['Your key allows 60 requests per minute (10 before top-up). If you exceed this, wait and retry with exponential backoff to respect the queue.', 'Bots should avoid immediate loops; the queue processes requests one after another, so waiting yields the best results.'] ['Implement exponential backoff for 429 responses', 'Respect the 60 requests/minute limit per key', 'Avoid immediate retry loops to prevent queue congestion']

Handle failed synthesis gracefully ['If synthesis fails, the charge is returned in full. Your bot should treat the empty response as a signal to retry or switch to a static fallback message.', 'This ensures you never pay for broken audio while maintaining a smooth conversational flow for the end user.'] ['Check for HTTP errors before playing audio', 'Retry once on transient failures', 'Use a text fallback if audio generation consistently fails']

Log metadata for billing ['Request metadata, including time, characters, and status, is kept for billing purposes. Log these details to verify that failed requests were correctly refunded.', 'This audit trail helps you track usage costs and identify patterns in synthesis failures without needing external tools.', '']

Testing your integration

Sound wave illustration for: Testing your integration

Testing your integration ensures your bot delivers clear audio without unexpected costs or delays. Start by leveraging the free trial credit available after signing in with Google, which provides about 50,000 characters valid for seven days. This allows you to validate your workflow without financial risk.

Use the provided curl examples to verify connectivity before building your application logic. This step confirms that your API key is active and that the endpoint responds correctly with audio data, allowing you to catch configuration errors early in the development cycle.

Use free trial credit

Sign up with Google to receive $0.50 in trial credit, sufficient for approximately 50,000 characters. This credit is valid for seven days, giving you ample time to test various voices and languages. Accounts created with email and password do not receive this trial credit, so choose your sign-up method accordingly.

  • Available only for Google sign-ins
  • Valid for 7 days
  • Approximately 50,000 characters

Test with curl first

Run the provided curl command to send a simple text request. Check the response headers and the audio file content to ensure the synthesis succeeded. This method helps you isolate issues between your code and the API before integrating into your main application.

Verify that the audio file is playable and matches the expected format. If the request fails, check the error message for details on rate limits or invalid parameters.

  • Use the curl example from the dashboard
  • Check response status codes
  • Verify audio file format

Verify audio quality in app

Play the generated audio within your chatbot interface to assess clarity and tone. Ensure that the voice matches your brand’s personality, such as using Aria for calm narration or Felix for energetic promos. Test with different languages and speeds to confirm natural-sounding output.

Pay attention to how the audio integrates with your bot’s user interface. Ensure that playback starts promptly and that the audio quality is consistent across different devices and network conditions.

  • Test various voices and languages
  • Check playback latency
  • Ensure consistent audio quality

Optimizing for latency

Sound wave illustration for: Optimizing for latency

Latency matters in conversational AI where users expect immediate responses. Pre-generating audio for frequent questions removes synthesis time from the critical path, ensuring instant playback. This approach keeps interactions smooth and natural.

For dynamic content, choosing the right model and minimizing network overhead ensures your bot feels responsive. Small optimizations compound to create a better user experience.

Pre-generate audio for FAQs

Identify the most common user queries in your bot's flow. Generate and cache the audio files for these standard responses. Serve the cached file instantly when the user asks the same question, bypassing the API entirely.

This eliminates the few seconds required for synthesis, making the interaction feel instantaneous. It also reduces API usage and costs for repetitive queries.

  • Cache responses for common phrases
  • Serve static audio files directly
  • Reduce API calls for standard answers

Use faster models when possible

Use the 'tts-1' model for standard interactions. It processes requests efficiently, keeping latency low for most use cases.

Reserve 'tts-1-hd' for moments where voice quality significantly impacts user satisfaction, such as brand intros or important announcements. This balance optimizes both speed and quality.

  • Use 'tts-1' for general flow
  • Reserve 'tts-1-hd' for key moments
  • Balance quality with speed

Minimize network round trips

Send the entire text payload in a single request rather than splitting it unnecessarily. Smaller payloads process faster, especially for short bot responses.

Ensure your client library uses efficient HTTP connections. Avoid unnecessary retries for successful requests to keep the conversation flowing without delay.

  • Send single requests when possible
  • Use efficient HTTP connections
  • Avoid unnecessary retries

Scaling your bot

Sound wave illustration for: Scaling your bot

Scaling your bot requires balancing throughput with cost efficiency. Since requests are processed sequentially, high volume can lead to queue delays. Monitor your usage metrics to identify bottlenecks and adjust your generation strategy accordingly.

Our pricing model supports growth without fixed monthly plans. You pay only for what you generate, ensuring costs align directly with your bot’s activity levels.

Monitor API usage

Track your character consumption and request rates via the dashboard. This visibility helps you anticipate when you might hit rate limits or run low on balance, allowing proactive adjustments to your bot’s behavior.

Understanding your usage patterns enables you to optimize text length and voice selection for better performance.

  • Access real-time usage stats in the dashboard
  • Track character consumption per voice
  • Identify peak usage times

Top up USDT balance

Add funds seamlessly using USDT on the TRON network (TRC-20). Transfers are credited automatically within minutes, ensuring your bot never stops due to insufficient balance.

There are no subscriptions or minimum spend requirements, so you can top up exactly when needed.

Starting with a minimum of $5 makes it easy to scale gradually as your bot gains users.

  • Minimum top-up: $5
  • Credit time: within minutes
  • No monthly subscriptions

Add more API keys if needed

While each key has a rate limit of 60 requests per minute, you can issue a new key at any time to reset your quota. The old key stops immediately, allowing you to manage concurrency.

This flexibility lets you distribute load across multiple keys if your bot experiences sudden spikes in traffic.

Keep in mind that each key is independent, so monitor usage per key to optimize your scaling strategy.

  • Issue new keys anytime
  • Old key stops immediately
  • Manage concurrency with multiple keys

Security best practices

Sound wave illustration for: Security best practices

Protecting your API key is essential for controlling usage and costs in your chatbot infrastructure. Since BotVoice API issues one active key per account, keeping it secure ensures that only your services can generate speech audio.

Store API key in environment

Never hardcode your key in your application code or commit it to version control. Instead, inject it via environment variables or a secrets manager. This prevents accidental exposure if your codebase becomes public.

  • Use environment variables in your deployment environment.
  • Refer to the key as a variable, e.g., BOTVOICE_API_KEY.

Use HTTPS for all requests

Always send your POST requests to https://api.playuubd.com/v1. The Authorization: Bearer header contains your secret key, so transmitting it over unencrypted HTTP exposes it to interception. Ensure your chatbot backend uses TLS 1.2 or higher.

Rotate keys periodically

Since each account holds only one active key, issuing a new key immediately invalidates the old one. Use this feature to rotate credentials if you suspect a leak. Generate a new key in the dashboard, update your environment variable, and verify the chatbot still functions before revoking the old key.

Common pitfalls

Sound wave illustration for: Common pitfalls

Chatbots often fail to sound natural because the TTS engine guesses the language incorrectly. If your bot sends Latin-script text in a non-English language without specifying the language parameter, it defaults to English. This results in awkward accents or mispronunciations that break immersion for your users.

Another common issue is ignoring rate limits. The API allows 60 requests per minute. If your bot sends multiple rapid requests, it may hit a 429 error. Always implement exponential backoff to handle these limits gracefully without dropping audio responses.

Forgetting to set language code

Always explicitly pass the language ISO code for non-English Latin text. This ensures the voice synthesizer applies the correct phonemes and intonation patterns, preventing the default English pronunciation from ruining the user experience.

  • Set language: 'fr' for French text.
  • Use language: 'de' for German text.
  • Do not rely on script detection for mixed-language inputs.

Ignoring rate limits

The API enforces a limit of 60 requests per minute per key. Exceeding this results in 429 errors. Implement retry logic with exponential backoff in your bot’s workflow to manage bursts of user interactions smoothly.

  • Monitor your request rate.
  • Implement exponential backoff.
  • Distribute load across keys if needed.

Not handling partial audio

The API returns the complete audio file after synthesis; it does not stream partial chunks. Ensure your bot waits for the full response before playing the audio. Do not attempt to play partial data, as the endpoint does not support streaming.

Support and resources

Sound wave illustration for: Support and resources

We prioritize clear, direct communication for product teams. Since we do not offer phone support or live chat, our email channel is the primary way to resolve account or billing questions.

Contact support by email

Send your queries to our support address. We handle all issues via email to ensure detailed, documented responses without the noise of live queues.

Check documentation for examples

Our docs at /docs/ provide ready-to-use curl examples and SDK configurations. Review these first for quick integration steps and parameter details.

  • JSON body structure
  • Error code explanations
  • Voice selection guide

Use community forums if available

While we do not host our own forums, you can share integration tips and voice selection advice with other developers in broader AI communities.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Design conversational flows that feel like a helpful colleague, not a robotic script, for our next voice interface update.

Avatar of the voice aria
ariafemale
Avatar of the voice nova
novafemale
Avatar of the voice luna
lunafemale
Avatar of the voice sage
sagefemale
Avatar of the voice felix
felixmale
Avatar of the voice milo
milomale
Avatar of the voice atlas
atlasmale
Avatar of the voice orion
orionmale

23 languages

Any voice speaks any of these languages.

Sources and further reading

  1. Wikipedia
  2. LibriVox public-domain audiobooks
  3. Python documentation
  4. openai-python on GitHub
  5. LibriTTS-R corpus (OpenSLR 141)
  6. IETF RFC 7845: Ogg Opus
  7. openai-node on GitHub
  8. MDN: Web Speech API
  9. TRON developer hub: TRC-20
  10. W3C WAI: making audio and video accessible
  11. curl documentation
  12. LibriTTS-R paper (arXiv 2305.18802)

More on this site