स्ट्रीमिंग

चंकेड ट्रांसफर एन्कोडिंग का इस्तेमाल करके ElevenLabs API से रीयल-टाइम ऑडियो स्ट्रीम करना सीखें

ElevenLabs API चुनिंदा एंडपॉइंट के लिए रीयल-टाइम ऑडियो स्ट्रीमिंग को सपोर्ट करता है, जो चंकेड ट्रांसफर एन्कोडिंग के ज़रिए HTTP पर सीधे रॉ ऑडियो बाइट्स (जैसे MP3 डेटा) लौटाता है। इससे क्लाइंट ऑडियो जनरेट होने के साथ-साथ उसे इंक्रीमेंटल तरीके से प्रोसेस या प्ले कर सकते हैं।

हमारी आधिकारिक Node और Python लाइब्रेरी में इस लगातार चलने वाली ऑडियो स्ट्रीम को संभालना आसान बनाने के लिए यूटिलिटी शामिल हैं।

टेक्स्ट टू स्पीच API, वॉइस चेंजर API और ऑडियो आइसोलेशन API के लिए स्ट्रीमिंग सपोर्ट की जाती है। यह सेक्शन टेक्स्ट टू स्पीच API को किए गए अनुरोधों के लिए स्ट्रीमिंग के काम करने के तरीके पर केंद्रित है।

Python में, स्ट्रीमिंग अनुरोध इस तरह दिखता है:

from elevenlabs import stream
from elevenlabs.client import ElevenLabs
elevenlabs = ElevenLabs()
audio_stream = elevenlabs.text_to_speech.stream(
text="This is a test",
voice_id="JBFqnCBsd6RMkjVDRZzb",
model_id="eleven_multilingual_v2"
)
# option 1: play the streamed audio locally
stream(audio_stream)
# option 2: process the audio bytes manually
for chunk in audio_stream:
if isinstance(chunk, bytes):
print(chunk)

Node / Typescript में, स्ट्रीमिंग अनुरोध इस तरह दिखता है:

import { ElevenLabsClient, stream } from "@elevenlabs/elevenlabs-js";
import { Readable } from "stream";
const elevenlabs = new ElevenLabsClient();
async function main() {
const audioStream = await elevenlabs.textToSpeech.stream("JBFqnCBsd6RMkjVDRZzb", {
text: "This is a test",
modelId: "eleven_v3",
});
// option 1: play the streamed audio locally
await stream(Readable.from(audioStream));
// option 2: process the audio manually
for await (const chunk of audioStream) {
console.log(chunk);
}
}
main();