You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1116 lines
858 KiB

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
https://github.com/joethei/obsidian-rss
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x2) => x2.done ? resolve(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// node_modules/@cospired/i18n-iso-languages/codes.json
var require_codes = __commonJS({
"node_modules/@cospired/i18n-iso-languages/codes.json"(exports, module2) {
module2.exports = [
["aa", "aar", "aar", "ISO 639-1:aa"],
["ab", "abk", "abk", "ISO 639-1:ab"],
["ae", "ave", "ave", "ISO 639-1:ae"],
["af", "afr", "afr", "ISO 639-1:af"],
["ak", "aka", "aka", "ISO 639-1:ak"],
["am", "amh", "amh", "ISO 639-1:am"],
["an", "arg", "arg", "ISO 639-1:an"],
["ar", "ara", "ara", "ISO 639-1:ar"],
["as", "asm", "asm", "ISO 639-1:as"],
["av", "ava", "ava", "ISO 639-1:av"],
["ay", "aym", "aym", "ISO 639-1:ay"],
["az", "aze", "aze", "ISO 639-1:az"],
["ba", "bak", "bak", "ISO 639-1:ba"],
["be", "bel", "bel", "ISO 639-1:be"],
["bg", "bul", "bul", "ISO 639-1:bg"],
["bh", "bih", "bih", "ISO 639-1:bh"],
["bi", "bis", "bis", "ISO 639-1:bi"],
["bm", "bam", "bam", "ISO 639-1:bm"],
["bn", "ben", "ben", "ISO 639-1:bn"],
["bo", "bod", "tib", "ISO 639-1:bo"],
["br", "bre", "bre", "ISO 639-1:br"],
["bs", "bos", "bos", "ISO 639-1:bs"],
["ca", "cat", "cat", "ISO 639-1:ca"],
["ce", "che", "che", "ISO 639-1:ce"],
["ch", "cha", "cha", "ISO 639-1:ch"],
["co", "cos", "cos", "ISO 639-1:co"],
["cr", "cre", "cre", "ISO 639-1:cr"],
["cs", "ces", "cze", "ISO 639-1:cs"],
["cu", "chu", "chu", "ISO 639-1:cu"],
["cv", "chv", "chv", "ISO 639-1:cv"],
["cy", "cym", "wel", "ISO 639-1:cy"],
["da", "dan", "dan", "ISO 639-1:da"],
["de", "deu", "ger", "ISO 639-1:de"],
["dv", "div", "div", "ISO 639-1:dv"],
["dz", "dzo", "dzo", "ISO 639-1:dz"],
["ee", "ewe", "ewe", "ISO 639-1:ee"],
["el", "ell", "gre", "ISO 639-1:el"],
["en", "eng", "eng", "ISO 639-1:en"],
["eo", "epo", "epo", "ISO 639-1:eo"],
["es", "spa", "spa", "ISO 639-1:es"],
["et", "est", "est", "ISO 639-1:et"],
["eu", "eus", "baq", "ISO 639-1:eu"],
["fa", "fas", "per", "ISO 639-1:fa"],
["ff", "ful", "ful", "ISO 639-1:ff"],
["fi", "fin", "fin", "ISO 639-1:fi"],
["fj", "fij", "fij", "ISO 639-1:fj"],
["fo", "fao", "fao", "ISO 639-1:fo"],
["fr", "fra", "fre", "ISO 639-1:fr"],
["fy", "fry", "fry", "ISO 639-1:fy"],
["ga", "gle", "gle", "ISO 639-1:ga"],
["gd", "gla", "gla", "ISO 639-1:gd"],
["gl", "glg", "glg", "ISO 639-1:gl"],
["gn", "grn", "grn", "ISO 639-1:gn"],
["gu", "guj", "guj", "ISO 639-1:gu"],
["gv", "glv", "glv", "ISO 639-1:gv"],
["ha", "hau", "hau", "ISO 639-1:ha"],
["he", "heb", "heb", "ISO 639-1:he"],
["hi", "hin", "hin", "ISO 639-1:hi"],
["ho", "hmo", "hmo", "ISO 639-1:ho"],
["hr", "hrv", "hrv", "ISO 639-1:hr"],
["ht", "hat", "hat", "ISO 639-1:ht"],
["hu", "hun", "hun", "ISO 639-1:hu"],
["hy", "hye", "arm", "ISO 639-1:hy"],
["hz", "her", "her", "ISO 639-1:hz"],
["ia", "ina", "ina", "ISO 639-1:ia"],
["id", "ind", "ind", "ISO 639-1:id"],
["ie", "ile", "ile", "ISO 639-1:ie"],
["ig", "ibo", "ibo", "ISO 639-1:ig"],
["ii", "iii", "iii", "ISO 639-1:ii"],
["ik", "ipk", "ipk", "ISO 639-1:ik"],
["io", "ido", "ido", "ISO 639-1:io"],
["is", "isl", "ice", "ISO 639-1:is"],
["it", "ita", "ita", "ISO 639-1:it"],
["iu", "iku", "iku", "ISO 639-1:iu"],
["ja", "jpn", "jpn", "ISO 639-1:ja"],
["jv", "jav", "jav", "ISO 639-1:jv"],
["ka", "kat", "geo", "ISO 639-1:ka"],
["kg", "kon", "kon", "ISO 639-1:kg"],
["ki", "kik", "kik", "ISO 639-1:ki"],
["kj", "kua", "kua", "ISO 639-1:kj"],
["kk", "kaz", "kaz", "ISO 639-1:kk"],
["kl", "kal", "kal", "ISO 639-1:kl"],
["km", "khm", "khm", "ISO 639-1:km"],
["kn", "kan", "kan", "ISO 639-1:kn"],
["ko", "kor", "kor", "ISO 639-1:ko"],
["kr", "kau", "kau", "ISO 639-1:kr"],
["ks", "kas", "kas", "ISO 639-1:ks"],
["ku", "kur", "kur", "ISO 639-1:ku"],
["kv", "kom", "kom", "ISO 639-1:kv"],
["kw", "cor", "cor", "ISO 639-1:kw"],
["ky", "kir", "kir", "ISO 639-1:ky"],
["la", "lat", "lat", "ISO 639-1:la"],
["lb", "ltz", "ltz", "ISO 639-1:lb"],
["lg", "lug", "lug", "ISO 639-1:lg"],
["li", "lim", "lim", "ISO 639-1:li"],
["ln", "lin", "lin", "ISO 639-1:ln"],
["lo", "lao", "lao", "ISO 639-1:lo"],
["lt", "lit", "lit", "ISO 639-1:lt"],
["lu", "lub", "lub", "ISO 639-1:lu"],
["lv", "lav", "lav", "ISO 639-1:lv"],
["mg", "mlg", "mlg", "ISO 639-1:mg"],
["mh", "mah", "mah", "ISO 639-1:mh"],
["mi", "mri", "mao", "ISO 639-1:mi"],
["mk", "mkd", "mac", "ISO 639-1:mk"],
["ml", "mal", "mal", "ISO 639-1:ml"],
["mn", "mon", "mon", "ISO 639-1:mn"],
["mr", "mar", "mar", "ISO 639-1:mr"],
["ms", "msa", "may", "ISO 639-1:ms"],
["mt", "mlt", "mlt", "ISO 639-1:mt"],
["my", "mya", "bur", "ISO 639-1:my"],
["na", "nau", "nau", "ISO 639-1:na"],
["nb", "nob", "nob", "ISO 639-1:nb"],
["nd", "nde", "nde", "ISO 639-1:nd"],
["ne", "nep", "nep", "ISO 639-1:ne"],
["ng", "ndo", "ndo", "ISO 639-1:ng"],
["nl", "nld", "dut", "ISO 639-1:nl"],
["nn", "nno", "nno", "ISO 639-1:nn"],
["no", "nor", "nor", "ISO 639-1:no"],
["nr", "nbl", "nbl", "ISO 639-1:nr"],
["nv", "nav", "nav", "ISO 639-1:nv"],
["ny", "nya", "nya", "ISO 639-1:ny"],
["oc", "oci", "oci", "ISO 639-1:oc"],
["oj", "oji", "oji", "ISO 639-1:oj"],
["om", "orm", "orm", "ISO 639-1:om"],
["or", "ori", "ori", "ISO 639-1:or"],
["os", "oss", "oss", "ISO 639-1:os"],
["pa", "pan", "pan", "ISO 639-1:pa"],
["pi", "pli", "pli", "ISO 639-1:pi"],
["pl", "pol", "pol", "ISO 639-1:pl"],
["ps", "pus", "pus", "ISO 639-1:ps"],
["pt", "por", "por", "ISO 639-1:pt"],
["qu", "que", "que", "ISO 639-1:qu"],
["rm", "roh", "roh", "ISO 639-1:rm"],
["rn", "run", "run", "ISO 639-1:rn"],
["ro", "ron", "rum", "ISO 639-1:ro"],
["ru", "rus", "rus", "ISO 639-1:ru"],
["rw", "kin", "kin", "ISO 639-1:rw"],
["sa", "san", "san", "ISO 639-1:sa"],
["sc", "srd", "srd", "ISO 639-1:sc"],
["sd", "snd", "snd", "ISO 639-1:sd"],
["se", "sme", "sme", "ISO 639-1:se"],
["sg", "sag", "sag", "ISO 639-1:sg"],
["si", "sin", "sin", "ISO 639-1:si"],
["sk", "slk", "slo", "ISO 639-1:sk"],
["sl", "slv", "slv", "ISO 639-1:sl"],
["sm", "smo", "smo", "ISO 639-1:sm"],
["sn", "sna", "sna", "ISO 639-1:sn"],
["so", "som", "som", "ISO 639-1:so"],
["sq", "sqi", "alb", "ISO 639-1:sq"],
["sr", "srp", "srp", "ISO 639-1:sr"],
["ss", "ssw", "ssw", "ISO 639-1:ss"],
["st", "sot", "sot", "ISO 639-1:st"],
["su", "sun", "sun", "ISO 639-1:su"],
["sv", "swe", "swe", "ISO 639-1:sv"],
["sw", "swa", "swa", "ISO 639-1:sw"],
["ta", "tam", "tam", "ISO 639-1:ta"],
["te", "tel", "tel", "ISO 639-1:te"],
["tg", "tgk", "tgk", "ISO 639-1:tg"],
["th", "tha", "tha", "ISO 639-1:th"],
["ti", "tir", "tir", "ISO 639-1:ti"],
["tk", "tuk", "tuk", "ISO 639-1:tk"],
["tl", "tgl", "tgl", "ISO 639-1:tl"],
["tn", "tsn", "tsn", "ISO 639-1:tn"],
["to", "ton", "ton", "ISO 639-1:to"],
["tr", "tur", "tur", "ISO 639-1:tr"],
["ts", "tso", "tso", "ISO 639-1:ts"],
["tt", "tat", "tat", "ISO 639-1:tt"],
["tw", "twi", "twi", "ISO 639-1:tw"],
["ty", "tah", "tah", "ISO 639-1:ty"],
["ug", "uig", "uig", "ISO 639-1:ug"],
["uk", "ukr", "ukr", "ISO 639-1:uk"],
["ur", "urd", "urd", "ISO 639-1:ur"],
["uz", "uzb", "uzb", "ISO 639-1:uz"],
["ve", "ven", "ven", "ISO 639-1:ve"],
["vi", "vie", "vie", "ISO 639-1:vi"],
["vo", "vol", "vol", "ISO 639-1:vo"],
["wa", "wln", "wln", "ISO 639-1:wa"],
["wo", "wol", "wol", "ISO 639-1:wo"],
["xh", "xho", "xho", "ISO 639-1:xh"],
["yi", "yid", "yid", "ISO 639-1:yi"],
["yo", "yor", "yor", "ISO 639-1:yo"],
["za", "zha", "zha", "ISO 639-1:za"],
["zh", "zho", "chi", "ISO 639-1:zh"],
["zu", "zul", "zul", "ISO 639-1:zu"]
];
}
});
// node_modules/@cospired/i18n-iso-languages/index.js
var require_i18n_iso_languages = __commonJS({
"node_modules/@cospired/i18n-iso-languages/index.js"(exports) {
var codes = require_codes();
var registeredLocales = {};
var alpha2 = {};
var alpha3T = {};
var alpha3B = {};
var invertedAlpha3B = {};
codes.forEach((codeInformation) => {
const [first, second, third] = codeInformation;
alpha2[first] = second;
alpha3T[second] = first;
alpha3B[third] = first;
invertedAlpha3B[first] = third;
});
function registerLocale(localeData) {
if (!localeData.locale) {
throw new TypeError("Missing localeData.locale");
}
if (!localeData.languages) {
throw new TypeError("Missing localeData.languages");
}
registeredLocales[localeData.locale] = localeData.languages;
}
function alpha3TToAlpha2(code) {
return alpha3T[code];
}
function alpha3BToAlpha2(code) {
return alpha3B[code];
}
function alpha2ToAlpha3T(code) {
return alpha2[code];
}
function alpha2ToAlpha3B(code) {
return invertedAlpha3B[code];
}
function toAlpha3T(code) {
if (typeof code !== "string") {
return void 0;
}
const codeLower = code.toLowerCase();
if (code.length === 2) {
return alpha2ToAlpha3T(codeLower);
}
if (code.length === 3) {
if (alpha3T[codeLower]) {
return codeLower;
}
if (alpha3BToAlpha2(codeLower)) {
return alpha2ToAlpha3T(alpha3BToAlpha2(codeLower));
}
}
return void 0;
}
function toAlpha3B(code) {
if (typeof code !== "string") {
return void 0;
}
const codeLower = code.toLowerCase();
if (code.length === 2) {
return alpha2ToAlpha3B(codeLower);
}
if (code.length === 3) {
if (alpha3B[codeLower]) {
return codeLower;
}
if (alpha3T[codeLower]) {
return alpha2ToAlpha3B(alpha3TToAlpha2(codeLower));
}
}
return void 0;
}
function toAlpha2(code) {
if (typeof code !== "string") {
return void 0;
}
const codeLower = code.toLowerCase();
if (code.length === 2) {
return codeLower;
}
if (code.length === 3) {
if (alpha3B[codeLower]) {
return alpha3BToAlpha2(codeLower);
}
if (alpha3T[codeLower]) {
return alpha3TToAlpha2(codeLower);
}
}
return void 0;
}
function getName(code, lang) {
try {
const d2 = registeredLocales[lang.toLowerCase()];
return d2[toAlpha2(code)];
} catch (err) {
return void 0;
}
}
function getNames(lang) {
const d2 = registeredLocales[lang.toLowerCase()];
if (d2 === void 0) {
return {};
}
return d2;
}
function getAlpha2Code(name, lang) {
try {
let p2;
const codenames = registeredLocales[lang.toLowerCase()];
for (p2 in codenames) {
if (Object.prototype.hasOwnProperty.call(codenames, p2)) {
if (codenames[p2].toLowerCase() === name.toLowerCase()) {
return p2;
}
}
}
return void 0;
} catch (err) {
return void 0;
}
}
function getAlpha2Codes() {
return alpha2;
}
function getAlpha3TCode(name, lang) {
const code = getAlpha2Code(name, lang);
if (code) {
return toAlpha3T(code);
}
return void 0;
}
function getAlpha3BCode(name, lang) {
const code = getAlpha2Code(name, lang);
if (code) {
return toAlpha3B(code);
}
return void 0;
}
function getAlpha3TCodes() {
return alpha3T;
}
function getAlpha3BCodes() {
return alpha3B;
}
function langs() {
return Object.keys(registeredLocales);
}
function isValid(code) {
return toAlpha3T(code) !== void 0;
}
exports.alpha2ToAlpha3B = alpha2ToAlpha3B;
exports.alpha2ToAlpha3T = alpha2ToAlpha3T;
exports.alpha3BToAlpha2 = alpha3BToAlpha2;
exports.alpha3TToAlpha2 = alpha3TToAlpha2;
exports.getAlpha2Code = getAlpha2Code;
exports.getAlpha2Codes = getAlpha2Codes;
exports.getAlpha3BCode = getAlpha3BCode;
exports.getAlpha3BCodes = getAlpha3BCodes;
exports.getAlpha3TCode = getAlpha3TCode;
exports.getAlpha3TCodes = getAlpha3TCodes;
exports.getName = getName;
exports.getNames = getNames;
exports.isValid = isValid;
exports.langs = langs;
exports.registerLocale = registerLocale;
exports.toAlpha2 = toAlpha2;
exports.toAlpha3B = toAlpha3B;
exports.toAlpha3T = toAlpha3T;
}
});
// src/main.ts
__export(exports, {
default: () => TTSPlugin
});
var import_obsidian5 = __toModule(require("obsidian"));
// src/settings.ts
var import_obsidian3 = __toModule(require("obsidian"));
// src/TextInputPrompt.ts
var import_obsidian = __toModule(require("obsidian"));
var TextInputPrompt = class extends import_obsidian.Modal {
constructor(app, promptText, hint, defaultValue, placeholder) {
super(app);
this.promptText = promptText;
this.hint = hint;
this.defaultValue = defaultValue;
this.placeholder = placeholder;
}
onOpen() {
this.titleEl.setText(this.promptText);
this.createForm();
}
onClose() {
this.contentEl.empty();
}
createForm() {
const div = this.contentEl.createDiv();
const text = new import_obsidian.Setting(div).setName(this.promptText).setDesc(this.hint).addText((textComponent) => {
textComponent.setValue(this.defaultValue).setPlaceholder(this.placeholder).inputEl.setAttribute("size", "50");
this.textComponent = textComponent;
});
text.controlEl.addClass("tts-text-input");
new import_obsidian.Setting(div).addButton((b2) => {
b2.setButtonText("Play").onClick(() => __async(this, null, function* () {
this.resolve(this.textComponent);
}));
return b2;
});
}
openAndGetValue(resolve) {
return __async(this, null, function* () {
this.resolve = resolve;
yield this.open();
});
}
};
// src/LanguageVoiceModal.ts
var import_obsidian2 = __toModule(require("obsidian"));
var import_i18n_iso_languages = __toModule(require_i18n_iso_languages());
var LanguageVoiceModal = class extends import_obsidian2.Modal {
constructor(plugin, map) {
super(plugin.app);
this.plugin = plugin;
if (map) {
this.language = map.language;
this.voice = map.voice;
}
}
display() {
return __async(this, null, function* () {
const { contentEl } = this;
contentEl.empty();
const languageNames = new Intl.DisplayNames(["en"], { type: "language" });
new import_obsidian2.Setting(contentEl).setName("Language").addDropdown((dropdown) => __async(this, null, function* () {
for (const languageCodeKey in import_i18n_iso_languages.default.getAlpha2Codes()) {
const displayNames = new Intl.DisplayNames([languageCodeKey], { type: "language", fallback: "none" });
if (displayNames) {
const name = displayNames.of(languageCodeKey);
if (name) {
dropdown.addOption(languageCodeKey, name);
}
}
}
dropdown.setValue(this.language).onChange((value) => {
this.language = value;
});
}));
new import_obsidian2.Setting(contentEl).setName("Voice").addDropdown((dropdown) => __async(this, null, function* () {
const voices = window.speechSynthesis.getVoices();
for (const voice of voices) {
dropdown.addOption(voice.name, voice.name + " - " + languageNames.of(voice.lang));
}
dropdown.setValue(this.voice).onChange((value) => __async(this, null, function* () {
this.voice = value;
}));
})).addExtraButton((button) => {
button.setIcon("play-audio-glyph").setTooltip("Test voice").onClick(() => __async(this, null, function* () {
const input = new TextInputPrompt(this.app, "What do you want to hear?", "", "Hello world this is Text to speech running in obsidian", "Hello world this is Text to speech running in obsidian");
yield input.openAndGetValue((value) => __async(this, null, function* () {
if (value.getValue().length === 0)
return;
yield this.plugin.ttsService.sayWithVoice("", value.getValue(), this.voice);
}));
}));
});
const footerEl = contentEl.createDiv();
const footerButtons = new import_obsidian2.Setting(footerEl);
footerButtons.addButton((b2) => {
b2.setTooltip("Save").setIcon("checkmark").onClick(() => __async(this, null, function* () {
this.saved = true;
this.close();
}));
return b2;
});
footerButtons.addExtraButton((b2) => {
b2.setIcon("cross").setTooltip("Cancel").onClick(() => {
this.saved = false;
this.close();
});
return b2;
});
});
}
onOpen() {
return __async(this, null, function* () {
yield this.display();
});
}
};
// src/settings.ts
var DEFAULT_SETTINGS = {
defaultVoice: "",
pitch: 1,
rate: 1,
volume: 1,
speakLinks: false,
speakFrontmatter: false,
speakSyntax: false,
speakTitle: true,
speakCodeblocks: false,
speakEmoji: false,
speakComments: false,
languageVoices: [],
stopPlaybackWhenNoteChanges: false
};
var TTSSettingsTab = class extends import_obsidian3.PluginSettingTab {
constructor(plugin) {
super(plugin.app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Text to Speech - Settings" });
new import_obsidian3.Setting(containerEl).setName("Default voice").addDropdown((dropdown) => __async(this, null, function* () {
const voices = window.speechSynthesis.getVoices();
for (const voice of voices) {
dropdown.addOption(voice.name, voice.name);
}
dropdown.setValue(this.plugin.settings.defaultVoice).onChange((value) => __async(this, null, function* () {
this.plugin.settings.defaultVoice = value;
yield this.plugin.saveSettings();
}));
})).addExtraButton((button) => {
button.setIcon("play-audio-glyph").setTooltip("Test voice").onClick(() => __async(this, null, function* () {
const input = new TextInputPrompt(this.app, "What do you want to hear?", "", "Hello world this is Text to speech running in obsidian", "Hello world this is Text to speech running in obsidian");
yield input.openAndGetValue((value) => __async(this, null, function* () {
if (value.getValue().length === 0)
return;
yield this.plugin.ttsService.say("", value.getValue());
}));
}));
});
containerEl.createEl("h3", { text: "Language specific voices" });
new import_obsidian3.Setting(containerEl).setName("Add New").setDesc("Add a new language specific voice").addButton((button) => {
return button.setTooltip("add new language specific voice").setIcon("create-new").onClick(() => __async(this, null, function* () {
const modal = new LanguageVoiceModal(this.plugin);
modal.onClose = () => __async(this, null, function* () {
if (modal.saved) {
this.plugin.settings.languageVoices.push({
language: modal.language,
voice: modal.voice
});
yield this.plugin.saveSettings();
this.display();
}
});
modal.open();
}));
});
const additionalContainer = containerEl.createDiv("tts-languages");
const voicesDiv = additionalContainer.createDiv("voices");
for (const languageVoice of this.plugin.settings.languageVoices) {
const displayNames = new Intl.DisplayNames([languageVoice.language], { type: "language", fallback: "none" });
const setting = new import_obsidian3.Setting(voicesDiv);
setting.setName(displayNames.of(languageVoice.language) + " - " + languageVoice.language);
setting.setDesc(languageVoice.voice);
setting.addExtraButton((b2) => {
b2.setIcon("pencil").setTooltip("Edit").onClick(() => {
const modal = new LanguageVoiceModal(this.plugin, languageVoice);
modal.onClose = () => __async(this, null, function* () {
if (modal.saved) {
const setting2 = this.plugin.settings.languageVoices.filter((value) => value.language !== modal.language);
setting2.push({ language: modal.language, voice: modal.voice });
this.plugin.settings.languageVoices = setting2;
yield this.plugin.saveSettings();
this.display();
}
});
modal.open();
});
}).addExtraButton((b2) => {
b2.setIcon("trash").setTooltip("Delete").onClick(() => __async(this, null, function* () {
this.plugin.settings.languageVoices = this.plugin.settings.languageVoices.filter((value) => value.language !== languageVoice.language);
yield this.plugin.saveSettings();
this.display();
}));
});
}
containerEl.createEl("h3", { text: "Audio settings" });
new import_obsidian3.Setting(containerEl).setName("Volume").addSlider((slider) => __async(this, null, function* () {
slider.setValue(this.plugin.settings.volume * 100).setDynamicTooltip().setLimits(0, 100, 1).onChange((value) => __async(this, null, function* () {
this.plugin.settings.volume = value / 100;
yield this.plugin.saveSettings();
}));
})).addExtraButton((button) => {
button.setIcon("reset").setTooltip("restore default").onClick(() => __async(this, null, function* () {
this.plugin.settings.volume = DEFAULT_SETTINGS.volume;
yield this.plugin.saveSettings();
this.display();
}));
});
new import_obsidian3.Setting(containerEl).setName("Rate").setDesc("how fast the text will be spoken").addSlider((slider) => __async(this, null, function* () {
slider.setValue(this.plugin.settings.rate).setDynamicTooltip().setLimits(0.1, 10, 0.1).onChange((value) => __async(this, null, function* () {
this.plugin.settings.rate = value;
yield this.plugin.saveSettings();
}));
})).addExtraButton((button) => {
button.setIcon("reset").setTooltip("restore default").onClick(() => __async(this, null, function* () {
this.plugin.settings.rate = DEFAULT_SETTINGS.rate;
yield this.plugin.saveSettings();
this.display();
}));
});
new import_obsidian3.Setting(containerEl).setName("Pitch").addSlider((slider) => __async(this, null, function* () {
slider.setValue(this.plugin.settings.pitch).setDynamicTooltip().setLimits(0, 2, 0.1).onChange((value) => __async(this, null, function* () {
this.plugin.settings.pitch = value;
yield this.plugin.saveSettings();
}));
})).addExtraButton((button) => {
button.setIcon("reset").setTooltip("restore default").onClick(() => __async(this, null, function* () {
this.plugin.settings.pitch = DEFAULT_SETTINGS.pitch;
yield this.plugin.saveSettings();
this.display();
}));
});
containerEl.createEl("h3", { text: "Speak" });
new import_obsidian3.Setting(containerEl).setName("Title").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakTitle).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakTitle = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Frontmatter").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakFrontmatter).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakFrontmatter = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Links").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakLinks).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakLinks = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Codeblocks").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakCodeblocks).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakCodeblocks = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Comments").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakComments).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakComments = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Syntax").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakSyntax).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakSyntax = value;
yield this.plugin.saveSettings();
}));
}));
new import_obsidian3.Setting(containerEl).setName("Emoji").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.speakEmoji).onChange((value) => __async(this, null, function* () {
this.plugin.settings.speakEmoji = value;
yield this.plugin.saveSettings();
}));
}));
containerEl.createEl("h2", { text: "Misc" });
new import_obsidian3.Setting(containerEl).setName("Stop playback when a note is closed/new note is opened").addToggle((toggle) => __async(this, null, function* () {
toggle.setValue(this.plugin.settings.stopPlaybackWhenNoteChanges).onChange((value) => __async(this, null, function* () {
this.plugin.settings.stopPlaybackWhenNoteChanges = value;
yield this.plugin.saveSettings();
}));
}));
}
};
// src/TTSService.ts
var import_obsidian4 = __toModule(require("obsidian"));
// node_modules/tinyld/dist/tinyld.esm.js
var p = "normal";
var S = { TINYLD_CONFIG: p };
var y = /[,.。,、#%&/\\+*!¿?[\];:…„“«»”"“_—~]/gi;
var v = /[0-9]/g;
var j = /[\uFF10-\uFF19]/g;
var I = /\s\s+/g;
var T = //gi;
var F = /[\u0300-\u036f]/g;
function V(a) {
return typeof a == "string" || a instanceof String;
}
function W(a) {
return a.toLowerCase().replace(T, "'").replace(y, " ").replace(j, (i) => String.fromCharCode(i.charCodeAt(0) - 65248)).replace(v, "").replace(I, " ").trim();
}
function U(a) {
return a.normalize("NFD").replace(F, "");
}
var d = { light: { TRAINING_UNIQUE_GRAMS: [1, 2, 3, 4], TOP_LANGUAGE_UNIQUE_GRAMS: 60, TOP_LANGUAGE_STATS_GRAMS: 50 }, normal: { TRAINING_UNIQUE_GRAMS: [1, 2, 3, 4, 5], TOP_LANGUAGE_UNIQUE_GRAMS: 100, TOP_LANGUAGE_STATS_GRAMS: 180 } };
var m = S.TINYLD_CONFIG || "normal";
var G = d[m].TRAINING_UNIQUE_GRAMS;
var s0 = d[m].TOP_LANGUAGE_UNIQUE_GRAMS;
var l0 = d[m].TOP_LANGUAGE_STATS_GRAMS;
var R = 1e4;
function Q(a) {
return Math.round(a * R) / R;
}
var E = (a) => {
let i = { only: [], verbose: false };
return a ? Object.assign(i, a) : i;
};
var u = { afr: { code: "af", region: "africa", name: "Afrikaans", skipLight: true }, amh: { code: "am", region: "africa", name: "Amharic", skipLight: true, coefProb: 0 }, ber: { code: "ber", region: "africa", name: "Berber", skipLight: true, coefProb: 0.25 }, run: { code: "rn", region: "africa", name: "Kirundi", skipLight: true }, jpn: { code: "ja", region: "asia-east", name: "Japanese", alias: ["jp"], coefProb: 0 }, cmn: { code: "zh", region: "asia-east", name: "Chinese", alias: ["cn"], coefProb: 0.25 }, kor: { code: "ko", region: "asia-east", name: "Korean", alias: ["kr"], coefProb: 0 }, mya: { code: "my", region: "asia", name: "Burmese", skipLight: true, coefProb: 0 }, tha: { code: "th", region: "asia", name: "Thai", coefProb: 0 }, vie: { code: "vi", region: "asia", name: "Vietnamese", skipLight: true, coefProb: 0 }, ind: { code: "id", region: "asia", name: "Indonesian", skipLight: true }, khm: { code: "km", region: "asia", name: "Khmer", skipLight: true, coefProb: 0 }, tgl: { code: "tl", region: "asia", name: "Tagalog", skipLight: true }, ben: { code: "bn", region: "asia-south", name: "Bengali", coefProb: 0 }, tam: { code: "ta", region: "asia-south", name: "Tamil", skipLight: true, coefProb: 0 }, hin: { code: "hi", region: "asia-south", name: "Hindi", coefProb: 0 }, urd: { code: "ur", region: "asia-south", name: "Urdu", skipLight: true, coefProb: 0 }, guj: { code: "gu", region: "asia-south", name: "Gujarati", skipLight: true, coefProb: 0 }, kan: { code: "kn", region: "asia-south", name: "Kannada", skipLight: true, coefProb: 0 }, tel: { code: "te", region: "asia-south", name: "Telugu", skipLight: true, coefProb: 0 }, fra: { code: "fr", region: "europe-west", name: "French" }, eng: { code: "en", region: "europe-west", name: "English", alias: ["us", "gb"] }, deu: { code: "de", region: "europe-west", name: "German", coefProb: 0.5 }, spa: { code: "es", region: "europe-west", name: "Spanish" }, cat: { code: "ca", region: "europe-west", name: "Catalan", skipLight: true }, por: { code: "pt", region: "europe-west", name: "Portuguese", alias: ["po"] }, ita: { code: "it", region: "europe-west", name: "Italian" }, nld: { code: "nl", region: "europe-west", name: "Dutch" }, gle: { code: "ga", region: "europe-west", name: "Irish", skipLight: true }, lat: { code: "la", region: "europe", name: "Latin", skipLight: true }, ces: { code: "cs", region: "europe", name: "Czech", skipLight: true }, srp: { code: "sr", region: "europe", name: "Serbian", skipLight: true }, ell: { code: "el", region: "europe", name: "Greek", alias: ["gr"], coefProb: 0 }, mkd: { code: "mk", region: "europe", name: "Macedonian", skipLight: true, coefProb: 1.5 }, slk: { code: "sk", region: "europe", name: "Slovak", skipLight: true }, dan: { code: "da", region: "europe-north", name: "Danish", skipLight: true, coefProb: 1.5 }, swe: { code: "sv", region: "europe-north", name: "Swedish" }, fin: { code: "fi", region: "europe-north", name: "Finnish" }, nob: { code: "no", region: "europe-north", name: "Norwegian", coefProb: 1.5 }, isl: { code: "is", region: "europe-north", name: "Icelandic", skipLight: true, coefProb: 0.5 }, hun: { code: "hu", region: "europe-east", name: "Hungarian" }, ron: { code: "ro", region: "europe-east", name: "Romanian", coefProb: 0.5 }, bul: { code: "bg", region: "europe-east", name: "Bulgarian", skipLight: true }, bel: { code: "be", region: "europe-east", name: "Belarusian", skipLight: true }, rus: { code: "ru", region: "europe-east", name: "Russian" }, ukr: { code: "uk", region: "europe-east", name: "Ukrainian", skipLight: true }, pol: { code: "pl", region: "europe-east", name: "Polish", coefProb: 0.5 }, lit: { code: "lt", region: "europe-east", name: "Lithuanian", skipLight: true }, est: { code: "et", region: "europe-east", name: "Estonian", skipLight: true }, lvs: { code: "lv", region: "europe-east", name: "Latvian", skipLight: true }, hye: { code: "hy", region: "middle-east", name: "Armenian", skipLight: true, coefProb: 0 }, tur: { code: "tr", region: "middle-east", name: "Turkish" }, heb: { code: "he", region: "middle-east", name: "Hebrew"
var h = new Set(Object.entries(u).filter((a) => m === "normal" || m === "light" && !a[1].skipLight).map((a) => a[0]));
var k = [...h.values()];
var B0 = Object.fromEntries(k.map((a, i) => [a, i + 1]));
var L = Object.fromEntries(k.map((a, i) => [i + 1, a]));
function D(a) {
return a in u ? u[a].code : a;
}
var w = "tinyld-dict";
var f = { " 'e": "1SJZ", " 'e'": "1SN2", " 'e' ": "1SSG", " 'ej ": "1SDV", " 'n": "019Z", " 'n ": "01JZ", " 'o": "1SBG", " 'oh": "1SF6", " 'oh ": "1SJ4", " 'y": "0D05", " aan": "01810SAG", " aan ": "013S0SAC", " aang": "01200S19", " aban": "030804BX0L0E0M030O0H0P2T0Q091608", " abb": "0N020R4J1516", " abbi": "0R3C", " abe": "030K0L020N3B0O040Q0G0U0R0Z0A10041C0E1P02", " abou": "0M4G", " aby": "0V5D0Z5D1B0P", " aby ": "0V3Z0Z6N1B0Z", " acc": "03020L1Q0M0X0O0Q0P0P0R1Y0S060U2H10041106161H", " ace": "030U0O180Q0S0U0C16EH1G0B", " acea": "167K", " aces": "0Q06169H", " ach": "0L1R0M030N0H0Q3X0S190T2A0U0A1B02", " ach ": "0N060T901B02", " acho": "0Q35", " aco": "0O0Z0P190Q2P162R", " ad ": "03SG0R1V0U9S100C15061Q1N", " ada ": "0BBV", " adal": "0BC01G04", " adam": "03040L020U071G221O681P02", " ae": "0O040Q040R050U330W06160C1C041D1Y1P04", " af ": "011B0S1A109L147M", " ag ": "0TK5", " aga ": "03041D4Y", " agam": "03020B0B0TQX0U03", " agat": "030504220TE7", " agor": "0Q2O", " agra": "03030L020O0Q0P3C0Q0M1P0D", " agu": "03050O1G0Q080T8W1P02", " agus": "03070TQC", " aho": "04620O2A0V020Z0C151H", " aho ": "04AF", " ahor": "0O2W", " ai ": "0L140R0N1204167B", " aici": "0T4L1655", " aik": "12591C02", " aika": "12A7", " ain": "0L0G0Q2H0T140U0312341D1Q", " aind": "0Q35", " air": "0B130L040M0C0O0B0S020T3N", " aiu": "0R35", " aiut": "0R37", " aix": "0P5G", " aix\xF2": "0P6A", " aiz": "1E6B", " aju": "0O020P1T0Q2C164K", " ajud": "0P2J0Q2X", " aka": "030K046V0B9I0D0D15891G02", " akan": "03050BGT", " akar": "0302042Z158F", " akin": "0D4I15091C0P", " akk": "037Q0S04130H1528", " akke": "038M", " ako": "041O0D7L0V030W1K0Z9D1P07", " ako ": "0DB70W400ZBF", " akon": "0D2W", " aku": "030I041G0BLH11021B021P08", " aku ": "0BSG", " ala ": "031O12081ROQ", " alam": "03040B0L0D3212031G0B", " ald": "0Q02101W111Z132L141R1G2D1O2I1P07", " aldr": "1023111Z132D143F", " ale ": "0V4D0Z2X16101B3S1R6W", " algo": "0O320Q1I", " algu": "0O3O0P3B0Q4T", " ali ": "0Q0G0W4S1G1G1R2C", " all ": "0M470N0A1104130A1D1L", " allt": "0N02113F131M1467", " als": "03020M0B0N4T0P2B0S7T150J", " als ": "0N7I0P3E0S7J", " alt ": "0N0P0P0Q1020132316061G03", " alti": "0R020S2D0U0C101O12041P05", " am ": "031S0M0W0N1V16FN", " amb ": "0PEC", " amic": "0L030P350R3M0U3F", " amit": "0L030U0B153O", " an ": "0L050M2M0N4P0TSG0U1511021305160H1G0B", " anar": "03040P4L", " anc": "0L080M030O0A0Q020R4J0U0J1G09", " anco": "0R31", " and ": "0MG21002", " anda": "03510BB30O0I0Q0N0R9M11051G0P", " ande": "011H0N340Q040S2H101J1102", " andi": "0R3U", " ang ": "0DSG", " ann ": "0TDE1B04", " anno": "0L070M070R0G0U2W1106120K", " ano ": "0D1S0Q0Z0V0M", " anoi": "0T8B", " anon": "0D2D1P06", " anse": "0N040T9H10021104", " ant ": "1C53", " any": "03020M3Y0P2Q152D", " anys": "0P3E", " ao": "0Q430T3Z", " ao ": "0Q44", " aon": "0Q060T4G", " aon ": "0TCR", " apa ": "0BHE150A160I", " apak": "0B92", " api": "03030B0C0U0312041C431R02", " apie": "1C8B", " aq": "032O0O2F0P9X0Q4B0U1J", " aqu": "03040O3P0PE30Q580U2V", " aqua": "0U2I", " aque": "0O140PGL0Q1R", " aqui": "0Q4Z0U09", " aqu\xED": "0O3Q0P3Z", " ar ": "030G0Q070TED164L1CEK1E8C", " ara ": "03SG0P381G0B", " araw": "0D22", " arbe": "0N370S03102J111K131I", " are": "03050M720O040Q040R0I0U07165H1B041C031P05", " are ": "0M89166X", " ari ": "04BR", " arka": "12021G3V", " arma": "030N0O0F0Q0D0R020U0O110516091D73", " arri": "0L370M0H0O090P3I0Q030R1H0S02", " arv": "0U031002121B1D4B", " arva": "0U03120O1DAG", " ar\u012B ": "1E50", " as ": "014I0L1U0M3Z0Q6E0T2Y", " ase": "03DL0O0I1215160R1P06", " aseg": "03LC0O0A", " asse": "012L030A0L1O0M020P170Q060R090U06", " asta": "16D4", " at ": "03030D420M4L0S080U0I10L713991G051Q4X", " ats": "1C6F1E1N", " atsi": "1C8P", " att": "030D0L2J0M0P0N020R1L0U0M100711L01305150F1E0S1G0D", " att ": "11KY", " at\xE1": "0T4V", " at\xE1 ": "0THE", " au ": "0L6C166B", " audi": "0L030M030O030Q020U2C", " auf": "0N8Q0U07", " auf ": "0NAP", " aus ": "0N5O", " aute": "0L030S030U2A0V08", " av ": "116113B5", " ave": "0L880M020O0H0Q080R6X0U0M163Z1P06", " avec": "0L9F", " avet": "0R33", " avez": "0L4A", " avo": "0L3G0M040S0I120616091P04", " aw": "032T0B0D0D030M0J1B021O2T1
var q = { " 'ac": "1s", " 'ar ": "1s", " 'iv ": "1s", " 'k": "1p", " 'op ": "1s", " aast": "1d", " acea": 16, " acho": "q", " acue": "o", " ac\xED": "p", " adev": 16, " adiu": "u", " aed": "u", " afis": 4, " aftu": 14, " ag ": "t", " ahir": "p", " aho ": 4, " ah\xED": "o", " aige": "t", " aika": 12, " aina": 12, " aind": "q", " aith": "t", " aiu": "r", " aix": "p", " aiz": "1e", " ajat": 12, " ajn": "1p", " ajut": 16, " ak-": 3, " aker": 3, " akh": "b", " akk ": 3, " akka": 3, " akke": 3, " akon": "d", " aku ": "b", " akvo": "1p", " ak\xE9": "z", " ak\xFD": "z", " alcu": "r", " aldy": "1o", " ald\u0131": "1g", " all\xE9": "l", " all\xF2": "p", " alst": "s", " alwa": "m", " amb ": "p", " amek": 3, " an-": "t", " anco": "r", " andi": "r", " ang ": "d", " anos": "q", " anys": "p", " anyt": "m", " aon ": "t", " aos": "q", " apak": "b", " apie": "1c", " apik": "1r", " apsi": "1c", " aql": 3, " araw": "d", " art\u0131": "1g", " as-d": 3, " ascu": 16, " asel": 3, " asij": "1r", " ass-": 3, " as\xED": "o", " atau": "b", " atb": "1e", " atc": "1e", " atid": "1c", " atq": "u", " atsi": "1c", " att ": 11, " at\xE1": "t", " at\xE9": "q", " auch": "n", " aucu": "l", " auf ": "n", " auj": "l", " aus ": "n", " autr": "l", " aux ": "l", " auz": 16, " avem": 16, " avet": "r", " avez": "l", " avre": "r", " avui": "p", " awst": "1o", " ayah": "b", " ayen": 3, " ayer": "o", " azt ": 15, " a\xED": "q", " a\xFA": "o", " a\u0161": "1c", " a\u0165": "v", " bahw": "b", " bao": "a", " bar\xE1": 15, " be'": "1s", " bem ": "q", " berh": "b", " ber\xE4": 11, " bhe": "t", " bij ": "s", " biq": "1s", " bizt": 15, " bje": 10, " bk": "1p", " ble ": 13, " blei": "n", " blij": "s", " bly ": 1, " boa ": "q", " bolm": "1o", " book": "m", " bp": "t", " bunu": "1g", " bv": "1p", " bw": 4, " bylo": "v", " byr": 14, " bys ": "v", " b\xE3": "a", " b\xE4rd": "1o", " b\xE9o ": "a", " b\xED ": "a", " b\xF3n": "a", " b\u0113": "1e", " b\u0119": "1b", " b\u0131": "1g", " b\u016Bs ": "1e", " cad ": "t", " cael": "u", " cal ": "p", " can'": "m", " cao ": "a", " cauz": 16, " cea ": 16, " cean": "t", " cee": 16, " ces ": "l", " cet ": "l", " cett": "l", " cha ": "a", " chaw": "1s", " chay": "1s", " chez": "l", " chli": "z", " cho ": "a", " cho\u010F": "z", " cht": "v", " chui": "t", " ch\xE9i": "t", " ch\xED": "a", " ch\xF3 ": "a", " cida": "q", " cieb": "1b", " cik ": "1e", " citt": "r", " citu": "1e", " ciut": "p", " coci": "o", " cs": 15, " cu ": 16, " cual": "o", " cung": "a", " cuno": 16, " cur ": "u", " c\xE1c": "a", " c\xE1i": "a", " c\xE1m ": "a", " c\xE9 ": "t", " c\xE9a": "t", " c\xE9n ": "t", " c\xE9u": "q", " c\xF2": "a", " c\xF3 ": "a", " c\xF3m": "o", " c\xF4 ": "a", " c\xFAm ": "a", " d-a": 3, " d-i": 3, " d-n": 3, " d-s": 3, " d-t": 3, " d-u": 3, " d-y": 3, " dagh": "1s", " dah ": "1s", " daja": "1s", " dakk": 3, " dal\u0161": "v", " dary": "1c", " daso": "1s", " dass": "n", " daud": "1e", " da\u015F": "1o", " dcer": "v", " ddan": 3, " ddu": 3, " dels": "p", " dezi": "1p", " dhe": "t", " dh\xE1": "t", " dh\xE9": "t", " did ": "m", " dije": "o", " dijo": "o", " dios": "o", " dirb": "1c", " dla ": "1b", " dled": "1q", " dlin": "1q", " dlo": "v", " doe ": "s", " does": "m", " dogt": 1, " doin": "m", " doit": "l", " dok ": "w", " dovu": "r", " dret": "p", " dric": 11, " dro ": 13, " dt": "t", " duj ": "1s", " durc": "n", " dusa": "1s", " duu": "s", " dver": "z", " dvi": "1c", " dyb": 10, " dze": "1e", " dzim": "1e", " d\xE2n": "a", " d\xE4l": "1o", " d\xE4r ": 11, " d\xE8": "l", " d\xE9s": "l", " d\xE9t": "l", " d\xEDt": "v", " d\xF4": "z", " d\xF6d": 11, " d\u0131": "1g", " eac": "m", " eam": "u", " eat": "m", " ebl": "1p", " edzi": "1p", " eens": "s", " eest": "1d", " ef ": 14, " efti": 14, " egy ": 15, " eie ": 1, " eigi": 14, " eine": "n", " eiti": "1c", " eitt": 14, " eiu": "u", " ek'": 1, " ekd": "1p", " ekke": 14, " ekki": 14, " ell ": "p", " ells": "p", " el\xE4": 12, " el\xE9g": 15, " ema ": "1d", " ents": "n", " eo ": "u", " eor": "u", " eos": "u", " epa": "1r", " epel": "1r", " eple": 13, " erat": "u", " erg ": "s", " erti": "1o", " ertu": 14, " e
var g = { id: w, multiples: f, uniques: q };
var X = /[.,,、。!¿?":;()「」{}„“«»”"“<>⋯《》*]+/;
var x = /[ ]+/;
function _(a) {
return a.split(X);
}
function $(a) {
return a.split(x);
}
function c(a, i, n = true) {
let o = [], t = n ? " ".repeat(i - 1) + a + " ".repeat(i - 1) : a;
for (let s = 0; s < t.length - (i - 1); s++) {
let r = [], l = 0;
for (let e = 0; e < i; e++)
t[s + e] === " " ? l += 1 : l = 0, !(l > 1) && r.push(t[s + e]);
let O = r.join("");
O.trim().length > 0 && O.length === i && o.push(O);
}
return o;
}
function a0(a, i, n, o) {
for (let t of G) {
let s = c(a, t);
o.verbose && console.log(`[Pass 1] detectUniqueGrams of ${t}-grams`, s);
for (let r of s) {
if (!n.has(r))
continue;
let l = D(i.uniques[r]);
if (!(o.only.length > 0 && !o.only.includes(l)))
return o.verbose && console.log(`- match '${r}' to ${l}`), l;
}
}
return "";
}
function e0(a, i, n) {
let o = new Map(), t = G.map((e) => c(a, e)).flat();
n.verbose && console.log("[Pass 2] DetectPotentialGrams", a, t);
let s = new Set([...h.values()].filter((e) => n.only.length > 0 ? n.only.includes(e) || n.only.includes(D(e)) : true));
s.forEach((e) => o.set(e, 0));
for (let e of t) {
let B = U(e), M = i.multiples[B];
if (!M)
continue;
let P = new Set(Object.keys(M)), N = [];
for (let A of s)
P.has(A) && (o.set(A, (o.get(A) || 0) + M[A] * B.length / 4), N.push(`${A} = ${M[A] / 1024 * 100}%`));
n.verbose && N.length > 0 && console.log(`Gram '${B}'`, N);
}
let r = [...o.entries()];
r.sort((e, B) => B[1] - e[1]);
let l = Math.max(...r.map((e) => e[1])) || 1, O = r.slice(0, 8).map((e) => ({ lang: D(e[0]), accuracy: 1 - Q((l - e[1]) / l), score: Q(e[1]) }));
return n.verbose && console.log("Result", a, O), O;
}
function b(a, i, n, o) {
let t = _(a);
t = t.map((e) => W(e)).filter((e) => !!e), t.sort((e, B) => B.length - e.length), t = t.slice(0, 3);
let s = 0, r = {};
for (let e of t) {
let B = a0(e, n, o, i);
if (B) {
r[B] = (r[B] || 0) + 1 * e.length, s += e.length;
continue;
}
let M = $(e);
for (let P of M)
e0(P, n, i).forEach((A) => {
r[A.lang] = (r[A.lang] || 0) + A.accuracy;
}), s += P.length;
}
let l = Object.entries(r).filter((e) => e[1] > 0);
l.sort((e, B) => B[1] - e[1]);
let O = l.map((e) => ({ lang: e[0], accuracy: e[1] / s }));
return i.verbose && console.log("Merge Results", O), O;
}
var Z = g;
var i0 = { uniques: Object.fromEntries(Object.entries(Z.uniques).map((a) => [a[0], L[parseInt(a[1].toString(), 36)]])), multiples: Object.fromEntries(Object.entries(Z.multiples).map((a) => {
var _a;
let i = Object.fromEntries(((_a = a[1].match(/(.{1,4})/g)) == null ? void 0 : _a.map((n) => {
let [o, t] = n.match(/(.{1,2})/g);
return [L[parseInt(o, 36)], parseInt(t, 36)];
})) || []);
return [a[0], i];
})) };
var n0 = new Set(Object.keys(g.uniques));
function h0(a, i) {
let n = o0(a, i);
return n.length > 0 ? n[0].lang : "";
}
function o0(a, i) {
let n = E(i);
return V(a) ? b(a, n, i0, n0) : [];
}
// src/TTSService.ts
var TTSService = class {
constructor(plugin) {
this.plugin = plugin;
}
stop() {
if (!this.isSpeaking())
return;
window.speechSynthesis.cancel();
}
pause() {
if (!this.isSpeaking())
return;
window.speechSynthesis.pause();
}
resume() {
if (!this.isSpeaking())
return;
window.speechSynthesis.resume();
}
isSpeaking() {
return window.speechSynthesis.speaking;
}
isPaused() {
return window.speechSynthesis.paused;
}
sayWithVoice(title, text, voice) {
return __async(this, null, function* () {
let content = text;
if (!this.plugin.settings.speakSyntax) {
content = content.replace(/#/g, "");
content = content.replace(/-/g, "");
content = content.replace(/_/g, "");
content = content.replace(/\*/g, "");
content = content.replace(/\^/g, "");
content = content.replace(/==/g, "");
content = content.replace(/^\S{6}/g, "");
}
if (!this.plugin.settings.speakLinks) {
content = content.replace(/(?:__|[*#])|\[(.*?)]\(.*?\)/gm, "$1");
}
if (!this.plugin.settings.speakCodeblocks) {
content = content.replace(/```[\s\S]*?```/g, "");
}
if (!this.plugin.settings.speakComments) {
content = content.replace(/%[\s\S]*?%/g, "");
content = content.replace(/<!--[\s\S]*?-->/g, "");
}
if (!this.plugin.settings.speakEmoji) {
content = content.replace(/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g, "");
}
content = content.replace(/\n/g, " ! ");
content = content.replace(/\[\[(.*\|)(.*)]]/gm, "$2");
if (this.plugin.settings.speakTitle && (title == null ? void 0 : title.length) > 0) {
content = title + " ! ! " + content;
}
const msg = new SpeechSynthesisUtterance();
msg.text = content;
msg.volume = this.plugin.settings.volume;
msg.rate = this.plugin.settings.rate;
msg.pitch = this.plugin.settings.pitch;
msg.voice = window.speechSynthesis.getVoices().filter((otherVoice) => otherVoice.name === voice)[0];
window.speechSynthesis.speak(msg);
this.plugin.statusbar.setText("TTS: speaking");
});
}
getVoice(languageCode) {
const filtered = this.plugin.settings.languageVoices.filter((lang) => lang.language === languageCode);
if (filtered.length === 0)
return null;
return filtered[0].voice;
}
say(title, text, languageCode) {
return __async(this, null, function* () {
let usedVoice = this.plugin.settings.defaultVoice;
if (languageCode && languageCode.length !== 0) {
const voice = this.getVoice(languageCode);
if (voice) {
usedVoice = voice;
} else {
new import_obsidian4.Notice("TTS: could not find voice for language " + languageCode + ". Using default voice.");
}
}
yield this.sayWithVoice(title, text, usedVoice);
});
}
play(view) {
return __async(this, null, function* () {
const isPreview = view.getMode() === "preview";
let previewText = view.previewMode.containerEl.innerText;
const selectedText = view.editor.getSelection().length > 0 ? view.editor.getSelection() : window.getSelection().toString();
let content = selectedText.length > 0 ? selectedText : view.getViewData();
if (isPreview) {
content = previewText;
}
const title = selectedText.length > 0 ? null : view.getDisplayText();
let language = this.getLanguageFromFrontmatter(view);
if (language === "") {
language = h0(content);
}
if (!this.plugin.settings.speakFrontmatter) {
if (!isPreview) {
content = content.replace("---", "");
content = content.substring(content.indexOf("---") + 1);
}
}
yield this.say(title, content, language);
});
}
getLanguageFromFrontmatter(view) {
let language = "";
if (!view.getViewData().startsWith("---"))
return language;
const frontmatter = view.getViewData().match(/---[\s\S]*?---/);
if (frontmatter && frontmatter[0]) {
const parsedFrontmatter = (0, import_obsidian4.parseYaml)(frontmatter[0].replace(/---/g, ""));
if (parsedFrontmatter["lang"]) {
language = parsedFrontmatter["lang"];
}
}
return language;
}
};
// src/main.ts
var TTSPlugin = class extends import_obsidian5.Plugin {
onload() {
return __async(this, null, function* () {
this.ttsService = new TTSService(this);
console.log("loading tts plugin");
if (import_obsidian5.Platform.isAndroidApp) {
new import_obsidian5.Notice("TTS: due to a bug in android this plugin does not work on this platform");
this.unload();
}
yield this.loadSettings();
this.addCommand({
id: "start-tts-playback",
name: "Start playback",
checkCallback: (checking) => {
const markdownView = this.app.workspace.getActiveViewOfType(import_obsidian5.MarkdownView);
if (!checking && markdownView)
this.ttsService.play(markdownView);
return !!markdownView;
}
});
this.addCommand({
id: "cancel-tts-playback",
name: "Stop playback",
checkCallback: (checking) => {
if (!checking)
this.ttsService.stop();
return this.ttsService.isSpeaking();
}
});
this.addCommand({
id: "pause-tts-playback",
name: "pause playback",
checkCallback: (checking) => {
if (!checking)
this.ttsService.pause();
return this.ttsService.isSpeaking();
}
});
this.addCommand({
id: "resume-tts-playback",
name: "Resume playback",
checkCallback: (checking) => {
if (!checking)
this.ttsService.resume();
return this.ttsService.isPaused();
}
});
this.registerInterval(window.setInterval(() => {
if (!this.ttsService.isSpeaking()) {
this.statusbar.setText("TTS");
}
}, 1e3 * 10));
this.addRibbonIcon("audio-file", "Text to Speech", (event) => __async(this, null, function* () {
yield this.createMenu(event);
}));
this.registerEvent(this.app.workspace.on("editor-menu", (menu, _2, markdownView) => {
menu.addItem((item) => {
item.setTitle(window.getSelection().toString().length > 0 ? "Read selected text" : "Read the note").setIcon("audio-file").onClick(() => {
this.ttsService.play(markdownView);
});
});
}));
this.registerEvent(this.app.workspace.on("layout-change", () => {
if (this.settings.stopPlaybackWhenNoteChanges) {
this.ttsService.stop();
}
}));
this.addSettingTab(new TTSSettingsTab(this));
this.statusbar = this.addStatusBarItem();
this.statusbar.setText("TTS");
this.statusbar.classList.add("mod-clickable");
this.statusbar.setAttribute("aria-label", "Text to Speech");
this.statusbar.setAttribute("aria-label-position", "top");
this.statusbar.onClickEvent((event) => __async(this, null, function* () {
yield this.createMenu(event);
}));
});
}
createMenu(event) {
return __async(this, null, function* () {
const menu = new import_obsidian5.Menu(this.app);
const markdownView = this.app.workspace.getActiveViewOfType(import_obsidian5.MarkdownView);
if (markdownView) {
if (window.speechSynthesis.speaking) {
menu.addItem((item) => {
item.setIcon("play-audio-glyph").setTitle("Add to playback queue").onClick(() => __async(this, null, function* () {
yield this.ttsService.play(markdownView);
}));
});
} else {
yield this.ttsService.play(markdownView);
return;
}
}
if (window.speechSynthesis.speaking) {
menu.addItem((item) => {
item.setIcon("stop-audio-glyph").setTitle("Stop").onClick(() => __async(this, null, function* () {
this.ttsService.stop();
}));
});
if (window.speechSynthesis.paused) {
menu.addItem((item) => {
item.setIcon("play-audio-glyph").setTitle("Resume").onClick(() => __async(this, null, function* () {
this.ttsService.resume();
}));
});
} else {
menu.addItem((item) => {
item.setIcon("paused").setTitle("Pause").onClick(() => __async(this, null, function* () {
this.ttsService.pause();
}));
});
}
}
menu.showAtPosition({ x: event.x, y: event.y });
});
}
onunload() {
return __async(this, null, function* () {
console.log("unloading tts plugin");
});
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
};