generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
166 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.