{
  "name": "Vorlux AI | VTuber TTS Pipeline",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "vtuber-tts",
        "options": { "responseMode": "lastNode" }
      },
      "id": "webhook-trigger",
      "name": "TTS Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $input.first().json.body || $input.first().json;\nconst text = data.text || data.message || '';\nconst character = data.character || 'myla';\nconst voiceProfiles = {\n  myla: { voice: 'nova', speed: 1.0, pitch: 1.1, language: 'en' },\n  aria: { voice: 'alloy', speed: 0.95, pitch: 1.0, language: 'en' },\n  blaze: { voice: 'echo', speed: 1.1, pitch: 0.9, language: 'en' },\n  kira: { voice: 'shimmer', speed: 0.9, pitch: 1.05, language: 'en' },\n  trix: { voice: 'fable', speed: 1.15, pitch: 1.2, language: 'en' }\n};\nconst profile = voiceProfiles[character] || voiceProfiles.myla;\nreturn [{ json: { text, character, profile, emotion: data.emotion || 'neutral', priority: data.priority || 'normal' } }];"
      },
      "id": "resolve-voice",
      "name": "Resolve Voice Profile",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/tts/generate",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.text, voice: $json.profile.voice, speed: $json.profile.speed, pitch: $json.profile.pitch }) }}",
        "options": { "timeout": 30000 }
      },
      "id": "generate-tts",
      "name": "Generate TTS Audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/vtuber/emotion",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ character: $('Resolve Voice Profile').first().json.character, emotion: $('Resolve Voice Profile').first().json.emotion, speaking: true }) }}",
        "options": { "timeout": 5000 }
      },
      "id": "set-speaking",
      "name": "Set Speaking Expression",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 200]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/tts/speak",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ audioUrl: $('Generate TTS Audio').first().json.url || $('Generate TTS Audio').first().json.audioUrl, character: $('Resolve Voice Profile').first().json.character }) }}",
        "options": { "timeout": 30000 }
      },
      "id": "play-audio",
      "name": "Play Audio Stream",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 400]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{ json: { success: true, character: $('Resolve Voice Profile').first().json.character, textLength: $('Resolve Voice Profile').first().json.text.length } }];"
      },
      "id": "response",
      "name": "Build Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1180, 300]
    }
  ],
  "connections": {
    "TTS Webhook": { "main": [[{ "node": "Resolve Voice Profile", "type": "main", "index": 0 }]] },
    "Resolve Voice Profile": { "main": [[{ "node": "Generate TTS Audio", "type": "main", "index": 0 }]] },
    "Generate TTS Audio": { "main": [[{ "node": "Set Speaking Expression", "type": "main", "index": 0 }, { "node": "Play Audio Stream", "type": "main", "index": 0 }]] },
    "Set Speaking Expression": { "main": [[{ "node": "Build Response", "type": "main", "index": 0 }]] },
    "Play Audio Stream": { "main": [[{ "node": "Build Response", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
