{"id":"ebRgW7PbvS4Pg082","meta":{"instanceId":"b91e510ebae4127f953fd2f5f8d40d58ca1e71c746d4500c12ae86aad04c1502"},"name":"GPT-4o Powered Chinese Text Translation with Audio Generation","tags":[],"nodes":[{"id":"f88a1299-a2b6-4360-89ad-7d9280c3f1ac","name":"Webhook Trigger","type":"n8n-nodes-base.webhook","position":[-2528,-64],"webhookId":"fb4b14da-5c79-40d8-bfcd-406dd2f9fd34","parameters":{"path":"chinese-to-speech","options":{},"httpMethod":"POST","responseMode":"lastNode"},"typeVersion":2.1},{"id":"e8c925a0-0571-4bf5-9519-556eac2c7e7a","name":"Workflow Configuration","type":"n8n-nodes-base.set","position":[-2304,-64],"parameters":{"options":{},"assignments":{"assignments":[{"id":"id-1","name":"targetLanguages","type":"array","value":"[\"English\", \"Spanish\", \"French\", \"German\", \"Japanese\"]"},{"id":"id-2","name":"elevenLabsVoiceId","type":"string","value":"<__PLACEHOLDER_VALUE__ElevenLabs Voice ID__>"},{"id":"id-3","name":"elevenLabsModelId","type":"string","value":"eleven_multilingual_v2"},{"id":"id-4","name":"stability","type":"number","value":0.5},{"id":"id-5","name":"similarityBoost","type":"number","value":0.75},{"id":"id-6","name":"style","type":"number","value":0},{"id":"id-7","name":"speakerBoost","type":"boolean","value":true},{"id":"id-8","name":"qualityThreshold","type":"number","value":7},{"id":"id-9","name":"maxRetries","type":"number","value":2}]},"includeOtherFields":true},"typeVersion":3.4},{"id":"c6c362dd-db6c-407f-841d-663213ddae9b","name":"Validate Chinese Text","type":"n8n-nodes-base.code","position":[-2080,-64],"parameters":{"jsCode":"const inputText = $input.first().json.body?.text || $input.first().json.text || '';\n\n// Check if text is provided\nif (!inputText || inputText.trim() === '') {\n  return [{\n    json: {\n      isValid: false,\n      error: 'No text provided',\n      text: inputText\n    }\n  }];\n}\n\n// Check for Chinese characters (Unicode ranges for Chinese)\nconst chineseRegex = /[\\u4e00-\\u9fff\\u3400-\\u4dbf\\u{20000}-\\u{2a6df}\\u{2a700}-\\u{2b73f}\\u{2b740}-\\u{2b81f}\\u{2b820}-\\u{2ceaf}\\uf900-\\ufaff\\u3300-\\u33ff\\ufe30-\\ufe4f\\uf900-\\ufaff\\u{2f800}-\\u{2fa1f}]/u;\n\nconst hasChinese = chineseRegex.test(inputText);\n\nif (!hasChinese) {\n  return [{\n    json: {\n      isValid: false,\n      error: 'No Chinese characters detected in the input text',\n      text: inputText\n    }\n  }];\n}\n\n// Validation passed\nreturn [{\n  json: {\n    isValid: true,\n    text: inputText,\n    characterCount: inputText.length\n  }\n}];"},"typeVersion":2},{"id":"4774a867-4c1d-49d2-8fef-f1706df7a26a","name":"Translation Agent","type":"@n8n/n8n-nodes-langchain.agent","position":[-1840,-32],"parameters":{"text":"={{ $json.text }}","options":{"systemMessage":"=You are a professional multilingual translator specializing in Chinese to multiple languages.\n\nYour task is to translate the provided Chinese text into multiple target languages while:\n1. Preserving the original intent, tone, and nuance\n2. Maintaining cultural context and idiomatic expressions\n3. Ensuring natural, fluent translations that sound native in each target language\n4. Keeping formatting and structure consistent\n\nTranslate the Chinese text into the following languages: {{ $('Workflow Configuration').first().json.targetLanguages.join(', ') }}\n\nReturn the translations in the exact JSON schema format specified by the output parser."},"promptType":"define","hasOutputParser":true},"typeVersion":3.1},{"id":"bccba84d-72d4-44cf-9881-bda7093192d5","name":"OpenAI Chat Model","type":"@n8n/n8n-nodes-langchain.lmChatOpenAi","position":[-1824,176],"parameters":{"model":{"__rl":true,"mode":"id","value":"gpt-4o"},"options":{},"builtInTools":{}},"credentials":{"openAiApi":{"id":"mv2ECvRtbAK63G2g","name":"OpenAi account"}},"typeVersion":1.3},{"id":"ed1f5b34-4f55-4b67-a255-f7dc2bdc5e95","name":"Structured Output Parser","type":"@n8n/n8n-nodes-langchain.outputParserStructured","position":[-1632,160],"parameters":{"schemaType":"manual","inputSchema":"{\n  \"type\": \"object\",\n  \"properties\": {\n    \"translations\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"language\": {\n            \"type\": \"string\",\n            \"description\": \"Target language name\"\n          },\n          \"text\": {\n            \"type\": \"string\",\n            \"description\": \"Translated text\"\n          }\n        },\n        \"required\": [\"language\", \"text\"]\n      }\n    }\n  },\n  \"required\": [\"translations\"]\n}"},"typeVersion":1.3},{"id":"188aadbe-8216-4165-a091-f437f230583b","name":"Split Translations","type":"n8n-nodes-base.code","position":[-1488,0],"parameters":{"jsCode":"const translations = $input.first().json.output?.translations || [];\n\nif (!translations || translations.length === 0) {\n  throw new Error('No translations found in the AI output');\n}\n\n// Create separate items for each translation\nconst items = translations.map(translation => ({\n  json: {\n    language: translation.language,\n    text: translation.text,\n    originalText: $input.first().json.text\n  }\n}));\n\nreturn items;"},"typeVersion":2},{"id":"a2920761-6e13-4ba6-ada4-5bd5f2cb5cf4","name":"Generate Speech with ElevenLabs","type":"n8n-nodes-base.httpRequest","position":[-1264,0],"parameters":{"url":"=https://api.elevenlabs.io/v1/text-to-speech/{{ $('Workflow Configuration').first().json.elevenLabsVoiceId }}","method":"POST","options":{"response":{"response":{"responseFormat":"file","outputPropertyName":"audio"}}},"jsonBody":"={\n  \"text\": {{ $json.text }},\n  \"model_id\": {{ $('Workflow Configuration').first().json.elevenLabsModelId }},\n  \"voice_settings\": {\n    \"stability\": {{ $('Workflow Configuration').first().json.stability }},\n    \"similarity_boost\": {{ $('Workflow Configuration').first().json.similarityBoost }},\n    \"style\": {{ $('Workflow Configuration').first().json.style }},\n    \"use_speaker_boost\": {{ $('Workflow Configuration').first().json.speakerBoost }}\n  }\n}","sendBody":true,"sendHeaders":true,"specifyBody":"json","authentication":"predefinedCredentialType","headerParameters":{"parameters":[{"name":"Content-Type","value":"application/json"}]},"nodeCredentialType":"elevenLabsApi"},"typeVersion":4.3},{"id":"fa1f0960-0c39-41aa-b794-cc6c963658ae","name":"Format Audio Response","type":"n8n-nodes-base.set","position":[-1040,0],"parameters":{"options":{"stripBinary":false},"assignments":{"assignments":[{"id":"id-1","name":"language","type":"string","value":"={{ $json.language }}"},{"id":"id-2","name":"fileName","type":"string","value":"={{ $json.language.toLowerCase().replace(/ /g, '_') }}_audio.mp3"},{"id":"id-3","name":"mimeType","type":"string","value":"audio/mpeg"},{"id":"id-4","name":"originalText","type":"string","value":"={{ $json.originalText }}"}]},"includeOtherFields":true},"typeVersion":3.4},{"id":"1faa94a2-9051-4aea-a578-88f383cd45ac","name":"Return Audio Files","type":"n8n-nodes-base.respondToWebhook","position":[-240,112],"parameters":{"options":{},"respondWith":"allIncomingItems"},"typeVersion":1.5},{"id":"3caa4a6b-79b3-464e-b4d9-0ca867785967","name":"Quality Review Agent","type":"@n8n/n8n-nodes-langchain.agent","position":[-816,0],"parameters":{"text":"=Original Chinese: {{ $json.originalText }}\nTranslated {{ $json.language }}: {{ $json.text }}","options":{"systemMessage":"You are a translation quality assurance specialist.\n\nYour task is to evaluate the quality of a translation from Chinese to another language. Assess the translation based on:\n\n1. Accuracy: Does it convey the original meaning correctly?\n2. Fluency: Does it sound natural in the target language?\n3. Tone preservation: Does it maintain the same tone and style as the original?\n4. Cultural appropriateness: Are idioms and cultural references properly adapted?\n5. Completeness: Is all information from the original present?\n\nProvide a quality score from 1-10 (where 10 is perfect) and brief feedback.\n\nReturn your assessment in the exact JSON schema format specified by the output parser."},"promptType":"define","hasOutputParser":true},"typeVersion":3.1},{"id":"710c35e4-fcbe-4c8c-bdfe-6c6a493da42d","name":"OpenAI Chat Model1","type":"@n8n/n8n-nodes-langchain.lmChatOpenAi","position":[-832,176],"parameters":{"model":{"__rl":true,"mode":"id","value":"gpt-4o"},"options":{},"builtInTools":{}},"credentials":{"openAiApi":{"id":"mv2ECvRtbAK63G2g","name":"OpenAi account"}},"typeVersion":1.3},{"id":"7cfc9501-bb6a-4de9-bc3d-7bc40cae0ddc","name":"Structured Output Parser1","type":"@n8n/n8n-nodes-langchain.outputParserStructured","position":[-624,176],"parameters":{"schemaType":"manual","inputSchema":"{\n  \"type\": \"object\",\n  \"properties\": {\n    \"qualityScore\": {\n      \"type\": \"number\",\n      \"description\": \"Quality score from 1-10\"\n    },\n    \"feedback\": {\n      \"type\": \"string\",\n      \"description\": \"Brief quality assessment feedback\"\n    },\n    \"passesQuality\": {\n      \"type\": \"boolean\",\n      \"description\": \"Whether translation meets quality threshold\"\n    }\n  },\n  \"required\": [\"qualityScore\", \"feedback\", \"passesQuality\"]\n}"},"typeVersion":1.3},{"id":"f79719a7-8b9b-482e-b5c9-1827ad98e238","name":"Check Quality Score","type":"n8n-nodes-base.if","position":[-464,112],"parameters":{"options":{},"conditions":{"options":{"leftValue":"","caseSensitive":false,"typeValidation":"loose"},"combinator":"and","conditions":[{"id":"id-1","operator":{"type":"boolean","operation":"true"},"leftValue":"={{ $json.output.passesQuality }}"}]}},"typeVersion":2.3},{"id":"0ee6418e-77da-49ff-ad47-ff13f80de3bc","name":"Sticky Note","type":"n8n-nodes-base.stickyNote","position":[-1376,-560],"parameters":{"color":4,"width":624,"height":304,"content":"## Prerequisites\nActive accounts: OpenAI API access, ElevenLabs subscription.\n## Use Cases\nChinese language learning apps, international marketing content localization\n## Customization\nAdd additional target languages, modify voice characteristics and speaking rates\n## Benefits\nAutomates 95% of translation workflow, delivers publication-ready audio in minutes"},"typeVersion":1},{"id":"a653e6c7-6ecc-4df7-8ff5-4157f346ee47","name":"Sticky Note1","type":"n8n-nodes-base.stickyNote","position":[-1920,-480],"parameters":{"width":480,"height":240,"content":"## Setup Steps\n1. Obtain OpenAI API key and configure in \"Translation Agent\"\n2. Set up ElevenLabs account, generate API key\n3. Configure webhook URL and update in source applications to trigger workflow\n4. Customize target languages and voice settings in translation and ElevenLabs nodes\n5. Adjust quality thresholds in \"Check Quality Score\" \n6. Update output webhook endpoint in \"Return Audio Files\" node"},"typeVersion":1},{"id":"2401f197-df5f-43a8-9a8a-bbe06b4980d5","name":"Sticky Note2","type":"n8n-nodes-base.stickyNote","position":[-2576,-512],"parameters":{"width":624,"height":288,"content":"## How It Works\nThis workflow provides automated Chinese text translation with high-quality audio synthesis for language learning platforms, content creators, and international communication teams. It addresses the challenge of converting Chinese text into accurate multilingual translations with natural-sounding voiceovers. The system receives Chinese text via webhook, validates input formatting, and processes it through an AI translation agent that generates multiple language versions. Each translation is converted to speech using ElevenLabs' neural voice models, then formatted into professional audio responses. A quality review agent evaluates translation accuracy, cultural appropriateness, and audio clarity against predefined criteria. High-scoring outputs are returned via webhook for immediate use, while low-quality results trigger review processes, ensuring consistent delivery of publication-ready multilingual audio content."},"typeVersion":1},{"id":"0d8319f9-8e2f-4e4a-9cd8-227773fa4125","name":"Sticky Note3","type":"n8n-nodes-base.stickyNote","position":[-1296,-160],"parameters":{"color":7,"width":416,"height":544,"content":"## Neural Text-to-Speech Synthesis\n**What:** ElevenLabs generates natural speech from translated text\n**Why:** Creates professional voiceovers with accurate pronunciation and natural intonation"},"typeVersion":1},{"id":"fc1bd92c-a3e1-41a7-82c5-ca26acee35cd","name":"Sticky Note4","type":"n8n-nodes-base.stickyNote","position":[-1920,-160],"parameters":{"color":7,"width":608,"height":528,"content":"## Context-Aware Multilingual Translation\n**What:** Translation agent converts Chinese to target languages with context awareness\n**Why:** Produces culturally appropriate translations while preserving original meaning and nuance"},"typeVersion":1},{"id":"c4f66712-3d3e-492d-8117-df66f59e5d70","name":"Sticky Note5","type":"n8n-nodes-base.stickyNote","position":[-2592,-176],"parameters":{"color":7,"width":656,"height":544,"content":"## Input Ingestion & Configuration\n**What:** Webhook receives Chinese text input with configuration parameters\n**Why:** Initiates automated processing without manual intervention from connected applications"},"typeVersion":1},{"id":"3aae914d-4d20-4086-ae31-b59270361a17","name":"Sticky Note6","type":"n8n-nodes-base.stickyNote","position":[-864,-160],"parameters":{"color":7,"width":784,"height":544,"content":"## Quality Scoring & Output Control\n**What:** Quality agent scores translations on linguistic accuracy and audio fidelity\n**Why:** Maintains output standards and filters unsuitable content before delivery"},"typeVersion":1}],"active":false,"pinData":{},"settings":{"availableInMCP":false,"executionOrder":"v1"},"versionId":"03f4e59c-5718-47d9-bc41-865ee05fb337","connections":{"Webhook Trigger":{"main":[[{"node":"Workflow Configuration","type":"main","index":0}]]},"OpenAI Chat Model":{"ai_languageModel":[[{"node":"Translation Agent","type":"ai_languageModel","index":0}]]},"Translation Agent":{"main":[[{"node":"Split Translations","type":"main","index":0}]]},"OpenAI Chat Model1":{"ai_languageModel":[[{"node":"Quality Review Agent","type":"ai_languageModel","index":0}]]},"Split Translations":{"main":[[{"node":"Generate Speech with ElevenLabs","type":"main","index":0}]]},"Check Quality Score":{"main":[[{"node":"Return Audio Files","type":"main","index":0}],[{"node":"Translation Agent","type":"main","index":0}]]},"Quality Review Agent":{"main":[[{"node":"Check Quality Score","type":"main","index":0}]]},"Format Audio Response":{"main":[[{"node":"Quality Review Agent","type":"main","index":0}]]},"Validate Chinese Text":{"main":[[{"node":"Translation Agent","type":"main","index":0}]]},"Workflow Configuration":{"main":[[{"node":"Validate Chinese Text","type":"main","index":0}]]},"Structured Output Parser":{"ai_outputParser":[[{"node":"Translation Agent","type":"ai_outputParser","index":0}]]},"Structured Output Parser1":{"ai_outputParser":[[{"node":"Quality Review Agent","type":"ai_outputParser","index":0}]]},"Generate Speech with ElevenLabs":{"main":[[{"node":"Format Audio Response","type":"main","index":0}]]}}}