Skip to content

Commit 29374ec

Browse files
authored
fix: eleven labs deployment returning uploaded blob (#583)
1 parent fb15ee0 commit 29374ec

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

apps/sim/app/api/proxy/tts/route.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NextResponse } from 'next/server'
22
import { createLogger } from '@/lib/logs/console-logger'
3+
import { uploadFile } from '@/lib/uploads/storage-client'
34

45
const logger = createLogger('ProxyTTSAPI')
56

@@ -44,12 +45,20 @@ export async function POST(request: Request) {
4445
return new NextResponse('Empty audio received', { status: 422 })
4546
}
4647

47-
return new NextResponse(audioBlob, {
48-
headers: {
49-
'Content-Type': 'audio/mpeg',
50-
'Cache-Control': 'public, max-age=86400', // Cache for a day
51-
'Access-Control-Allow-Origin': '*', // CORS support
52-
},
48+
// Upload the audio file to storage and return multiple URL options
49+
const audioBuffer = Buffer.from(await audioBlob.arrayBuffer())
50+
const timestamp = Date.now()
51+
const fileName = `elevenlabs-tts-${timestamp}.mp3`
52+
const fileInfo = await uploadFile(audioBuffer, fileName, 'audio/mpeg')
53+
54+
// Generate the full URL for external use
55+
const host = request.headers.get('host') || 'localhost:3000'
56+
const protocol = request.headers.get('x-forwarded-proto') || 'http'
57+
const audioUrl = `${protocol}://${host}${fileInfo.path}`
58+
59+
return NextResponse.json({
60+
audioUrl,
61+
size: fileInfo.size,
5362
})
5463
} catch (error) {
5564
logger.error('Error proxying TTS:', error)

apps/sim/tools/elevenlabs/tts.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsRes
5555
throw new Error(`ElevenLabs API error: ${response.status} ${response.statusText}`)
5656
}
5757

58-
// Create a blob URL that can be used in an audio player
59-
const audioBlob = await response.blob()
60-
const audioUrl = URL.createObjectURL(audioBlob)
58+
const data = await response.json()
6159

6260
return {
6361
success: true,
6462
output: {
65-
audioUrl,
63+
audioUrl: data.audioUrl,
6664
},
6765
}
6866
},

0 commit comments

Comments
 (0)