{
  "id": "oGZBcAWL45us8pwq",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Audio generator",
  "tags": [],
  "nodes": [
    {
      "id": "90a47429-775e-43d5-acfb-b7f72f382894",
      "name": "Start: External Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        300,
        80
      ],
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "id_repo_audio"
            },
            {
              "name": "id_repo_script"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "415fa2d1-532f-4a46-8634-8099f820816e",
      "name": "Start: Manual Test",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        200,
        440
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "627fad9c-407d-496a-b0ff-5b58055c666c",
      "name": "Test Values",
      "type": "n8n-nodes-base.set",
      "position": [
        420,
        440
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "id_repo_audio",
              "type": "string",
              "value": "1wrnIskVWQJRAvKs04bhXavgDv2FokabG"
            },
            {
              "name": "id_repo_script",
              "type": "string",
              "value": "12tIJJuO_DfwJbtOuO72mpk2_3s9O4xZc"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e0efd839-dc9e-4d0b-b602-a6ead9e8d679",
      "name": "Aggregate Inputs",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        560,
        80
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "id_repo_audio"
            },
            {
              "fieldToAggregate": "id_repo_script"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fea5d345-4d72-431d-bf9b-4165b9b6f605",
      "name": "Get Scripts",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        820,
        80
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $('Aggregate Inputs').item.json.id_repo_script[0] }}"
          }
        },
        "options": {},
        "resource": "fileFolder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "0fccfd48-ca42-45ea-9eb0-75f49f4572f6",
      "name": "Loop Scripts",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1140,
        80
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ba6ea0f9-d1d7-4f22-a817-764335132a1c",
      "name": "Download Script",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1500,
        100
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "f0f95702-4636-4810-9e42-4b3af5c13d9a",
      "name": "Save Script",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        1780,
        100
      ],
      "parameters": {
        "options": {},
        "fileName": "/tmp/script.txt",
        "operation": "write",
        "dataPropertyName": "=data"
      },
      "typeVersion": 1
    },
    {
      "id": "63cb6eb3-6693-4b34-84c9-4f6b39872752",
      "name": "Generate WAV",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        2000,
        100
      ],
      "parameters": {
        "command": "=/opt/venv/bin/python /scripts/generate_voice.py /tmp/script.txt /tmp/output_{{ $json.name.replace(/\\.txt$/, '') }}.wav"
      },
      "typeVersion": 1
    },
    {
      "id": "0d29f755-5ed2-4005-9eed-acbc9c8ff8d1",
      "name": "Read Audio",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        2220,
        100
      ],
      "parameters": {
        "options": {},
        "fileSelector": "=/tmp/output_{{ $('Loop Scripts').item.json.name.replace(/\\.txt$/, '.wav') }}"
      },
      "typeVersion": 1
    },
    {
      "id": "394dead9-49af-4187-a589-1ff751e998f8",
      "name": "Upload Audio",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2440,
        100
      ],
      "parameters": {
        "name": "={{ $json.fileName }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Aggregate Inputs').item.json.id_repo_audio[0] }}"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "95f7b0e0-980f-4beb-adac-197b4b50a84f",
      "name": "\ud83d\udcdd Workflow Instructions",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        260
      ],
      "parameters": {
        "width": 600,
        "height": 400,
        "content": "## Audio Generation Workflow\n\n1. This workflow automates the conversion of text scripts into audio files using a Python voice synthesis script.\n2. It retrieves scripts from Google Drive, generates audio with Bark-style narration, and reuploads the result.\n3. Script filenames must be .txt. Only clean plain text is supported.\n\n### Inputs:\n- id_repo_script: Google Drive folder with scripts\n- id_repo_audio: Google Drive folder to upload audio files\n\nMake sure the Python script is deployed at /scripts/generate_voice.py and has access to Bark or other required models."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "30318ca0-c87d-43db-8b74-3ec1127e1061",
  "connections": {
    "Read Audio": {
      "main": [
        [
          {
            "node": "Upload Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Scripts": {
      "main": [
        [
          {
            "node": "Loop Scripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Script": {
      "main": [
        [
          {
            "node": "Generate WAV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Test Values": {
      "main": [
        [
          {
            "node": "Aggregate Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate WAV": {
      "main": [
        [
          {
            "node": "Read Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Scripts": {
      "main": [
        [],
        [
          {
            "node": "Download Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Audio": {
      "main": [
        [
          {
            "node": "Loop Scripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Script": {
      "main": [
        [
          {
            "node": "Save Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Inputs": {
      "main": [
        [
          {
            "node": "Get Scripts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start: Manual Test": {
      "main": [
        [
          {
            "node": "Test Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start: External Trigger": {
      "main": [
        [
          {
            "node": "Aggregate Inputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}