Next.js Discord

Discord Forum

How to return streaming audio from api handler

Unanswered
Keyhole wasp posted this in #help-forum
Open in Discord
Avatar
Keyhole waspOP
I want to use elevenlabs to generate some streaming audio and then return the stream in the response. The docs talkabout using the textstream from the ai sdk but is there a solution for audio?

my code:
import { NextRequest, NextResponse } from 'next/server'
import { ElevenLabsClient } from 'elevenlabs'
import { ELEVEN_LABS_API_KEY, ELEVEN_LABS_VOICE_ID } from '@/constants'
const elevenlabs = new ElevenLabsClient({
  apiKey: ELEVEN_LABS_API_KEY, // Defaults to process.env.ELEVENLABS_API_KEY
})
interface RequestBody {
  text: string
}

export async function POST(request: NextRequest): Promise<NextResponse> {
  const { text }: RequestBody = await request.json()

  const audioStream = await elevenlabs.generate({
    stream: true,
    voice: ELEVEN_LABS_VOICE_ID,
    text: text,
    model_id: 'eleven_multilingual_v2',
  })
  
  ///????
}
export const maxDuration = 300


looking for some clues of where to get started with this?

0 Replies