                success: function(response) {
                    if (response.success) {
                        mementorTTSShowNotification('Voice "' + voiceName + '" set as default.', 'success');
                        if (window.mementorTTSDebug) window.mementorTTSDebug.log('TTS Plugin: Voice saved with language: ' + language);
                    } else {
                        // Show the error message from the server
                        var errorMessage = 'Failed to set default voice.';
                        if (response.data && response.data.message) {
                            errorMessage = response.data.message;
                        }
                        mementorTTSShowNotification(errorMessage, 'error');
                        
                        // Revert button state on error
                        button.removeClass('selected').text('Use Voice');
                        
                        // If the server provided a fallback voice, update the UI to reflect it
                        if (response.data && response.data.voice_id && response.data.voice_name) {
                            if (window.mementorTTSDebug) window.mementorTTSDebug.log('TTS Plugin: Server rejected PRO voice, using fallback voice:', response.data.voice_name);
                            
                            // Update hidden input fields with the fallback voice
                            $('input[name="mementor_tts_voice"]').val(response.data.voice_id);
                            $('input[name="mementor_tts_voice_name"]').val(response.data.voice_name);
                            
                            // Find the button for the fallback voice and mark it as selected
                            $('.mementor-tts-voice-use-button').each(function() {
                                var $btn = $(this);
                                if ($btn.data('voice-id') === response.data.voice_id) {
                                    $btn.addClass('selected').text('Selected');
                                }
                            });
                        }
                    }
                },
