GeminiSalesRevenue growthAI score · PendingAI-assisted edit · no obvious prompt-injection riskn8n.io

Convert PDF Documents to AI Podcasts with Google Gemini

Upload PDF → Gemini generates conversational script → TTS synthesizes speech → Output WAV audio

Some experienceStepsWorkflowPromptTip
Who
Content creators, educators, researchers, and marketing professionals looking to repurpose written content into audio
You get
Automatically convert PDF documents into 5-7 minute natural conversational podcast audio (WAV format)
You need
n8n

Constraints

Prerequisites: n8n instance; Google Gemini API key (configured in n8n as googlePalmApi credential); HTTP custom auth (httpCustomAuth). PDF must be text-based and under 10MB. TTS calls the gemini-2.5-flash-preview-tts preview endpoint, which may be subject to Google access policies or quota limits.

What they did

Author iamthis published this workflow in the n8n template library, demonstrating how to automatically convert PDF documents into podcast audio using Gemini AI. The workflow contains 8 functional nodes: manual trigger, PDF text extraction, LLM script generation, Gemini 2.0 Flash model, TTS request preparation, HTTP TTS call, audio processing, and binary file save.

How it went

The source (template page) does not report specific runtime results or performance metrics; only functional expectations are described.

Worth knowing

The TTS endpoint is gemini-2.5-flash-preview-tts, a preview version that may be subject to Google access restrictions or quota limits, not a stable production API. PDFs are limited to text-based files under 10MB. The script length target is 750-1000 words (approximately 5-7 minutes spoken), but actual duration depends on speech rate and TTS model behavior. WAV packaging uses 24000Hz/mono/16bit PCM; the source code includes base64 decoding and WAV header generation logic. For extensions, insert text cleaning nodes before script generation, or connect output to cloud storage or notification services.

n8n workflow template

Structure checked · Not run-tested

Use “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.

Setup and test checklist

Credentials to connect

  • Google Gemini Flash 2.0 node: connect Google Gemini/PaLM API credentials.
  • 🎙️ Convert Text to Speech With Gemini node: connect Google Gemini/PaLM API credentials.
  • 🎙️ Convert Text to Speech With Gemini node: connect httpCustomAuth credentials.

Configuration to replace

  • Source template is n8n public workflow #4883 (~10 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
  • Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.

Test input and expected output

  • Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
  • Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.

Template changes

  • Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
  • No business-logic edits; verify keys, quotas and privacy compliance before use.

Template retrieved: 2026-10-24

