Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions apps/sim/app/api/proxy/tts/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { NextResponse } from 'next/server'
import { createLogger } from '@/lib/logs/console-logger'
import { uploadFile } from '@/lib/uploads/storage-client'
import { getBaseUrl } from '@/lib/urls/utils'

const logger = createLogger('ProxyTTSAPI')

Expand Down Expand Up @@ -44,12 +46,18 @@ export async function POST(request: Request) {
return new NextResponse('Empty audio received', { status: 422 })
}

return new NextResponse(audioBlob, {
headers: {
'Content-Type': 'audio/mpeg',
'Cache-Control': 'public, max-age=86400', // Cache for a day
'Access-Control-Allow-Origin': '*', // CORS support
},
// Upload the audio file to storage and return multiple URL options
const audioBuffer = Buffer.from(await audioBlob.arrayBuffer())
const timestamp = Date.now()
const fileName = `elevenlabs-tts-${timestamp}.mp3`
const fileInfo = await uploadFile(audioBuffer, fileName, 'audio/mpeg')

// Generate the full URL for external use using the configured base URL
const audioUrl = `${getBaseUrl()}${fileInfo.path}`

return NextResponse.json({
audioUrl,
size: fileInfo.size,
})
} catch (error) {
logger.error('Error proxying TTS:', error)
Expand Down
6 changes: 2 additions & 4 deletions apps/sim/tools/elevenlabs/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsRes
throw new Error(`ElevenLabs API error: ${response.status} ${response.statusText}`)
}

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

return {
success: true,
output: {
audioUrl,
audioUrl: data.audioUrl,
},
}
},
Expand Down