MCPcopy Create free account
hub / github.com/simstudioai/sim / synthesizeWithCartesia

Function synthesizeWithCartesia

apps/sim/app/api/tools/tts/unified/route.ts:489–588  ·  view source on GitHub ↗
(
  params: Partial<CartesiaTtsParams>
)

Source from the content-addressed store, hash-verified

487}
488
489async function synthesizeWithCartesia(
490 params: Partial<CartesiaTtsParams>
491): Promise<{ audioBuffer: Buffer; format: string; mimeType: string }> {
492 const {
493 text,
494 apiKey,
495 modelId = 'sonic-3',
496 voice,
497 language = 'en',
498 outputFormat,
499 speed,
500 emotion,
501 } = params
502
503 if (!text || !apiKey) {
504 throw new Error('text and apiKey are required for Cartesia')
505 }
506
507 const requestBody: Record<string, unknown> = {
508 model_id: modelId,
509 transcript: text,
510 language,
511 }
512
513 if (voice) {
514 requestBody.voice = {
515 mode: 'id',
516 id: voice,
517 }
518 }
519
520 const generationConfig: Record<string, unknown> = {}
521 if (speed !== undefined) generationConfig.speed = speed
522 if (emotion !== undefined) generationConfig.emotion = emotion
523 if (Object.keys(generationConfig).length > 0) {
524 requestBody.generation_config = generationConfig
525 }
526
527 if (outputFormat && typeof outputFormat === 'object') {
528 requestBody.output_format = outputFormat
529 }
530
531 if (!requestBody.output_format) {
532 requestBody.output_format = {
533 container: 'wav',
534 encoding: 'pcm_s16le',
535 sample_rate: 24000,
536 }
537 }
538
539 logger.info('Cartesia API request:', {
540 model_id: requestBody.model_id,
541 has_voice: !!requestBody.voice,
542 language: requestBody.language,
543 output_format: requestBody.output_format,
544 has_generation_config: !!requestBody.generation_config,
545 })
546

Callers 1

route.tsFile · 0.85

Calls 6

getMimeTypeFunction · 0.90
readTtsErrorJsonFunction · 0.85
getTtsErrorMessageFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected