Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 20 additions & 2 deletions apps/sim/app/api/tools/tts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
)
if (!parsed.success) return parsed.response

const { text, voiceId, apiKey, modelId, workspaceId, workflowId, executionId } =
parsed.data.body
const {
text,
voiceId,
apiKey,
modelId,
stability,
similarityBoost,
workspaceId,
workflowId,
executionId,
} = parsed.data.body

const voiceIdValidation = validateAlphanumericId(voiceId, 'voiceId', 255)
if (!voiceIdValidation.isValid) {
Expand All @@ -57,6 +66,14 @@ export const POST = withRouteHandler(async (request: NextRequest) => {

const endpoint = `https://api.elevenlabs.io/v1/text-to-speech/${voiceId}`

const hasVoiceSetting = stability !== undefined || similarityBoost !== undefined
const voiceSettings = hasVoiceSetting
? {
stability: stability ?? 0.5,
similarity_boost: similarityBoost ?? 0.75,
}
: undefined

const response = await fetch(endpoint, {
method: 'POST',
headers: {
Expand All @@ -67,6 +84,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
body: JSON.stringify({
text,
model_id: modelId,
...(voiceSettings ? { voice_settings: voiceSettings } : {}),
}),
signal: AbortSignal.timeout(DEFAULT_EXECUTION_TIMEOUT_MS),
})
Expand Down
40 changes: 33 additions & 7 deletions apps/sim/blocks/blocks/elevenlabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ElevenLabsBlockResponse } from '@/tools/elevenlabs/types'
export const ElevenLabsBlock: BlockConfig<ElevenLabsBlockResponse> = {
type: 'elevenlabs',
name: 'ElevenLabs',
description: 'Convert TTS using ElevenLabs',
description: 'Convert text to speech with ElevenLabs',
authMode: AuthMode.ApiKey,
longDescription: 'Integrate ElevenLabs into the workflow. Can convert text to speech.',
docsLink: 'https://docs.sim.ai/tools/elevenlabs',
Expand Down Expand Up @@ -42,6 +42,21 @@ export const ElevenLabsBlock: BlockConfig<ElevenLabsBlockResponse> = {
{ label: 'eleven_flash_v2_5', id: 'eleven_flash_v2_5' },
{ label: 'eleven_v3', id: 'eleven_v3' },
],
value: () => 'eleven_monolingual_v1',
},
{
id: 'stability',
title: 'Stability',
type: 'short-input',
placeholder: '0.0 to 1.0 (e.g., 0.5)',
mode: 'advanced',
},
{
id: 'similarityBoost',
title: 'Similarity Boost',
type: 'short-input',
placeholder: '0.0 to 1.0 (e.g., 0.75)',
mode: 'advanced',
},
{
id: 'apiKey',
Expand All @@ -57,19 +72,30 @@ export const ElevenLabsBlock: BlockConfig<ElevenLabsBlockResponse> = {
access: ['elevenlabs_tts'],
config: {
tool: () => 'elevenlabs_tts',
params: (params) => ({
apiKey: params.apiKey,
text: params.text,
voiceId: params.voiceId,
modelId: params.modelId,
}),
params: (params) => {
const parseUnitInterval = (value: unknown): number | undefined => {
if (value === undefined || value === null || value === '') return undefined
const n = Number(value)
return Number.isFinite(n) ? n : undefined
}
return {
apiKey: params.apiKey,
text: params.text,
voiceId: params.voiceId,
modelId: params.modelId,
stability: parseUnitInterval(params.stability),
similarityBoost: parseUnitInterval(params.similarityBoost),
}
},
},
},

inputs: {
text: { type: 'string', description: 'Text to convert' },
voiceId: { type: 'string', description: 'Voice identifier' },
modelId: { type: 'string', description: 'Model identifier' },
stability: { type: 'number', description: 'Voice stability 0.0-1.0' },
similarityBoost: { type: 'number', description: 'Similarity boost 0.0-1.0' },
apiKey: { type: 'string', description: 'ElevenLabs API key' },
},

Expand Down
2 changes: 2 additions & 0 deletions apps/sim/lib/api/contracts/tools/media/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export const ttsToolBodySchema = z.object({
voiceId: z.string({ error: 'Missing required parameters' }).min(1, 'Missing required parameters'),
apiKey: z.string({ error: 'Missing required parameters' }).min(1, 'Missing required parameters'),
modelId: z.string().optional().default('eleven_monolingual_v1'),
stability: z.coerce.number().min(0).max(1).optional(),
similarityBoost: z.coerce.number().min(0).max(1).optional(),
workspaceId: z.string().optional(),
workflowId: z.string().optional(),
executionId: z.string().optional(),
Expand Down
8 changes: 4 additions & 4 deletions apps/sim/tools/elevenlabs/tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ToolConfig } from '@/tools/types'
export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsResponse> = {
id: 'elevenlabs_tts',
name: 'ElevenLabs TTS',
description: 'Convert TTS using ElevenLabs voices',
description: 'Convert text to speech using ElevenLabs voices',
version: '1.0.0',

params: {
Expand Down Expand Up @@ -34,7 +34,7 @@ export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsRes
description:
'Voice stability setting from 0.0 to 1.0 (e.g., 0.5 for balanced, 0.75 for more stable). Higher values produce more consistent output',
},
similarity: {
similarityBoost: {
type: 'number',
required: false,
visibility: 'user-or-llm',
Expand All @@ -52,7 +52,7 @@ export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsRes
request: {
url: '/api/tools/tts',
method: 'POST',
headers: (params) => ({
headers: () => ({
'Content-Type': 'application/json',
}),
body: (
Expand All @@ -65,7 +65,7 @@ export const elevenLabsTtsTool: ToolConfig<ElevenLabsTtsParams, ElevenLabsTtsRes
voiceId: params.voiceId,
modelId: params.modelId || 'eleven_monolingual_v1',
stability: params.stability,
similarity: params.similarity,
similarityBoost: params.similarityBoost,
workspaceId: params._context?.workspaceId,
workflowId: params._context?.workflowId,
executionId: params._context?.executionId,
Expand Down
9 changes: 2 additions & 7 deletions apps/sim/tools/elevenlabs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface ElevenLabsTtsParams {
voiceId: string
modelId?: string
stability?: number
similarity?: number
similarityBoost?: number
}

export interface ElevenLabsTtsResponse extends ToolResponse {
Expand All @@ -17,9 +17,4 @@ export interface ElevenLabsTtsResponse extends ToolResponse {
}
}

export interface ElevenLabsBlockResponse extends ToolResponse {
output: {
audioUrl: string
audioFile?: UserFile
}
}
export type ElevenLabsBlockResponse = ElevenLabsTtsResponse
Loading