Skip to content

Instantly share code, notes, and snippets.

View dosstx's full-sized avatar

Nick Medrano dosstx

  • Organik, LLC
  • Virtual
View GitHub Profile
@chanmathew
chanmathew / streaming.ts
Last active April 21, 2024 04:40
ElevenLabs streaming implementation - Typescript
const voiceId = '' // Pick any voice ID from https://docs.elevenlabs.io/api-reference/voices
const model = 'eleven_monolingual_v1'
const elUrl = `https://api.elevenlabs.io/v1/text-to-speech/${voiceId}/stream?optimize_streaming_latency=3` // Optimize for latency
const codec = 'audio/mpeg'
const maxBufferDuration = 60 // Maximum buffer duration in seconds
const maxConcurrentRequests = 3 // Maximum concurrent requests allowed
// Create a new MediaSource and Audio element
const mediaSource = new MediaSource()
const audioElement = new Audio()