Skip to content

Commit

Permalink
Fix migration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joethei committed Feb 19, 2024
1 parent 884ade7 commit 8846f9f
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 70 deletions.
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.5.3",
"version": "0.5.4",
"minAppVersion": "1.4.0",
"description": "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
Expand Up @@ -16,7 +16,7 @@
"@cospired/i18n-iso-languages": "^3.1.1",
"@types/node": "^16.11.6",
"builtin-modules": "^3.2.0",
"obsidian": "0.15.2",
"obsidian": "1.4.11",
"tslib": "2.3.1",
"typescript": "4.4.4",
"tinyld": "1.2.3",
Expand Down
14 changes: 9 additions & 5 deletions src/LanguageVoiceModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import languages from "@cospired/i18n-iso-languages";

export class LanguageVoiceModal extends Modal {
plugin: TTSPlugin;
id: string;
language: string;
voice: string;

Expand All @@ -16,6 +17,7 @@ export class LanguageVoiceModal extends Modal {
this.plugin = plugin;

if(map) {
this.id = map.id;
this.language = map.language;
this.voice = map.voice;
}
Expand All @@ -24,6 +26,8 @@ export class LanguageVoiceModal extends Modal {
async display() : Promise<void> {
const { contentEl } = this;

const voices = await this.plugin.serviceManager.getVoices();

contentEl.empty();

//not know to rollup and webstorm, but exists in obsidian
Expand Down Expand Up @@ -55,14 +59,14 @@ export class LanguageVoiceModal extends Modal {
new Setting(contentEl)
.setName("Voice")
.addDropdown(async (dropdown) => {
const voices = window.speechSynthesis.getVoices();
for (const voice of voices) {
dropdown.addOption(voice.name, voice.name + " - " + languageNames.of(voice.lang));
dropdown.addOption(voice.service + "-" + voice.id, voice.name + " - " + languageNames.of(voice.languages[0]));
}
dropdown
.setValue(this.voice)
.setValue(this.id)
.onChange(async (value) => {
this.voice = value;
this.id = value;
this.voice = voices.filter(voice => voice.service + "-" + voice.id === value).first().name;
});
}).addExtraButton(button => {
button
Expand All @@ -72,7 +76,7 @@ export class LanguageVoiceModal extends Modal {
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");
await input.openAndGetValue((async value => {
if (value.getValue().length === 0) return;
await this.plugin.ttsService.sayWithVoice(value.getValue(), this.voice);
await this.plugin.serviceManager.sayWithVoice(value.getValue(), this.id);
}));


Expand Down
80 changes: 80 additions & 0 deletions src/ServiceManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {TTSService} from "./services/TTSService";
import TTSPlugin from "./main";
import {SpeechSynthesis} from "./services/SpeechSynthesis";
import {Notice} from "obsidian";

export class ServiceManager {
private readonly plugin: TTSPlugin;
private services: TTSService[] = [];

constructor(plugin: TTSPlugin) {
this.plugin = plugin;
this.services.push(new SpeechSynthesis(this.plugin));
//this.services.push(new OpenAI(this));
}

public getServices(): TTSService[] {
return this.services;
}

public isSpeaking(): boolean {
return this.services.some(service => service.isSpeaking());
}

public isPaused(): boolean {
return this.services.every(service => service.isPaused());
}

stop() : void {
for (const service of this.services) {
if(service.isSpeaking() || service.isPaused()) {
service.stop();
}
}
}

pause() : void {
for (const service of this.services) {
if(service.isSpeaking()) {
service.pause();
}
}
}

resume(): void {
for (const service of this.services) {
if(service.isPaused()) {
service.resume();
}
}
}

async sayWithVoice(text: string, voice: string): Promise<void> {
const service = this.services.filter(service => voice.startsWith(service.id)).first();
const split = voice.split("-");
split.shift();
voice = split.join("-");
if(!service) {
new Notice("No service found for voice" + voice);
}
await service.sayWithVoice(text, voice);

}

async getVoices() {
const voices = [];
for (const service of this.services) {
for (const voice of await service.getVoices()) {
voices.push({
service: service.id,
id: voice.id,
name: voice.name,
languages: voice.languages
});
}
}
return voices;
}


}
Loading

0 comments on commit 8846f9f

Please sign in to comment.