How to Integrate Our Text-to-Speech API into Your App?

By LingvoLink editorial team · Updated 2026-11-18

This guide walks you through integrating LingvoLink’s text-to-speech API into your language learning application. We cover the full lifecycle: from setting up your API key and configuring the OpenAI-compatible endpoint to handling voice selection, language detection, and error responses. You’ll learn how to structure requests for optimal performance and manage costs effectively.

Designed for engineering teams building programmable audio workflows, this page provides concrete code examples in Python, JavaScript, and cURL. Whether you are generating short pronunciation clips or longer lesson content, you will find specific instructions on speed settings, format choices, and scaling strategies to ensure reliable audio delivery in your stack.

How to Integrate Our Text-to-Speech API into Your App?

Frequently asked questions

What is the easiest way to start?

Sign up on /get-api-key/ using Google or email. You receive a Bearer token and $0.50 trial credit. Send a POST request to https://api.pk8ok.com/v1/audio/speech with your text and voice preset. The API returns an audio file instantly. No complex setup is required to begin generating speech.

Do I need to use the OpenAI SDK?

No. You can use any HTTP client. The endpoint matches the OpenAI speech format, so you can use the OpenAI SDK by changing the base_url to https://api.pk8ok.com/v1. Alternatively, use plain HTTP requests with your Bearer token in the Authorization header. Any language with HTTP support works.

Can I use Python for integration?

Yes. Use the official OpenAI Python SDK or standard libraries like requests. Set the base_url to https://api.pk8ok.com/v1. Pass your API key as a Bearer token. Send a JSON body with model, input, voice, and response_format. The SDK handles the request and returns the audio data directly.

Is JavaScript support available?

Yes. Use fetch or any HTTP library. Set the Authorization header with your Bearer token. POST to https://api.pk8ok.com/v1/audio/speech. Include model, input, voice, and response_format in the JSON body. The API returns the audio file, which you can play or save in your JavaScript application.

How do I handle long texts?

Split text into parts of up to 4096 characters. Send each part as a separate POST request to the API. Join the resulting audio files on your end. Requests are processed sequentially, so under load, a request may wait in a queue. This ensures reliable generation for longer content.

What is the best voice for language learning?

Q: Which voices are suitable for language learning? A: Aria offers a warm, clear narrator style, while Sage provides a calm, instructional tone. Both are well-suited for educational content. You can choose any of the 8 presets, as all voices support all 23 languages. Test voices with your specific language to find the best fit for your learners.

How do I detect the language automatically?

Set the language parameter to an ISO code. If omitted, the API guesses the language from the script. Latin script defaults to English. For non-English Latin text, explicitly set the language parameter. This ensures accurate pronunciation. Supported languages include Arabic, Chinese, French, German, Spanish, and others listed in the docs.

Can I change the speed of the audio?

Yes. Use the speed parameter in your request. Values range from 0.25 to 4.0. This allows you to slow down speech for learners or speed it up for practice. The API processes requests sequentially, so speed changes do not affect generation time significantly.

What formats are best for mobile apps?

Q: Which formats are recommended for mobile apps? A: MP3 is widely supported and offers good compression. WAV provides uncompressed quality. OPUS is efficient for streaming. FLAC offers lossless quality. PCM is raw audio. Choose based on your app requirements. MP3 is often preferred for mobile due to balance between size and compatibility.

How do I manage API keys securely?

Use the Authorization: Bearer header. Store your key in environment variables. You can issue a new key at any time via the dashboard. The old key stops immediately. Rotate keys regularly. Do not expose keys in client-side code if possible. Use HTTPS for all requests.

What happens if the API is down?

Requests are processed sequentially. Under load, requests may wait in a queue. Failed requests are free; charges are returned in full. There is no SLA or uptime guarantee. Monitor your response codes. If errors occur, retry with exponential backoff. Support is available via email.

How do I track my usage?

View your dashboard at /get-api-key/. It shows balance, characters left, and usage history. You are charged $0.01 per 1,000 characters. Failed requests are free. Track characters consumed per request to manage your budget. The dashboard updates in real-time as you use the API.

Can I use this API in a browser?

Yes. Send requests directly from your browser using fetch or XMLHttpRequest. Include your Bearer token in the Authorization header. Be aware that exposing your API key in client-side code may allow others to use your balance. Consider using a backend proxy for production apps.

Do I need a backend server?

Not strictly. You can call the API directly from the browser. However, a backend server is recommended to hide your API key and manage rate limits. It also allows you to split long texts and join audio files server-side. This provides better security and control.

Prerequisites

Sound wave illustration for: Prerequisites

Before integrating the LingvoLink TTS API, ensure you have a valid API key from /get-api-key/. Keys are tied to your account balance and support rate limits of 60 requests per minute.

