Skip to content

Commit

Permalink
~ some small code style fixes
Browse files Browse the repository at this point in the history
~ update readme
  • Loading branch information
joethei committed Dec 6, 2021
1 parent 6dd15bc commit 2b87992
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ You can use this plugins API to add Text to Speech capabilities to your plugin.
//@ts-ignore
if (this.app.plugins.plugins["obsidian-tts"]) {//check if the plugin is loaded
//@ts-ignore
const tts = this.app.plugins.plugins["obsidian-tts"];
const tts = this.app.plugins.plugins["obsidian-tts"].ttsService;
await tts.say(title, text, language);//language is optional, use a ISO 639-1 code
tts.pause();
tts.resume();
tts.stop();
tts.isSpeaking();
tts.isPaused();

tts.isPaused();
}
```
2 changes: 1 addition & 1 deletion src/LanguageVoiceModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class LanguageVoiceModal extends Modal {
.setName("Language")
.addDropdown(async (dropdown) => {

for (let languageCodeKey in languages.getAlpha2Codes()) {
for (const languageCodeKey in languages.getAlpha2Codes()) {
//@ts-ignore
const displayNames = new Intl.DisplayNames([languageCodeKey], {type: 'language', fallback: 'none'});
if(displayNames) {
Expand Down
13 changes: 4 additions & 9 deletions src/TTSService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,28 +94,23 @@ export class TTSService {

async play(view: MarkdownView): Promise<void> {
let content = view.getViewData();
let language: string;
let language = this.getLanguageFromFrontmatter(view);

//check if any language is defined in frontmatter
const frontmatter = content.match(/---[\s\S]*?---/);
if (frontmatter && frontmatter[0]) {
const parsedFrontmatter = parseYaml(frontmatter[0].replace(/---/g, ''));
if (parsedFrontmatter['lang']) {
language = parsedFrontmatter['lang'];
}
}
if (!this.plugin.settings.speakFrontmatter)
if (content.startsWith("---")) {
content = content.replace("---", "");
content = content.substring(content.indexOf("---") + 1);
}

await this.say(view.getDisplayText(), content, language);

}

getLanguageFromFrontmatter(view: MarkdownView) : string {
let language = "";
//check if any language is defined in frontmatter
if(!view.getViewData().startsWith("---")) return language;

const frontmatter = view.getViewData().match(/---[\s\S]*?---/);
if (frontmatter && frontmatter[0]) {
const parsedFrontmatter = parseYaml(frontmatter[0].replace(/---/g, ''));
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class TTSPlugin extends Plugin {
})));

this.registerEvent(this.app.workspace.on('layout-change', (() => {
if(this.settings.stopPlaybackWhenNoteClosed) {
if(this.settings.stopPlaybackWhenNoteChanges) {
this.ttsService.stop();
}
})));
Expand Down

0 comments on commit 2b87992

Please sign in to comment.