Templates / Generate audio from text scripts using self-hosted Bark model and Google Drive

Generate audio from text scripts using self-hosted Bark model and Google Drive

Ready for 3.0

by Flavien · 917 views · created 2025-05-20 · Content Creation, Multimodal AI

Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.

Nodes used (8)

Google Drive

What it does

Audio Generator – Documentation 🎯 Purpose: Generate audio files from text scripts stored in Google Drive. 🔁 Flow: 1. Receive repo IDs. 2. Fetch text scripts. 3. Generate .wav files using local Bark model. 4. Upload back to Drive. 📦 Dependencies: - Python script: /scripts/generatevoice.py - Bark (voice generation system) - n8n instance with access to local shell - Google Drive OAuth2 credentials ✏️ Notes: - Script filenames must end with .txt - Only works with plain text - No external API used = 100% free 📦 /scripts/generatevoice.py: python import sys import torch import numpy import re from bark import SAMPLERATE, generateaudio, preloadmodels from scipy.io.wavfile import write as writewav Patch to allow numpy.core.multiarray.scalar during loading torch.serialization.addsafeglobals(numpy.core.multiarray.scalar) Monkey patch torch.load to force weightsonly=False originaltorchload = torch.load def patchedtorchload(f, args, kwargs): if 'weightsonly' not in kwargs: kwargs'weightsonly' = False return originaltorchload(f, args, kwargs) torch.load = patchedtorchload Preload Bark models preloadmodels() def splittext(text, maxlen=300): Split on punctuation to avoid mid-sentence cuts sentences = re.split(r'(?<=.?!)\s+', text) chunks = current = "" for sentence in sentences: if len(current) + len(sentence) < maxlen: current += sentence + " " else: chunks.append(current.strip()) current = sentence + " " if current: chunks.append(current.strip()) return chunks Input text file and output path inputtextpath = sys.argv1 outputwavpath = sys.argv2 with open(inputtextpath, 'r', encoding='utf-8') as f: fulltext = f.read() voicepreset = "v2/enspeaker7" chunks = splittext(fulltext) Generate and concatenate audio chunks audioarrays = for chunk in chunks: print(f"Generating audio for chunk: {chunk:50}...") audio = generateaudio(chunk, historyprompt=voicepreset) audioarrays.append(audio) Merge all audio chunks finalaudio = numpy.concatenate(audioarrays) Write final .wav file writewav(outputwavpath, SAMPLERATE, finalaudio) print(f"Full audio generated at: {outputwavpath}")

View the original on n8n.io → Check your own copy

Get the weekly “what broke” email

New templates, newly broken ones, and n8n release changes. One short email a week.

Form not loading? Subscribe here.