Your development environment must support standard HTTP JSON requests. Since the API follows the OpenAI SDK shape, you can use existing Python, JS, or PHP libraries with a simple base URL adjustment.

API Key

Sign up at /get-api-key/ to generate your key. It starts with tts- and authenticates all requests. You can rotate keys instantly if needed.

  • Keys are per account, not per project.
  • New keys invalidate the old one immediately.

Development Environment

Standard HTTP clients work. We recommend using the official OpenAI SDK for Python or JS, pointing it to our base URL. No custom SDK installation is required.

Network Access

Ensure your server can reach https://api.pk8ok.com/v1. Standard HTTPS ports (443) are sufficient. No special firewall rules are needed for typical startup infrastructures.

Setup

Sound wave illustration for: Setup

Integration requires installing the official OpenAI SDK or using plain HTTP, as LingvoLink uses the same request schema. This allows immediate compatibility with your existing Python, JS, or PHP stacks without learning a new protocol.

Configure the client to point to our API base URL and authenticate with your unique key. This ensures all requests route correctly to the speech generation engine.

Install SDK

Use the standard OpenAI library for your language. This provides a familiar interface for making API calls. No custom client is needed because the endpoint structure mirrors OpenAI’s speech endpoint exactly.

  • Python: pip install openai
  • Node.js: npm install openai
  • PHP: composer require openai-php/client

Configure Base URL

Set the base URL to https://api.pk8ok.com/v1. This directs requests to the correct processing cluster. The endpoint for speech generation remains /audio/speech, maintaining standard request shapes.

Set Authentication

Include your API key in the Authorization header as Bearer tts-... . Each account holds one active key. If you issue a new key, the old one stops immediately, ensuring secure access control.

First Request

Sound wave illustration for: First Request

Once you have your API key, making your first request is straightforward. The API follows the standard OpenAI speech endpoint shape, allowing you to use familiar SDKs or simple HTTP calls. You send a JSON payload with the text, voice, and model, and receive an audio file in response.

Below are minimal examples for cURL, Python, and JavaScript to get you generating audio immediately. Replace YOUR_API_KEY with your key from the dashboard.

Curl Example

Use cURL for quick testing or shell scripts. This command sends a simple text string and returns an MP3 file.

```bash curl -X POST "https://api.pk8ok.com/v1/audio/speech" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "tts-1", "input": "Hello, this is a test.", "voice": "aria", "response_format": "mp3"}' \ -o speech.mp3 ```

Python Example

The OpenAI Python SDK works out of the box by pointing it to our base URL. Ensure you have the openai package installed.

```python from openai import OpenAI client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.pk8ok.com/v1") response = client.audio.speech.create( model="tts-1", voice="nova", input="Language learning made simple." ) response.stream_to_file("output.mp3") ```

JS Example

For Node.js or browser environments, use the official OpenAI SDK. Configure the base URL to our API endpoint.

```javascript import OpenAI from 'openai'; const openai = new OpenAI({ apiKey: 'YOUR_API_KEY', baseURL: 'https://api.pk8ok.com/v1' }); const audio = await openai.audio.speech.create({ model: 'tts-1', voice: 'felix', input: 'Start your journey here.', response_format: 'mp3' }); const buffer = Buffer.from(await audio.arrayBuffer()); ```

Voice Selection

Sound wave illustration for: Voice Selection

Select from eight distinct voice presets, each engineered for specific audio characteristics. Choose between four female voices and four male voices to match your application’s auditory identity. Every voice supports all 23 languages, ensuring consistent quality regardless of the target language.

Female Voices

Aria offers a warm, clear narrator style ideal for educational content. Nova provides a bright, upbeat tone suitable for energetic marketing or app notifications. Luna delivers a soft, storytelling voice perfect for audiobooks or calm interfaces. Sage presents a calm, instructional tone well-suited for guided learning modules.

  • Aria: Warm, clear narrator
  • Nova: Bright, upbeat
  • Luna: Soft, storytelling
  • Sage: Calm, instructional

Male Voices

Felix brings an energetic, promotional voice to dynamic content. Milo offers a friendly, conversational tone for interactive features. Atlas provides a neutral, news-style delivery for factual information. Orion delivers a deep, documentary-style voice for serious or immersive experiences.

  • Felix: Energetic, promo
  • Milo: Friendly, conversational
  • Atlas: Neutral, news
  • Orion: Deep, documentary

Tone Matching

Match voice personality to your app’s context. Use Felix for high-engagement tasks and Atlas for data-heavy interfaces. Adjust speed between 0.25 and 4.0 to fine-tune pacing. Remember that each generated file contains an inaudible synthetic watermark for identification purposes.

Language Handling

Sound wave illustration for: Language Handling

