Plugin Directory

Changeset 3122041

Timestamp:
07/19/2024 12:34:27 PM (16 months ago)
Author:
Elliotvs
Message:

1.0.1

Location:
ai-text-to-speech/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ai-text-to-speech/trunk/aitts.php

    r3061582 r3122041  
    33* Plugin Name: AI Text to Speech
    44* Description: Easily generate and display an audio version for your posts using OpenAI's TTS API.
    5 * Version: 1.0.0
     5* Version: 1.0.1
    66* Author: Elliot Sowersby, RelyWP
    77* Author URI: https://relywp.com
  • ai-text-to-speech/trunk/inc/content/generate.php

    r3061582 r3122041  
    130130        if (is_wp_error($response)) {
    131131            wp_send_json_error(['message' => 'Error generating audio.']);
     132            error_log('Error generating audio: ' . $response->get_error_message());
     133            ai_tts_add_to_error_log('Error generating audio: ' . $response->get_error_message());
    132134        } else {
    133135            $combined_audio_data .= wp_remote_retrieve_body($response);
  • ai-text-to-speech/trunk/inc/options.php

    r3061582 r3122041  
    104104
    105105                        if ($api_key) {
     106
    106107                            $date = gmdate('Y-m-d');
     108                            if (!$date) {
     109                                $date = date('Y-m-d');
     110                            }
     111
    107112                            $url = 'https://api.openai.com/v1/usage?date=' . $date;
    108113                            $args = array(
     
    116121                            // Check for WP_Error or non-200 status code.
    117122                            if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
    118                                 echo esc_html__('Error fetching data.', 'ai-text-to-speech');
    119                                 return;
    120                             }
    121 
    122                             $body = json_decode(wp_remote_retrieve_body($response));
    123 
    124                             // Process the response body.
    125                             $total_characters_used = 0;
    126                             $total_requests = 0;
    127 
    128                             if (isset($body->tts_api_data) && is_array($body->tts_api_data)) {
    129                                 foreach ($body->tts_api_data as $item) {
    130                                     // Ensure that the required properties exist.
    131                                     if (isset($item->num_characters) && isset($item->num_requests)) {
    132                                         $total_characters_used += $item->num_characters;
    133                                         $total_requests += $item->num_requests;
     123
     124                                echo '<p style="color: red; font-weight: bold;">';
     125                                echo esc_html__('Error fetching data. There may be an issue with your Open API key or connection to api.openai.com', 'ai-text-to-speech');
     126                                echo '</p>';
     127                               
     128                                if(is_wp_error($response)) {
     129                                    echo '<p>';
     130                                    echo 'Error message: ' . esc_html($response->get_error_message());
     131                                    ai_tts_add_to_error_log('Error fetching usage data: ' . $response->get_error_message());
     132                                    echo '</p>';
     133                                }
     134
     135                                if(200 !== wp_remote_retrieve_response_code($response) && wp_remote_retrieve_response_code($response)) {
     136                                    echo '<p>';
     137                                    echo 'Response code: ' . esc_html(wp_remote_retrieve_response_code($response)) . " " . esc_html(wp_remote_retrieve_response_message($response));
     138                                    ai_tts_add_to_error_log('Error fetching usage data: ' . wp_remote_retrieve_response_code($response) . " " . wp_remote_retrieve_response_message($response));
     139                                    echo '</p>';
     140                                }
     141
     142                            } else {
     143
     144                                $body = json_decode(wp_remote_retrieve_body($response));
     145
     146                                // Process the response body.
     147                                $total_characters_used = 0;
     148                                $total_requests = 0;
     149
     150                                if (isset($body->tts_api_data) && is_array($body->tts_api_data)) {
     151                                    foreach ($body->tts_api_data as $item) {
     152                                        // Ensure that the required properties exist.
     153                                        if (isset($item->num_characters) && isset($item->num_requests)) {
     154                                            $total_characters_used += $item->num_characters;
     155                                            $total_requests += $item->num_requests;
     156                                        }
    134157                                    }
    135158                                }
    136                             }
    137 
    138                             // Output the results.
    139                             echo esc_html__('Total Characters Used:', 'ai-text-to-speech') . " " . esc_html($total_characters_used) . "<br>";
    140                             echo esc_html__('Total Requests:', 'ai-text-to-speech') . " " . esc_html($total_requests);
    141                             $total_cost = $total_characters_used / 1000 * 0.015;
    142                             $total_cost = round($total_cost, 2);
    143                             echo "<br>" . esc_html__('Total Cost:', 'ai-text-to-speech') . " $" . esc_html($total_cost);
     159
     160                                // Output the results.
     161                                echo esc_html__('Total Characters Used:', 'ai-text-to-speech') . " " . esc_html($total_characters_used) . "<br>";
     162                                echo "<span title='1 request is made for roughly every sentence generated.'>" . esc_html__('Total Requests:', 'ai-text-to-speech') . " " . esc_html($total_requests) . "</span>";
     163                                $total_cost = $total_characters_used / 1000 * 0.015;
     164                                $total_cost = round($total_cost, 4);
     165                                echo "<br>" . esc_html__('Total Cost:', 'ai-text-to-speech') . " $" . esc_html($total_cost);
     166
     167                            }
     168                               
    144169                        } else {
     170
    145171                            echo esc_html__('No API key set.', 'ai-text-to-speech');
     172
    146173                        }
    147174                        ?>
    148175                    </td>
    149176                </tr>
     177                <?php
     178                $ai_tts_error_log = ai_tts_get_option('error_log');
     179                if ($ai_tts_error_log) {
     180                ?>
     181                <tr>
     182                    <th scope="row"></th>
     183                    <td>
     184                        <?php
     185                        echo '<p style="color: red; font-weight: bold;">';
     186                        echo esc_html__('Error Log:', 'ai-text-to-speech');
     187                        echo ' <a href="?page=ai-text-to-speech&clear_error_log=1" style="text-decoration: underline;">' . esc_html__('Delete', 'ai-text-to-speech') . '</a>';
     188                        echo '</p>';
     189                        echo '<span style="max-height: 50px; overflow: auto; display: block; border: 1px solid #ccc; padding: 10px; background-color: #f1f1f1;">';
     190                        $ai_tts_error_log = str_replace("/n", "<br>", $ai_tts_error_log);
     191                        $ai_tts_error_log = substr($ai_tts_error_log, 4);
     192                        echo wp_kses_post($ai_tts_error_log);
     193                        echo '</span>';                           
     194                        ?>
     195                    </td>
     196                </tr>
     197                <?php } ?>
    150198                </table>
     199
     200                <?php if(isset($_GET['clear_error_log']) && $_GET['clear_error_log'] == 1) {
     201                    $options = get_option('ai_tts_settings');
     202                    if(!$options) {
     203                        $options = array();
     204                    }
     205                    $options['error_log'] = '';
     206                    update_option('ai_tts_settings', $options);
     207                    wp_redirect(admin_url('options-general.php?page=ai-text-to-speech'));
     208                    exit;
     209                } ?>
    151210
    152211                <hr/>
     
    354413    register_setting('ai_tts_settings', 'ai_tts_settings');
    355414}
     415
     416function ai_tts_add_to_error_log($message) {
     417
     418    $ai_tts_error_log = ai_tts_get_option('error_log');
     419    $ai_tts_error_log = "/n" . date('Y-m-d H:i:s') . ' - ' . $message . $ai_tts_error_log;
     420
     421    $ai_tts_error_log = explode("/n", $ai_tts_error_log);
     422    if(count($ai_tts_error_log) > 10) {
     423        array_shift($ai_tts_error_log);
     424    }
     425    $ai_tts_error_log = implode("/n", $ai_tts_error_log);
     426   
     427    $options = get_option('ai_tts_settings');
     428    if(!$options) {
     429        $options = array();
     430    }
     431    $options['error_log'] = $ai_tts_error_log;
     432    update_option('ai_tts_settings', $options);
     433
     434}
  • ai-text-to-speech/trunk/readme.txt

    r3121240 r3122041  
    55Requires at least: 4.7
    66Tested up to: 6.6.0
    7 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    88License: GPLv3 or later.
    99
     
    1515
    1616When the audio has been generated for a post, an audio player will be displayed automatically at the top of your post, which visitors can listen to.
     17
     18This plugin is perfect for bloggers, content creators, and anyone who wants to provide an audio version of their posts for their visitors.
     19
     20Key Features:
     21- Easily generate an audio version of your posts using OpenAI's Text to Speech API.
     22- Automatically display an audio player at the top of your post.
     23- Supports text to speech generation for over 50 languages.
     24- Optionally include the post title, author name and post date at the start of the audio.
    1725
    1826## 👍 Suggestions and Support
     
    6977== Changelog ==
    7078
    71 = Version 1.0.0 - 30th March 2024 =
     79= Version 1.0.1 - 19th July 2024 =
     80- Tweak: Added some better error handling and error messages on the admin settings page if there is a connection issue with the OpenAI API.
     81- Tweak: Added an error log to the plugin settings page to help debug any issues.
     82
     83= Version 1.0.0 - 19th January 2024 =
    7284- Initial release
Note: See TracChangeset for help on using the changeset viewer.