import { getRequestHeaders } from '../../../script.js';
import { getApiUrl } from '../../extensions.js';
import { doExtrasFetch, modules } from '../../extensions.js';
import { getPreviewString } from './index.js';
import { saveTtsProviderSettings } from './index.js';
export { EdgeTtsProvider };
const EDGE_TTS_PROVIDER = {
extras: 'extras',
plugin: 'plugin',
};
class EdgeTtsProvider {
//########//
// Config //
//########//
settings;
voices = [];
separator = ' . ';
audioElement = document.createElement('audio');
defaultSettings = {
voiceMap: {},
rate: 0,
provider: EDGE_TTS_PROVIDER.extras,
};
get settingsHtml() {
let html = `Microsoft Edge TTS
`;
return html;
}
onSettingsChange() {
this.settings.rate = Number($('#edge_tts_rate').val());
$('#edge_tts_rate_output').text(this.settings.rate);
this.settings.provider = String($('#edge_tts_provider').val());
saveTtsProviderSettings();
}
async loadSettings(settings) {
// Pupulate Provider UI given input settings
if (Object.keys(settings).length == 0) {
console.info('Using default TTS Provider settings');
}
// Only accept keys defined in defaultSettings
this.settings = this.defaultSettings;
for (const key in settings) {
if (key in this.settings) {
this.settings[key] = settings[key];
} else {
throw `Invalid setting passed to TTS Provider: ${key}`;
}
}
$('#edge_tts_rate').val(this.settings.rate || 0);
$('#edge_tts_rate_output').text(this.settings.rate || 0);
$('#edge_tts_rate').on('input', () => { this.onSettingsChange(); });
$('#edge_tts_provider').val(this.settings.provider || EDGE_TTS_PROVIDER.extras);
$('#edge_tts_provider').on('change', () => { this.onSettingsChange(); });
await this.checkReady();
console.debug('EdgeTTS: Settings loaded');
}
/**
* Perform a simple readiness check by trying to fetch voiceIds
*/
async checkReady() {
await this.throwIfModuleMissing();
await this.fetchTtsVoiceObjects();
}
async onRefreshClick() {
return;
}
//#################//
// TTS Interfaces //
//#################//
/**
* Get a voice from the TTS provider.
* @param {string} voiceName Voice name to get
* @returns {Promise