diff --git a/src/client.ts b/src/client.ts index 658e0af..64d75ea 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,6 +1,7 @@ import { RestAPI } from "./rest"; import { audioQuery } from "./audio_query"; import { Preset } from "./preset"; +import { Speaker } from "./speaker"; // voicevox client /** @@ -103,4 +104,13 @@ export class Client { async deletePreset(id: number): Promise { return await this.rest.deletePreset(id); } + + // Fetch speakers + /** + * @returns Speakers + */ + async fetchSpeakers(): Promise { + let speakers = await this.rest.getSpeakers(); + return speakers.map((x) => new Speaker(x)); + } } diff --git a/src/rest.ts b/src/rest.ts index a10de78..6a5bda0 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -4,6 +4,7 @@ import { createAudioQueryFromPresetOptions, } from "./types/audioquery"; import { Preset, DeletePresetOptions } from "./types/preset"; +import { Speaker } from "./types/speaker"; import { synthesisParams } from "./types/synthesis"; type fetchOptions = { @@ -118,4 +119,8 @@ export class RestAPI { params: params, }); } + + async getSpeakers(): Promise { + return await this.request("GET", "/speakers"); + } } diff --git a/src/speaker.ts b/src/speaker.ts new file mode 100644 index 0000000..07e4683 --- /dev/null +++ b/src/speaker.ts @@ -0,0 +1,18 @@ +import { Speaker as SpeakerT, Styles, SupportedFeatures } from "./types/speaker"; + +// speaker +export class Speaker { + public name: string; + public speaker_uuid: string; + public styles: Styles[]; + public version: string; + public supported_features: SupportedFeatures; + + constructor(speaker: SpeakerT) { + this.name = speaker.name; + this.speaker_uuid = speaker.speaker_uuid; + this.styles = speaker.styles; + this.version = speaker.version; + this.supported_features = speaker.supported_features; + } +} diff --git a/src/types/speaker.ts b/src/types/speaker.ts new file mode 100644 index 0000000..4add250 --- /dev/null +++ b/src/types/speaker.ts @@ -0,0 +1,19 @@ +export type StyleType = "talk" | "singing_teacher" | "frame_decode" | "sing"; + +export interface Styles { + id: number; + name: string; + type: string; +} + +export interface SupportedFeatures { + permitted_synthesis_morphing: "ALL" | "SELF_ONLY" | "NOTHING" +} + +export interface Speaker { + name: string; + speaker_uuid: string; + styles: Styles[]; + version: string; + supported_features: SupportedFeatures; +} \ No newline at end of file diff --git a/tests/speakers.ts b/tests/speakers.ts new file mode 100644 index 0000000..2ebba78 --- /dev/null +++ b/tests/speakers.ts @@ -0,0 +1,11 @@ +import assert from "assert"; +import Client from "../dist"; + +const client = new Client("http://127.0.0.1:50021"); + +async function main() { + const speakers = await client.fetchSpeakers(); + assert(speakers.length > 0); +} + +main();