The API automatically infers the language from the text script, defaulting to English for Latin characters. This simplifies initial integration but requires explicit configuration for non-English Latin text to ensure accurate pronunciation.

You can force a specific language by passing the ISO code in the request body. This overrides auto-detection and guarantees the engine uses the correct phonetic rules for the selected voice.

{

h3

Auto-Detection

paras

['The system guesses the language based on Unicode script properties. Latin script defaults to English. If you send French or German text without specifying the language, the engine may still pronounce it with an English accent if not explicitly set.', '']

bullets

['Latin text defaults to English if language is omitted']

Error Handling

Sound wave illustration for: Error Handling

Handling errors correctly prevents wasted credits and keeps your integration resilient. Understanding the specific failure modes of the TTS API allows you to distinguish between transient network issues and permanent configuration mistakes, ensuring that your application behaves predictably under load or when receiving malformed data.

Rate Limits

The API enforces a limit of 60 requests per minute per key (10 per minute before the first top-up). If you exceed this, you will receive a 429 status code. Since requests are processed sequentially, high concurrency may cause queuing delays before the limit is hit.

  • Implement exponential backoff on 429 responses.
  • Monitor usage via the /v1/voices endpoint.
  • Upgrade key status by topping up to increase limits.

Invalid Input

Requests fail if the input text exceeds 4096 characters or if an unsupported voice or format is specified. The API returns a 400 error with a descriptive message. Note that failed requests are free, so these errors do not consume your character balance.

  • Validate text length before sending.
  • Ensure voice names match the 8 presets.
  • Check response_format is one of: mp3, wav, opus, flac, pcm.

Network Errors

Transient network issues may result in 5xx errors or timeouts. The API processes requests one after another, so under heavy load, generation times may vary. Implement retries for 500-level errors, but avoid aggressive retry loops to prevent exacerbating congestion.

  • Retry 500 errors with jitter.
  • Set reasonable timeout thresholds (e.g., 30s).
  • Log error codes for debugging support.

Optimization

Sound wave illustration for: Optimization

Optimize your integration by adjusting speed and format settings to balance latency and file size. Use speed multipliers to accelerate narration or slow it down for clarity, and select formats like MP3 for bandwidth efficiency or WAV for lossless quality.

Speed Settings

Adjust the speed parameter (0.25–4.0) to control playback rate. Faster speeds reduce processing time but may affect clarity for language learners. Slower speeds improve comprehension but increase generation latency.

  • Standard speed: 1.0
  • Fast narration: 1.5–2.0
  • Slower for learners: 0.75–0.9

Format Choice

Choose mp3 for smaller file sizes and faster downloads, or wav for uncompressed audio. Use opus for efficient compression and flac for lossless archival. Select pcm for raw data processing.

  • mp3: Balanced size/quality
  • wav: Lossless, larger files
  • opus: Efficient streaming
  • flac: Lossless archival

Caching

Cache generated audio files locally or on your CDN since voice outputs are deterministic. This avoids redundant API calls for identical text inputs, reducing costs and latency for repeated content like vocabulary words or phrases.

  • Hash input text + voice + speed
  • Store MP3/WAV files
  • Invalidate on content update
Optimization

Scaling

Sound wave illustration for: Scaling

Scaling your TTS integration requires handling volume without exceeding the 60 requests per minute limit. For long texts, split input into chunks of up to 4096 characters and join the resulting audio files. This ensures consistent delivery even for extended educational content.

Batch Processing

Process multiple distinct texts sequentially to maintain order. Since requests are processed one after another, batching small phrases minimizes overhead while staying within the per-key rate limit of 60 requests per minute.

  • Split long texts into 4096-character segments
  • Concatenate output audio files programmatically
  • Respect the 60 req/min limit per key

Concurrency

Use multiple API keys to increase throughput. Each key allows 60 requests per minute, so running parallel processes with different keys effectively multiplies your capacity. This is ideal for language learning apps generating vocabulary sets.

  • Rotate between multiple API keys
  • Run parallel synthesis jobs
  • Scale horizontally by adding keys

Queue Management

Implement a task queue to handle spikes in demand. Under load, requests may wait in a queue, causing delays. Prioritize urgent audio generation and defer non-critical content to maintain user experience during peak hours.

  • Use a message queue (e.g., Redis, RabbitMQ)
  • Prioritize high-traffic vocabulary items
  • Defer low-priority content during peak load

Testing

Sound wave illustration for: Testing

Testing ensures your TTS integration handles character limits, rate limits, and audio formats correctly before production. Use unit tests to verify request payload structure and response parsing. Focus on boundary conditions like the 4096-character limit and speed range validation.

Integration tests should confirm that the API returns valid audio files in your chosen format (mp3, wav, opus, flac, pcm) and that authentication via Bearer token works with the configured base URL.

Unit Tests

Validate input parameters such as model, voice, speed, and response_format. Ensure that texts exceeding 4096 characters are split correctly if handled client-side, or that the API rejects oversized inputs with a 400 error.

Test that invalid voice names or unsupported formats trigger appropriate error responses without crashing your application.

  • Verify payload structure for POST /v1/audio/speech
  • Check character count limits (4096 chars)
  • Validate speed range (0.25–4.0)

Integration Tests

Send a full request to the live API endpoint and verify the audio file is returned with the correct Content-Type. Ensure the audio duration aligns with the input text length, considering the typical real-time generation speed.

Confirm that the Authorization: Bearer header is correctly applied and that the key has sufficient balance.

  • Verify audio file format (mp3/wav/opus/flac/pcm)
  • Check response headers and status codes
  • Validate audio playback integrity

Load Testing

Simulate concurrent requests to ensure your application handles the 60 requests per minute rate limit without queuing failures. Monitor response times, as short phrases may take a few seconds and longer texts are processed sequentially.

Test retry logic for temporary network errors or rate limit exceeded (429) responses to ensure smooth user experience under load.

  • Simulate 60 requests/minute
  • Test retry logic for 429 errors
  • Monitor queue wait times

Deployment

Sound wave illustration for: Deployment

Deployment requires isolating the API key from application code to prevent accidental exposure in version control. Store the Bearer token in environment variables, ensuring it is loaded dynamically at runtime rather than hardcoded in configuration files.

Environment Variables

Inject the key via AUTH_KEY in your deployment environment. This ensures the same codebase works across dev, staging, and production without manual updates to the source code.

Secret Management

Use your platform’s secret manager to rotate keys. Since a new key invalidates the old one immediately, ensure your deployment pipeline handles key swaps without downtime by updating the secret store before restarting services.

  • Never log the full key in plain text.

Monitoring

Track request latency and character counts. Since requests are processed sequentially, monitor queue depth to detect if your concurrency is approaching the 60 requests/minute limit, triggering 429 errors.

  • Alert on HTTP 429 status codes.

Troubleshooting

Sound wave illustration for: Troubleshooting

If audio generation fails or sounds unnatural, check your request logs first. Most issues stem from exceeding the 4096 character limit or incorrect language codes for non-English Latin text. Verify that your API key is active and not expired, as a new key invalidates the old one immediately.

Common Issues

Ensure you are splitting long texts into chunks of 4096 characters. If a request times out, it may be waiting in the queue under load. Failed requests are free, so retrying is cost-neutral if you receive a non-200 status code.

  • Check character count per request (< 4096)
  • Verify API key status
  • Confirm language code for non-English text

Debug Logs

Enable verbose logging in your SDK to capture request headers and response bodies. The x-request-id header is useful for correlating issues with our backend logs. Check for standard HTTP error codes like 429 (Rate Limit) or 400 (Bad Request).

Support Contact

Support is available via email only. Please include your API key, request ID, and a reproducible code snippet in your message. We do not offer live chat or phone support.

Best Practices

Sound wave illustration for: Best Practices

Proper text handling and validation ensure consistent audio quality and predictable billing. By standardizing input and verifying outputs, you avoid unnecessary character consumption and playback issues.

Text Cleaning

Strip unnecessary whitespace and normalize punctuation before sending requests. This prevents the API from generating unnatural pauses or artifacts, ensuring the audio matches your intended rhythm exactly.

  • Remove trailing spaces and extra newlines.
  • Normalize ellipses and dashes for consistent pacing.
  • Ensure text stays within the 4096-character limit per request.

Audio Validation

Verify that the returned audio file is valid and plays correctly. Check that the format matches your response_format parameter and that the duration aligns with the input length.

  • Validate file headers against the requested format (mp3, wav, etc.).
  • Check that audio duration is non-zero and reasonable.
  • Ensure no truncation occurred during the transfer.

Cost Tracking

Monitor your character count against your balance to avoid service interruption. Since each request counts characters including spaces, track usage in your application logs to stay within your budget.

  • Log character count for every successful request.
  • Set alerts when balance drops below $1.00.
  • Review usage to estimate future TRC-20 top-up needs.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. There are no monthly plans, no subscriptions, and no VAT invoices.

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. LibriTTS-R paper (arXiv 2305.18802)
  3. LibriTTS-R corpus (OpenSLR 141)
  4. ISO 639 language codes
  5. TRON developer hub: TRC-20
  6. Tether (USDT)
  7. Python documentation
  8. openai-python on GitHub
  9. FFmpeg documentation
  10. openai-node on GitHub
  11. W3C WAI: making audio and video accessible
  12. Node.js documentation

More on this site