Skip to content

Commit

Permalink
Made changes requested per PR comments here: obsidianmd/obsidian-rele…
Browse files Browse the repository at this point in the history
  • Loading branch information
travisvn committed Nov 6, 2024
1 parent d87eca7 commit a6b28a5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 55 deletions.
4 changes: 2 additions & 2 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import process from "process";
import builtins from "builtin-modules";

const banner =
`/*
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
Expand All @@ -15,7 +15,7 @@ const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.ts"],
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "edge-tts",
"name": "Edge TTS",
"version": "1.0.3",
"version": "1.0.4",
"minAppVersion": "0.15.0",
"description": "Read notes aloud using Microsoft Edge Read Aloud API (free, high quality text-to-speech).",
"author": "Travis",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-edge-tts",
"version": "1.0.3",
"version": "1.0.4",
"description": "This is a TTS plugin for Obsidian (https://obsidian.md).",
"main": "main.js",
"scripts": {
Expand Down
78 changes: 34 additions & 44 deletions main.ts → src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Plugin, MarkdownView, Notice, PluginSettingTab, Setting } from 'obsidian';
import { Plugin, MarkdownView, Notice, PluginSettingTab, Setting, Editor, MarkdownFileInfo } from 'obsidian';
import { EdgeTTSClient, OUTPUT_FORMAT } from 'edge-tts-client';
import { filterMarkdown } from 'utils';
import { filterMarkdown } from 'src/utils';

// Top voices to be displayed in the dropdown
const TOP_VOICES = [
Expand All @@ -20,14 +20,12 @@ const TOP_VOICES = [
interface EdgeTTSPluginSettings {
selectedVoice: string;
customVoice: string;
showRibbonIcon: boolean;
showNotices: boolean;
}

const DEFAULT_SETTINGS: EdgeTTSPluginSettings = {
selectedVoice: 'en-US-ChristopherNeural',
customVoice: '',
showRibbonIcon: true,
showNotices: false,
};

Expand All @@ -37,24 +35,25 @@ export default class EdgeTTSPlugin extends Plugin {
audioContext: AudioContext | null = null;

async onload() {
console.log('Loading Obsidian Edge TTS Plugin');
if (process.env.NODE_ENV === 'development') {
console.log('Loading Obsidian Edge TTS Plugin');
}

// Load settings
await this.loadSettings();

// Add settings tab
this.addSettingTab(new EdgeTTSPluginSettingTab(this.app, this));

// Add the ribbon icon if enabled
if (this.settings.showRibbonIcon) {
this.addPluginRibbonIcon();
}
this.addPluginRibbonIcon();

// Add command to read notes aloud
this.addCommand({
id: 'read-note-aloud',
name: 'Read Note Aloud',
callback: () => this.readNoteAloud()
name: 'Read note aloud',
editorCallback: (editor, view) => {
this.readNoteAloud(editor, view);
}
});
}

Expand All @@ -63,7 +62,7 @@ export default class EdgeTTSPlugin extends Plugin {
this.ribbonIconEl.remove();
}

this.ribbonIconEl = this.addRibbonIcon('audio-lines', 'Read Note Aloud', () => {
this.ribbonIconEl = this.addRibbonIcon('audio-lines', 'Read note aloud', () => {
this.readNoteAloud();
});
}
Expand All @@ -75,10 +74,15 @@ export default class EdgeTTSPlugin extends Plugin {
}
}

async readNoteAloud() {
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
if (view) {
const editor = view.editor;
async readNoteAloud(editor?: Editor, viewInput?: MarkdownView | MarkdownFileInfo) {
// Fallback to active Markdown view if not provided
const view = viewInput ?? this.app.workspace.getActiveViewOfType(MarkdownView);

if (!editor && view) {
editor = view.editor;
}

if (editor && view) {
const selectedText = editor.getSelection() || editor.getValue();

if (selectedText.trim()) {
Expand Down Expand Up @@ -120,7 +124,9 @@ export default class EdgeTTSPlugin extends Plugin {
}
};

console.log('Audio playback started');
if (process.env.NODE_ENV === 'development') {
console.log('Audio playback started');
}
} catch (decodeError) {
console.error('Error decoding audio:', decodeError);
this.cleanupAudioContext();
Expand All @@ -145,6 +151,10 @@ export default class EdgeTTSPlugin extends Plugin {
new Notice('No text selected or available.');
}
}
} else {
if (this.settings.showNotices) {
new Notice('No active editor or Markdown view.');
}
}
}

Expand Down Expand Up @@ -182,11 +192,9 @@ class EdgeTTSPluginSettingTab extends PluginSettingTab {
const { containerEl } = this;
containerEl.empty();

containerEl.createEl('h2', { text: 'Edge TTS Plugin Options' });

// Add a text notice about sampling voices
const inbetweenInfo = containerEl.createEl('div', {
cls: 'inbetween-info-div'
cls: 'edge-tts-info-div'
})

const infoText = document.createElement('p');
Expand All @@ -200,7 +208,7 @@ class EdgeTTSPluginSettingTab extends PluginSettingTab {

// Dropdown for top voices
new Setting(containerEl)
.setName('Select Voice')
.setName('Select voice')
.setDesc('Choose from the top voices.')
.setClass('default-style')
.addDropdown(dropdown => {
Expand All @@ -225,7 +233,7 @@ class EdgeTTSPluginSettingTab extends PluginSettingTab {

// Text input for custom voice
new Setting(containerEl)
.setName('Custom Voice')
.setName('Custom voice')
.setDesc(patternFragment)
.addText(text => {
text.setPlaceholder('e.g., fr-FR-HenriNeural');
Expand All @@ -236,27 +244,9 @@ class EdgeTTSPluginSettingTab extends PluginSettingTab {
});
});

// Ribbon icon toggle setting
new Setting(containerEl)
.setName('Show Ribbon Icon')
.setDesc('Toggle the ribbon icon for quick access.')
.addToggle(toggle => {
toggle.setValue(this.plugin.settings.showRibbonIcon);
toggle.onChange(async (value) => {
this.plugin.settings.showRibbonIcon = value;
await this.plugin.saveSettings();

if (value) {
this.plugin.addPluginRibbonIcon();
} else {
this.plugin.removePluginRibbonIcon();
}
});
});

// Notice toggle setting
new Setting(containerEl)
.setName('Show Notices')
.setName('Show notices')
.setDesc('Toggle notices for processing status and errors.')
.addToggle(toggle => {
toggle.setValue(this.plugin.settings.showNotices);
Expand All @@ -266,10 +256,10 @@ class EdgeTTSPluginSettingTab extends PluginSettingTab {
});
});

const starContainer = containerEl.createEl('div', { cls: 'star-section' });
starContainer.createEl('h3', {
const starContainer = containerEl.createEl('div', { cls: 'edge-tts-star-section' });
starContainer.createEl('p', {
text: 'Please star this project on GitHub if you find it useful ⭐️',
cls: 'star-message'
cls: 'edge-tts-star-message'
});

starContainer.createEl('a', {
Expand Down
File renamed without changes.
17 changes: 11 additions & 6 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
.default-style {
text-align: left;
}

.setting-item-description {
.edge-tts-info-div {
padding-bottom: 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}

.inbetween-info-div {
.edge-tts-star-section {
padding-bottom: 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}

.edge-tts-star-message {
font-size: x-large;
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"1.0.0": "0.15.0",
"1.0.1": "0.15.0",
"1.0.2": "0.15.0",
"1.0.3": "0.15.0"
"1.0.3": "0.15.0",
"1.0.4": "0.15.0"
}

0 comments on commit a6b28a5

Please sign in to comment.