Skip to content

Commit

Permalink
+ added a option to ignore emojis
Browse files Browse the repository at this point in the history
~ better readme
  • Loading branch information
joethei committed Dec 8, 2021
1 parent 5b2a4b9 commit 18d5547
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ Plugin for [Obsidian](https://obsidian.md)
![GitHub](https://img.shields.io/github/license/joethei/obsidian-tts)
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
---
**This plugin is currently in beta**
Features:
- Start playback for note from statusbar and ribbon
- Only speaking selected text in edit mode:
![Selection Demo](https://i.joethei.space/Obsidian_rjttPsYPwj.png)
- usable with other plugins (currently [RSS Reader](https://github.com/joethei/obsidian-rss))

You can create language specific voices, which will be used when you have a note with
```lang: {languageCode}```
Expand All @@ -20,7 +24,6 @@ to [this bug in the Webview](https://bugs.chromium.org/p/chromium/issues/detail?
## Adding languages

This plugin uses the native API of your Operating System, to add a new language reference the documentation accordingly:

- [Windows 10](https://support.microsoft.com/en-us/topic/how-to-download-text-to-speech-languages-for-windows-10-d5a6b612-b3ae-423f-afa5-4f6caf1ec5d3)
- [MacOS](https://support.apple.com/guide/mac-help/change-the-system-language-mh26684/mac)
- [iOS](https://support.apple.com/guide/iphone/change-the-language-and-region-iphce20717a3/ios)
Expand All @@ -29,8 +32,7 @@ This plugin uses the native API of your Operating System, to add a new language

## Installing the plugin

<!--- `Settings > Third-party plugins > Community Plugins > Browse` and search for `Text to Speech`-->

- `Settings > Third-party plugins > Community Plugins > Browse` and search for `Text to Speech`
- Using the [Beta Reviewers Auto-update Tester](https://github.com/TfTHacker/obsidian42-brat) plugin with the repo
path: `joethei/obsidian-tts`
- Copy over `main.js`, `styles.css`, `manifest.json` from the releases to your
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": "obsidian-tts",
"name": "Text to Speech",
"version": "0.3.2",
"version": "0.3.3",
"minAppVersion": "0.12.0",
"description": "Text to speech for Obsidian. Hear your notes.",
"author": "Johannes Theiner",
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-tts",
"version": "0.3.2",
"version": "0.3.3",
"description": "Text to speech for Obsidian. Hear your notes.",
"main": "main.js",
"scripts": {
Expand Down
23 changes: 14 additions & 9 deletions src/TTSService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ export class TTSService {
}

stop(): void {
if(!this.isSpeaking()) return;
if (!this.isSpeaking()) return;
window.speechSynthesis.cancel();
}

pause(): void {
if(!this.isSpeaking()) return;
if (!this.isSpeaking()) return;
window.speechSynthesis.pause();
}

resume(): void {
if(!this.isSpeaking()) return;
if (!this.isSpeaking()) return;
window.speechSynthesis.resume();
}

isSpeaking() : boolean {
isSpeaking(): boolean {
return window.speechSynthesis.speaking;
}

isPaused() : boolean {
isPaused(): boolean {
return window.speechSynthesis.paused;
}

Expand All @@ -49,7 +49,12 @@ export class TTSService {
}

if (this.plugin.settings.speakTitle) {
content = title + " " + content;
content = title + " ! ! " + content;
}

if (!this.plugin.settings.speakEmoji) {
//regex from https://ihateregex.io/expr/emoji/
content = content.replace(/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/g, '');
}

//add pauses, taken from https://stackoverflow.com/a/50944593/5589264
Expand Down Expand Up @@ -94,7 +99,7 @@ export class TTSService {

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

if (!this.plugin.settings.speakFrontmatter)
if (content.startsWith("---")) {
Expand All @@ -106,10 +111,10 @@ export class TTSService {

}

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

const frontmatter = view.getViewData().match(/---[\s\S]*?---/);
if (frontmatter && frontmatter[0]) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class TTSPlugin extends Plugin {
this.addCommand({
id: 'start-tts-playback',
name: 'Start playback',
editorCallback: (editor, view) => {
editorCallback: (_, view) => {
this.ttsService.play(view);
}
});
Expand Down
13 changes: 13 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TTSSettings {
speakSyntax: boolean;
speakCodeblocks: boolean;
speakTitle: boolean;
speakEmoji: boolean;
languageVoices: LanguageVoiceMap[];
stopPlaybackWhenNoteChanges: boolean;
}
Expand All @@ -32,6 +33,7 @@ export const DEFAULT_SETTINGS: TTSSettings = {
speakSyntax: false,
speakTitle: true,
speakCodeblocks: false,
speakEmoji: false,
languageVoices: [],
stopPlaybackWhenNoteChanges: false,
}
Expand Down Expand Up @@ -272,6 +274,17 @@ export class TTSSettingsTab extends PluginSettingTab {
});
});

new Setting(containerEl)
.setName("Emoji")
.addToggle(async (toggle) => {
toggle
.setValue(this.plugin.settings.speakEmoji)
.onChange(async (value) => {
this.plugin.settings.speakEmoji = value;
await this.plugin.saveSettings();
});
});

containerEl.createEl("h2", {text: "Misc"});
new Setting(containerEl)
.setName("Stop playback when a note is closed/new note is opened")
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"0.1.0": "0.9.12",
"0.2.0": "0.9.12",
"0.3.2": "0.12.0"
"0.3.2": "0.12.0",
"0.3.3": "0.12.0"
}

0 comments on commit 18d5547

Please sign in to comment.