Steps

  1. Configure credentials and voice

    Add a Google Gemini(PaLM) API account in n8n Credentials. Obtain API key at https://aistudio.google.com/. To change voice, set voiceName in a later step to Kore (professional), Aoede (conversational), or Laomedeia (energetic).

  2. Upload PDF and extract text

    Start the workflow with the Manual Trigger node and upload a PDF file. The Extract from File node extracts text using operation=pdf and binaryPropertyName=data0.

  3. Generate podcast script

    Pass the extracted text to the Basic LLM Chain node, which uses Google Gemini Flash 2.0 (models/gemini-2.0-flash-001) to generate a conversational podcast script.

    Execution prompt · Source text。Basic LLM Chain node messages.messageValues[0].message field

    =Create an engaging podcast script based on the following content. The script should be exactly 5-7 minutes when read aloud (approximately 750-1000 words).  CONTENT TO DISCUSS: {content}  STYLE: {style}  PODCAST SCRIPT REQUIREMENTS: 1. Start with: "Welcome to our AI-generated podcast. Today we're diving into..." 2. Structure: Introduction, 2-3 main discussion points, conclusion 3. Use natural conversational language 4. Include smooth transitions between topics 5. Add brief pauses with periods and commas for natural speech 6. Avoid complex punctuation that might confuse TTS 7. End with: "Thanks for listening! This has been your AI podcast." 8. Write ONLY the spoken content (no stage directions) 9. Keep sentences moderate length for clear speech 10. Use engaging storytelling techniques
  4. Prepare TTS request body

    A Code node wraps the script text into the Gemini TTS API request body, specifying responseModalities including AUDIO and setting the voice configuration.

    Execution prompt · Source text。Code node 'Prepare TTS Request' jsCode field

    const script = $input.first().json.text;
    const voiceName = $input.first().json.voiceName || "Kore";
    
    return {
      json: {
        requestBody: {
          contents: [{
            parts: [{
              text: script
            }]
          }],
          generationConfig: {
            responseModalities: ["AUDIO"],
            speechConfig: {
              voiceConfig: {
                prebuiltVoiceConfig: {
                  voiceName: voiceName
                }
              }
            }
          }
        }
      }
    };
  5. Call Gemini TTS to generate speech

    The HTTP Request node sends a POST request to https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-tts:generateContent, authenticated with the googlePalmApi credential, using the requestBody from the previous step.

  6. Process audio response and save WAV

    A Code node parses the returned base64 audio data, decodes it to PCM16 bytes, adds a WAV header (24000Hz, mono, 16bit), and the Write Binary File node saves it as a .wav file.

    Execution prompt · Source text。Code node 'Process Audio Response' jsCode field

    const response = $input.all()[0].json;
    
    console.log('=== GEMINI TTS DEBUG ===');
    console.log('Response status:', response.candidates?.[0]?.finishReason);
    
    if (response.candidates?.[0]?.finishReason === 'STOP') {
      try {
        // Get the base64 audio data
        const base64AudioData = response.candidates[0].content.parts[0].inlineData.data;
        const mimeType = response.candidates[0].content.parts[0].inlineData.mimeType;
        
        console.log('Audio data length:', base64AudioData.length);
        console.log('Mime type:', mimeType);
        
        // CRITICAL FIX: Properly decode base64 to actual audio bytes
        const actualAudioBytes = Buffer.from(base64AudioData, 'base64');
        
        console.log('Decoded audio size:', actualAudioBytes.length);
        
        // Create WAV file with proper PCM16 format
        const sampleRate = 24000;
        const channels = 1;
        const bitsPerSample = 16;
        
        // Create WAV header
        const wavHeader = createWavHeader(actualAudioBytes.length, sampleRate, channels, bitsPerSample);
        const wavFile = Buffer.concat([wavHeader, actualAudioBytes]);
        
        const filename = `tts_fixed_${Date.now()}.wav`;
        
        return {
          json: {
            success: true,
            filename: filename,
            audioSize: wavFile.length,
            audioSizeMB: (wavFile.length / 1024 / 1024).toFixed(2),
            originalBase64Length: base64AudioData.length,
            decodedAudioLength: actualAudioBytes.length
          },
          binary: {
            audio: {
              data: wavFile,
              mimeType: 'audio/wav',
              fileName: filename
            }
          }
        };
        
      } catch (error) {
        return {
          json: {
            success: false,
            error: error.message,
            step: 'audio_processing'
          }
        };
      }
    } else {
      return {
        json: {
          success: false,
          error: 'TTS generation failed',
          finishReason: response.candidates?.[0]?.finishReason || 'unknown',
          response: response
        }
      };
    }
    
    // Helper function to create WAV header
    function createWavHeader(dataLength, sampleRate, channels, bitsPerSample) {
      const byteRate = sampleRate * channels * bitsPerSample / 8;
      const blockAlign = channels * bitsPerSample / 8;
      const header = Buffer.alloc(44);
      
      // "RIFF" chunk descriptor
      header.write('RIFF', 0);
      header.writeUInt32LE(36 + dataLength, 4);
      header.write('WAVE', 8);
      
      // "fmt " sub-chunk
      header.write('fmt ', 12);
      header.writeUInt32LE(16, 16); // Sub-chunk size
      header.writeUInt16LE(1, 20);  // Audio format (PCM)
      header.writeUInt16LE(channels, 22);
      header.writeUInt32LE(sampleRate, 24);
      header.writeUInt32LE(byteRate, 28);
      header.writeUInt16LE(blockAlign, 32);
      header.writeUInt16LE(bitsPerSample, 34);
      
      // "data" sub-chunk
      header.write('data', 36);
      header.writeUInt32LE(dataLength, 40);
      
      return header;
    }

Prompt you can copy

Setup guidance · Editorial suggestion。Hand to setup assistant to confirm inputs, permissions, and node configuration

This block is the prompt. Ads are never placed here.

You are reproducing n8n template #4883: converting PDF to AI podcast. First confirm that the Google Gemini(PaLM) API credential is configured, and prepare a text-based PDF under 10MB. The core pipeline is: extract PDF text → Gemini 2.0 Flash generates a 750-1000 word conversational script → package TTS request → call gemini-2.5-flash-preview-tts → decode base64 audio and wrap as WAV → save file. To adjust style, edit the message content in the Generate Podcast Script node; to change voice, modify the voiceName variable in Prepare TTS Request.

Test with a single PDF first and check the n8n execution log for GEMINI TTS DEBUG output. If finishReason is not STOP, troubleshoot API quota or model access permissions.

Source

Convert PDF documents to AI podcasts with Google Gemini and text-to-speech · iamthis · n8n.io · 2025-06-11

Comments & feedback

Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.

Loading…

    Related