MCPcopy Index your code
hub / github.com/simstudioai/sim / synthesizeWithOpenAi

Function synthesizeWithOpenAi

apps/sim/app/api/tools/tts/unified/route.ts:327–365  ·  view source on GitHub ↗
(
  params: OpenAiTtsParams
)

Source from the content-addressed store, hash-verified

325})
326
327async function synthesizeWithOpenAi(
328 params: OpenAiTtsParams
329): Promise<{ audioBuffer: Buffer; format: string; mimeType: string }> {
330 const { text, apiKey, model = 'tts-1', responseFormat = 'mp3', speed = 1.0 } = params
331 const voice = (params.voice || 'alloy') as OpenAiTtsParams['voice']
332
333 const response = await fetch('https://api.openai.com/v1/audio/speech', {
334 method: 'POST',
335 headers: {
336 Authorization: `Bearer ${apiKey}`,
337 'Content-Type': 'application/json',
338 },
339 body: JSON.stringify({
340 model,
341 voice,
342 input: text,
343 response_format: responseFormat,
344 speed: Math.max(0.25, Math.min(4.0, speed)),
345 }),
346 })
347
348 if (!response.ok) {
349 const error = await readTtsErrorJson(response, 'OpenAI TTS error response')
350 const errorMessage = getTtsErrorMessage(error, response.statusText)
351 throw new Error(`OpenAI TTS API error: ${errorMessage}`)
352 }
353
354 const audioBuffer = await readResponseToBufferWithLimit(response, {
355 maxBytes: MAX_TTS_AUDIO_BYTES,
356 label: 'OpenAI TTS audio response',
357 })
358 const mimeType = getMimeType(responseFormat)
359
360 return {
361 audioBuffer,
362 format: responseFormat,
363 mimeType,
364 }
365}
366
367async function synthesizeWithDeepgram(
368 params: DeepgramTtsParams

Callers 1

route.tsFile · 0.85

Calls 4

getMimeTypeFunction · 0.90
readTtsErrorJsonFunction · 0.85
getTtsErrorMessageFunction · 0.85

Tested by

no test coverage detected