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.
For publishers · Add an audio player to a 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.
Step 1
Open Settings → Sites, add your production domain, and copy your verification token and ws_ site key.
Step 2
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',
},
};
Step 3
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"
/>
</>
);
}
Step 4
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.
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;
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.
The iframe runs stateless with no cookies or analytics scripts, keeping your Next.js privacy setup simple.
Output the post’s updated timestamp in <meta property="article:modified_time"> via generateMetadata() so edits from Sanity, Contentful, or Markdown trigger fresh audio.
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.
Platform guide
Drop two lines with is:inline into your Astro BlogPost layout—zero hydration overhead and full dark mode support.
Platform guide
Drop two lines into your Blade post view with @once and article:modified_time so edits re-read automatically.
Privacy & architecture
How WebtoSpeech runs embeds with zero cookies, zero sessions, domain-locked CSP, and privacy-respecting play counts.
Publisher plan
200 hours of audio a month, every Studio and standard voice, cookie-free embeds, RSS-to-podcast feeds, and play counts.