WebToSpeech

For publishers · Add an audio player to a Next.js blog

Add an audio player to your Next.js blog.

Verify your domain with Next.js Metadata, drop a tiny <AudioPlayer /> component into your post route, and turn every MDX or headless CMS article into audio.

Works with Next.js App Router, Pages Router, MDX, Sanity, Contentful, and static exports. Requires the Publisher plan.

  1. Step 1

    Add your domain in WebtoSpeech

    Open Settings → Sites, add your production domain, and copy your verification token and ws_ site key.

  2. Step 2

    Verify with Next.js Metadata (or DNS)

    Add the verification token to your root app/layout.tsx metadata object (or create a DNS TXT record), deploy, and press Verify in WebtoSpeech.

    app/layout.tsx

    export const metadata = {
      other: {
        'webtospeech-verification': 'your_verification_code',
      },
    };
  3. Step 3

    Render the player on your post page

    Create a small component using next/script with strategy="afterInteractive" and render it above your article body in app/blog/[slug]/page.tsx.

    components/AudioPlayer.tsx

    import Script from 'next/script';
    
    export function AudioPlayer() {
      return (
        <>
          <div data-webtospeech />
          <Script
            src="https://webtospeech.app/embed.js"
            data-site="ws_your_site_key"
            strategy="afterInteractive"
          />
        </>
      );
    }
  4. Step 4

    Deploy and test on your production domain

    Open any published post on your verified domain and click play. The first listener triggers generation and starts listening within seconds; everyone after gets the finished MP3.

    Include alternates.canonical and openGraph.modifiedTime in generateMetadata() so edited posts re-read automatically.

Using Content-Security-Policy headers in next.config?

If your Next.js app sends a strict Content-Security-Policy header, allow WebtoSpeech in script-src and frame-src so the embed script and iframe load cleanly.

CSP directives

script-src 'self' https://webtospeech.app;
frame-src 'self' https://webtospeech.app;

Good to know on Next.js

Server-render the article text

WebtoSpeech fetches the page HTML to extract your article. Server Components, SSG, and ISR work best; avoid hiding the article body behind client-only loading spinners.

Zero cookies or consent popups

The iframe runs stateless with no cookies or analytics scripts, keeping your Next.js privacy setup simple.

Headless CMS updates stay in sync

Output the post’s updated timestamp in <meta property="article:modified_time"> via generateMetadata() so edits from Sanity, Contentful, or Markdown trigger fresh audio.

Auto-publish a podcast from your Next.js RSS route

If you serve /rss.xml from a Route Handler, connect it in Settings → Sites → Feed and podcast to distribute every post as a podcast automatically.

See everything else the player does

Questions

Does WebtoSpeech work with Next.js App Router and MDX?
Yes. Server-rendered MDX routes extract cleanly and work with both the on-page embed player and automatic RSS-to-podcast feeds.
What happens when a reader navigates between posts with next/link?
Ensure your post page mounts a fresh player element per slug (for example with key={slug}) or uses standard anchors for long-form articles so each post loads its own canonical URL.
Does it work on Vercel preview URLs?
Embeds only run on domains verified in Settings → Sites, protecting your allowance from unauthorized framing on external hosts.

Publisher plan

$29 a month. Unlimited sites.

200 hours of audio a month, every Studio and standard voice, cookie-free embeds, RSS-to-podcast feeds, and play counts.