コンテンツを読み上げるプラグイン

「コンテンツを読み上げてくれるボタン」を表示するプラグインを作成しました。
WP Speech Contents
です。

プラグインをインストールして有効化してから、個別ページを開くと、コンテンツの上部に「読み上げ開始」みたいなボタンが表示されます。
それをクリックすると、コンテンツを読み上げてくれます。

やっていることは 
Web Speech API
を使って、post_content の内容を読ませているだけなんで簡単です。

ほんとは、もうすこし細かな設定とかできるようにしたいんですが、とりあえず今はこれだけ。

ボタンの表示位置だけは上か下を変更できるように、フックを用意しました。

add_filter( 'wp-speech-contents-mode', function () {
    return 'bottom'; // top or bottom
});

こんな感じで。

例えばある記事だけに表示させたいときは

add_filter( 'wp-speech-contents_mode', function () {
    if(is_single(1)){
        return 'bottom'; // top or bottom
    }else{
        return 'none';
    }
});

読み上げる内容を修正できるフックを用意しました。

例えば読み上げる内容に、文言を追加する場合

add_filter( 'wp-speech-contents_content', function ( $content ) {
    return 'これから読み上げます。'.$content;
});

例えば読み上げる内容から記号を削除(日本語の場合)

add_filter( 'wp-speech-contents_content', function ( $content ) {
    $content = preg_replace('/[^、。!!??\pL]/u','',$content);
    return $content;
});

と言う感じでいけるはず。