Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

How to Create a Voice-Powered WordPress Plugin and Host It

Overview If you’ve ever wanted a WordPress site that talks back to users, or a plugin that lets visitors dictate comments and posts, voice AI is the next step. In this guide we’ll walk through building a lightweight, v

Overview

If you’ve ever wanted a WordPress site that talks back to users, or a plugin that lets visitors dictate comments and posts, voice AI is the next step. In this guide we’ll walk through building a lightweight, voice‑powered WordPress plugin that:

  • Converts text to speech using ElevenLabs’ advanced TTS engine
  • Supports voice cloning for a personalized narrator
  • Can be deployed on an affordable, developer‑friendly host like Bluehost

By the end of this article you’ll have a working plugin, a clear understanding of how the pieces fit together, and a simple deployment strategy.

Why Voice‑Powered WordPress?

  1. Accessibility – Auditory content helps users with visual impairments or reading difficulties.
  2. Engagement – Spoken content can feel more personal and interactive.
  3. Future‑Proof – Voice assistants are everywhere; integrating them early keeps you ahead.

The key to a smooth experience is a reliable TTS provider. ElevenLabs offers high‑fidelity voices, customizable emotion, and voice cloning—all wrapped in a developer‑friendly API.

Getting Started with ElevenLabs

1. Sign Up

Create an account at ElevenLabs. The free tier gives you a generous number of characters per month, perfect for prototyping.

Tip: The affiliate link above gives you a small discount on the next tier, so it’s a win‑win.

2. Grab Your API Key

After logging in, navigate to Settings → API Keys and copy your key. Keep it secret—store it in your WordPress wp-config.php or a .env file if you’re using a plugin that supports environment variables.

// wp-config.php
define( 'ELEVENLABS_API_KEY', 'YOUR_API_KEY_HERE' );

3. Test the API

Before hooking into WordPress, make sure the API works. Try a simple curl call:

curl https://api.elevenlabs.io/v1/text-to-speech \
  -H "xi-api-key: YOUR_API_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello, WordPress!","voice_settings":{"stability":0.5,"similarity_boost":0.75}}'

You should receive a binary audio stream (MP3). Save it to a file and play it to confirm the voice quality.

Building the Plugin

We’ll create a plugin called VoiceTalk that turns any post into a spoken audio file. The core steps are:

  1. Create a shortcode to trigger TTS.
  2. Call ElevenLabs from PHP.
  3. Store the MP3 in the uploads folder.
  4. Render an HTML5 audio player.

1. Plugin Boilerplate

Create a folder voice-talk inside wp-content/plugins/ and a file voice-talk.php with the following header:

<?php
/*
Plugin Name: VoiceTalk
Description: Convert posts to speech using ElevenLabs.
Version: 1.0
Author: Your Name
*/

2. Shortcode

Add a shortcode that users can place inside any post or page:

add_shortcode( 'voicetalk', 'vt_render_player' );

function vt_render_player( $atts ) {
    $post_id = get_the_ID();
    $audio_url = vt_generate_audio( $post_id );

    if ( ! $audio_url ) {
        return '<p>Couldn’t generate audio.</p>';
    }

    return '<audio controls src="' . esc_url( $audio_url ) . '"></audio>';
}

3. Generate Audio

The heavy lifting happens here. We’ll make an HTTP request to ElevenLabs and stream the result to the uploads directory.

function vt_generate_audio( $post_id ) {
    // Check if we already have an audio file
    $meta = get_post_meta( $post_id, '_voice_audio', true );
    if ( $meta ) {
        return wp_get_upload_dir()['baseurl'] . '/' . $meta;
    }

    $post = get_post( $post_id );
    $text = $post->post_content;

    // Prepare request
    $endpoint = 'https://api.elevenlabs.io/v1/text-to-speech/';
    $voice_id = 'YOUR_VOICE_ID'; // From ElevenLabs dashboard
    $url = $endpoint . $voice_id;

    $body = [
        'text' => $text,
        'voice_settings' => [
            'stability' => 0.5,
            'similarity_boost' => 0.75
        ]
    ];

    $response = wp_remote_post( $url, [
        'headers' => [
            'xi-api-key' => ELEVENLABS_API_KEY,
            'Content-Type' => 'application/json'
        ],
        'body'    => wp_json_encode( $body ),
        'timeout' => 120
    ]);

    if ( is_wp_error( $response ) ) {
        return false;
    }

    $audio = wp_remote_retrieve_body( $response );
    if ( empty( $audio ) ) {
        return false;
    }

    // Store the file
    $upload_dir = wp_get_upload_dir();
    $file_path  = $upload_dir['path'] . "/voicepost-{$post_id}.mp3";
    file_put_contents( $file_path, $audio );

    // Save relative path for later
    update_post_meta( $post_id, '_voice_audio', "voicepost-{$post_id}.mp3" );

    return $upload_dir['url'] . "/voicepost-{$post_id}.mp3";
}

Security Note: In a production environment, validate the text length and sanitize the output to avoid excessive API usage or abuse.

4. Add a Settings Page (Optional)

If you want users to pick a voice or adjust settings, add a simple admin page under Settings → VoiceTalk. Store choices in options and read them in vt_generate_audio.

Voice Cloning

ElevenLabs offers a voice cloning feature that lets you create a custom voice profile from a few minutes of audio. Here’s a quick rundown:

  1. Collect Samples – Record 1–2 minutes of clear speech.
  2. Upload to ElevenLabs – Use the Voice Cloning tab in the dashboard.
  3. Generate Voice ID – Once processed, you’ll receive a unique ID.
  4. Use in Plugin – Replace YOUR_VOICE_ID with the cloned ID in the code above.

Cloned voices can dramatically improve the naturalness of your plugin, making the narration feel like a real person.

Deploying on Bluehost

Once your plugin is ready, it’s time to host it. Bluehost is an excellent choice for WordPress developers:

  • Managed WordPress – One‑click installs and automatic updates.
  • Affordable Plans – Starter plans start at a few dollars a month.
  • Developer Tools – SSH access, Git integration, and staging environments.

Bluehost’s plans are perfect for a small voice‑powered site, and the hosting speeds are more than adequate for streaming MP3 files.

How to Deploy

  1. Create an Account – Sign up at Bluehost.
  2. Install WordPress – Use the cPanel “WordPress” installer.
  3. Upload Plugin – Zip your voice-talk folder and upload via Plugins → Add New → Upload Plugin.
  4. Activate & Test – Add [voicetalk] to a post and view it.
  5. Scale – If traffic grows, upgrade to a higher tier or add a CDN.

Bluehost’s customer support is friendly, and the setup process is straightforward, making it an ideal home for your voice AI project.

Troubleshooting Tips

Issue Fix
API errors (e.g., 401) Double‑check your ELEVENLABS_API_KEY. Make sure no whitespace or line breaks.
Large audio files Use the max_length parameter in the ElevenLabs request to trim output.
Slow playback Host audio on a CDN or enable Gzip compression in your server settings.
No audio on mobile Ensure the browser supports MP3; consider providing fallback formats.

Final Thoughts

Building a voice‑powered WordPress plugin is surprisingly straightforward with ElevenLabs and a bit of PHP. The key takeaways:

  • ElevenLabs gives you high‑quality, customizable TTS and voice cloning.
  • Your plugin can generate audio on the fly and embed it seamlessly.
  • Bluehost offers an affordable, developer‑friendly hosting solution that’s ready for WordPress out of the box.

Ready to give your site a voice? Try ElevenLabs today and deploy your plugin on Bluehost for a smooth, cost‑effective experience.

Get started now:

Happy coding!

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.