MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / processStream

Function processStream

packages/components/src/textToSpeech.ts:30–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28 return
29 }
30 const processStream = async () => {
31 try {
32 if (textToSpeechConfig) {
33 const credentialId = textToSpeechConfig.credentialId as string
34 const credentialData = await getCredentialData(credentialId ?? '', options)
35
36 switch (textToSpeechConfig.name) {
37 case TextToSpeechType.OPENAI_TTS: {
38 onStart('mp3')
39
40 const openai = new OpenAI({
41 apiKey: credentialData.openAIApiKey
42 })
43
44 const response = await openai.audio.speech.create(
45 {
46 model: 'gpt-4o-mini-tts',
47 voice: (textToSpeechConfig.voice || 'alloy') as
48 | 'alloy'
49 | 'ash'
50 | 'ballad'
51 | 'coral'
52 | 'echo'
53 | 'fable'
54 | 'nova'
55 | 'onyx'
56 | 'sage'
57 | 'shimmer',
58 input: text,
59 response_format: 'mp3'
60 },
61 {
62 signal: abortController.signal
63 }
64 )
65
66 const stream = Readable.fromWeb(response.body as unknown as ReadableStream)
67 if (!stream) {
68 throw new Error('Failed to get response stream')
69 }
70
71 await processStreamWithRateLimit(stream, onChunk, onEnd, resolve, reject, 640, 20, abortController, () => {
72 streamDestroyed = true
73 })
74 break
75 }
76
77 case TextToSpeechType.ELEVEN_LABS_TTS: {
78 onStart('mp3')
79
80 const client = new ElevenLabsClient({
81 apiKey: credentialData.elevenLabsApiKey
82 })
83
84 const response = await client.textToSpeech.stream(
85 textToSpeechConfig.voice || '21m00Tcm4TlvDq8ikWAM',
86 {
87 text: text,

Callers 1

Calls 3

getCredentialDataFunction · 0.90
createMethod · 0.45

Tested by

no test coverage detected