रीयलटाइम ट्रांसलेशन API
कुछ ही मिनटों में किसी भी application में लाइव speech-to-speech translation जोड़ें। Audio stream करें और translated audio तथा transcripts प्राप्त करें — यह सब एक ही WebSocket connection के माध्यम से।
रीयलटाइम ट्रांसलेशन API क्यों?
उन applications के लिए बनाया गया है जिन्हें तुरंत और लगातार translation की आवश्यकता होती है। एक persistent connection पूरी session को संभालता है — बिना polling, बिना delay और बिना complexity के।
अत्यंत कम Latency
Streaming audio का real time में translation होकर वापस मिलता है। कोई request-response round trips नहीं — speaker के बोलते समय ही परिणाम प्राप्त होते हैं।
Audio In, Audio Out
Raw microphone audio भेजें और translated speech वापस प्राप्त करें। Input और output transcripts भी stream होते हैं ताकि आप live captions दिखा सकें।
130+ भाषाएँ
Standard BCP-47 language codes का उपयोग करके किसी भी प्रमुख भाषा में translation करें। Sessions के बीच target language बदलें बिना SDK में बदलाव किए।
डिफ़ॉल्ट रूप से सुरक्षित
हर connection आपके JWT token से authenticate होता है। Sessions प्रत्येक user के लिए अलग रहती हैं — आपका audio कभी share या store नहीं किया जाता।
Connect और Authenticate करें
रीयलटाइम ट्रांसलेशन API एक dedicated Socket.IO namespace पर चलता है। Connection बनाते समय अपनी API key को query parameter के रूप में पास करें — server session शुरू होने से पहले इसे validate करता है।
wss://api.gpttranslator.co └── namespace: /api/realtime-translator
import { io } from 'socket.io-client'; // Connect to the Realtime Translation namespace const socket = io('https://api.gpttranslator.co/api/realtime-translator', { transports: ['websocket'], query: { apiKey: 'YOUR_API_KEY' // your GPT Translator API key }, });
नोट: GPT Translator dashboard में API Keys section से अपनी API key प्राप्त करें। बिना valid API key वाले connections तुरंत reject कर दिए जाते हैं।
अपनी API key को कभी भी client-side code में उजागर न करें
ऊपर दिया गया code example केवल उदाहरण के लिए है। अपनी API key को सीधे browser JavaScript में जोड़ने से वह किसी भी व्यक्ति को दिखाई दे सकती है जो आपके page source या network traffic की जांच करता है — और फिर कोई भी आपकी key का उपयोग करके आपका token balance समाप्त कर सकता है।
✅ सुझाव: अपने backend के माध्यम से proxy का उपयोग करें
आपका server API key को सुरक्षित रूप से रखता है और browser की ओर से Socket.IO connection खोलता है। Browser आपके server से जुड़ता है, सीधे translation API से नहीं।
// Your backend holds the key — the browser never sees it
const socket = io('https://api.gpttranslator.co/api/realtime-translator', {
transports: ['websocket'],
query: { apiKey: process.env.GPT_TRANSLATOR_API_KEY },
});
// Proxy events between the browser client and the translation API
browserSocket.on('translation_start', (data) => socket.emit('translation_start', data));
browserSocket.on('audio_chunk', (chunk) => socket.emit('audio_chunk', chunk));
browserSocket.on('translation_stop', () => socket.emit('translation_stop'));
socket.on('output_audio', (data) => browserSocket.emit('output_audio', data));
socket.on('output_transcript', (data) => browserSocket.emit('output_transcript', data));
socket.on('input_transcript', (data) => browserSocket.emit('input_transcript', data));Session Lifecycle
हर translation session एक सरल पाँच-स्टेप sequence का पालन करती है। इस क्रम को समझने से आप एक मजबूत integration बना सकेंगे।
Session शुरू करें
आप emit करते हैंTarget language code के साथ translation_start emit करें। Server आपके token balance को reserve करता है और session initialize करना शुरू करता है।
Readiness signals का इंतजार करें
आप listen करते हैंServer क्रम में तीन status events emit करता है: session_initializing, translation_ready, और अंत में ready_for_audio। केवल ready_for_audio के बाद ही audio भेजना शुरू करें।
Audio chunks stream करें
आप emit करते हैंMicrophone से capture किए गए base64-encoded PCM16 audio के साथ लगातार audio_chunk events emit करें। Lowest latency के लिए chunks छोटे रखें (लगभग 100 ms प्रत्येक)।
Translated output प्राप्त करें
आप listen करते हैंTranslation के दौरान server output_audio (translated speech), output_transcript (translated text), और input_transcript (recognized source text) stream करता है — सब incremental deltas के रूप में।
Session समाप्त करें
आप emit करते हैंSession को सही तरीके से बंद करने के लिए translation_stop emit करें। Token usage finalize हो जाता है और translation_closed event session समाप्त होने की पुष्टि करता है।
Events Reference
रीयलटाइम ट्रांसलेशन API के हर event का पूरा reference — आप क्या भेजते हैं और क्या प्राप्त करते हैं।
वे Events जिन्हें आप Emit करते हैं
आप emit करते हैंtranslation_startएक नई translation session शुरू करता है। Target language के लिए BCP-47 language code पास करें।
{
"targetLanguage": "es" // BCP-47 language code (e.g. "fr", "de", "zh", "ja")
}audio_chunkRaw microphone audio का एक chunk भेजता है। audioData field base64-encoded PCM16 mono audio buffer होना चाहिए जिसका sample rate 24,000 Hz हो।
{
"audioData": "<base64-encoded PCM16 mono audio>"
// Sample rate: 24 000 Hz
// Encoding: 16-bit PCM, little-endian
// Send continuously while the user speaks
}translation_stopSession को सही तरीके से समाप्त करता है। Server billing finalize करता है और translation_closed emit करता है।
वे Events जिन्हें आप Listen करते हैं
आप listen करते हैंsession_initializingstatustranslation_start के तुरंत बाद emit किया जाता है। यह दर्शाता है कि session setup हो रही है — अभी audio के लिए तैयार नहीं है।
translation_readystatusजब server-side connection स्थापित हो जाता है तब emit किया जाता है। अंतिम session activation का अभी इंतजार है।
ready_for_audiostatusSession पूरी तरह active है। अब audio_chunk events stream करना शुरू करें।
output_audiostreamTranslated speech audio का एक chunk। Delta एक base64-encoded PCM16 audio buffer है। लगातार आने वाले deltas को buffer करें और क्रम में play करें।
{
"delta": "<base64-encoded PCM16 audio chunk>"
// Decoded and played directly to the output speaker
// Arrives incrementally — buffer chunks for smooth playback
}output_transcriptstreamTranslated text का एक fragment। अपने UI में पूरा translated transcript बनाने के लिए deltas को जोड़ें।
{
"delta": "Hola, ¿cómo estás?" // translated text fragment
}input_transcriptstreamRecognized source speech का एक fragment। Source-language caption बनाने के लिए deltas को जोड़ें।
{
"delta": "Hello, how are you?" // recognized source speech fragment
}translation_closedstatusयह पुष्टि करता है कि session सही तरीके से समाप्त हुई — चाहे translation_stop के बाद या जब server token समाप्त होने के कारण session बंद कर दे।
translation_errorerrorएक unexpected error हुई। message field बताती है कि क्या गलत हुआ। Session अभी भी active हो सकती है — आप retry कर सकते हैं या translation_stop call कर सकते हैं।
{
"message": "Translation session error. Please try again."
}insufficient_tokenserrorआपका token balance समाप्त हो गया है। Session अपने आप बंद कर दी गई है। जारी रखने के लिए अपना plan upgrade करें।
{
"message": "You have reached the limit of words for translation...",
"remainingTokens": 0
}Complete Integration Example
एक minimal लेकिन complete JavaScript example जो दिखाता है कि कैसे connect करें, session शुरू करें, audio stream करें, सभी server events को handle करें, और session को सही तरीके से बंद करें।
import { io } from 'socket.io-client';
const socket = io('https://api.gpttranslator.co/api/realtime-translator', {
transports: ['websocket'],
query: { apiKey: 'YOUR_API_KEY' },
});
// ─── Listen for server events ───────────────────────────────────────
socket.on('session_initializing', () => {
console.log('Session is being prepared...');
});
socket.on('translation_ready', () => {
console.log('Session connected. Waiting for activation...');
});
socket.on('ready_for_audio', () => {
console.log('Ready! Start streaming audio chunks now.');
startMicrophone(); // begin capturing and sending audio
});
socket.on('output_audio', ({ delta }) => {
// delta is a base64-encoded PCM16 audio chunk
playAudioChunk(atob(delta));
});
socket.on('output_transcript', ({ delta }) => {
// Append translated text delta to your UI
appendToTranscript('translated', delta);
});
socket.on('input_transcript', ({ delta }) => {
// Append recognized source speech to your UI
appendToTranscript('original', delta);
});
socket.on('translation_closed', () => {
console.log('Session ended.');
stopMicrophone();
});
socket.on('translation_error', ({ message }) => {
console.error('Error:', message);
stopMicrophone();
});
socket.on('insufficient_tokens', ({ message, remainingTokens }) => {
console.warn('Out of tokens:', message, 'remaining:', remainingTokens);
stopMicrophone();
showUpgradePrompt();
});
// ─── Start a session ────────────────────────────────────────────────
socket.emit('translation_start', { targetLanguage: 'es' });
// ─── Stream audio chunks ────────────────────────────────────────────
function onAudioData(pcm16Base64) {
socket.emit('audio_chunk', { audioData: pcm16Base64 });
}
// ─── Stop the session ───────────────────────────────────────────────
function stopSession() {
socket.emit('translation_stop');
}Billing कैसे काम करती है
रीयलटाइम translation का billing session duration के आधार पर होता है — session activate होने से लेकर translation_stop या token exhaustion तक। कोई per-character या per-word counting नहीं होती।
Per-Second Billing
Usage को seconds में मापा जाता है जब से आपकी session पूरी तरह active होती है तब तक जब तक वह समाप्त न हो जाए। Partial seconds को ऊपर की ओर round किया जाता है।
Tokens Live Deduct होते हैं
हर session के अंत में actual duration के आधार पर आपके balance से tokens deduct किए जाते हैं। Session शुरू होने से पहले आपका available balance check किया जाता है।
Automatic Cap
जब आपका remaining token balance समाप्त होने वाला होता है तब session अपने आप terminate हो जाती है। Session बंद होने से पहले आपको insufficient_tokens event प्राप्त होगा।
अनुमानित Token Consumption
नोट: Token estimates अनुमानित हैं। वास्तविक consumption audio noise levels और session activity पर निर्भर करती है। Real-time usage के लिए अपना dashboard देखें।
Audio Format Requirements
सर्वोत्तम accuracy और lowest latency के लिए API एक specific audio format की अपेक्षा करती है। Browser में microphone audio capture और convert करने के लिए नीचे दिए गए code snippet का उपयोग करें।
PCM 16-bit, little-endian24 000 Hz1 (mono)Base64 string// Capture PCM16 audio from the browser microphone
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const audioContext = new AudioContext({ sampleRate: 24000 });
const source = audioContext.createMediaStreamSource(stream);
const processor = audioContext.createScriptProcessor(4096, 1, 1);
processor.onaudioprocess = (e) => {
const float32 = e.inputBuffer.getChannelData(0);
// Convert Float32 → Int16 PCM
const int16 = new Int16Array(float32.length);
for (let i = 0; i < float32.length; i++) {
int16[i] = Math.max(-32768, Math.min(32767, float32[i] * 32768));
}
// Base64-encode and send
const base64 = btoa(String.fromCharCode(...new Uint8Array(int16.buffer)));
socket.emit('audio_chunk', { audioData: base64 });
};
source.connect(processor);
processor.connect(audioContext.destination);अक्सर पूछे जाने वाले प्रश्न
रीयलटाइम ट्रांसलेशन API के integration और उपयोग से संबंधित सामान्य प्रश्न।