From b945e904c69d2766059c673e247598f783e588da Mon Sep 17 00:00:00 2001 From: ryunix Date: Mon, 18 Sep 2023 01:56:22 +0900 Subject: [PATCH] Add fetchPresets --- src/client.ts | 7 +++++++ src/preset.ts | 28 ++++++++++++++++++++++++++++ src/rest.ts | 5 +++++ src/types/preset.ts | 12 ++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 src/preset.ts create mode 100644 src/types/preset.ts diff --git a/src/client.ts b/src/client.ts index 4d37cdf..df996c4 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,5 +1,6 @@ import { RestAPI } from "./rest"; import { audioQuery } from "./audio_query"; +import { preset } from "./preset"; // voicevox client /** @@ -67,4 +68,10 @@ export class Client { ); return new audioQuery(this.rest, audioquery); } + + // Fetch presets + async fetchPresets(): Promise { + let presets = await this.rest.getPresets(); + return presets.map((x) => new preset(x)); + } } diff --git a/src/preset.ts b/src/preset.ts new file mode 100644 index 0000000..fdea368 --- /dev/null +++ b/src/preset.ts @@ -0,0 +1,28 @@ +import { preset as presetT } from "./types/preset"; + +// preset +export class preset { + public id: number; + public name: string; + public speaker_uuid: string; + public style_id: number; + public speedScale: number; + public pitchScale: number; + public intonationScale: number; + public volumeScale: number; + public prePhonemeLength: number; + public postPhonemeLength: number; + + constructor(preset: presetT) { + this.id = preset.id; + this.name = preset.name; + this.speaker_uuid = preset.speaker_uuid; + this.style_id = preset.style_id; + this.speedScale = preset.speedScale; + this.pitchScale = preset.pitchScale; + this.intonationScale = preset.intonationScale; + this.volumeScale = preset.volumeScale; + this.prePhonemeLength = preset.prePhonemeLength; + this.postPhonemeLength = preset.postPhonemeLength; + } +} diff --git a/src/rest.ts b/src/rest.ts index 0ddb993..b2f14bc 100644 --- a/src/rest.ts +++ b/src/rest.ts @@ -3,6 +3,7 @@ import { createAudioQueryOptions, createAudioQueryFromPresetOptions, } from "./types/audioquery"; +import { preset } from "./types/preset"; import { synthesisParams } from "./types/synthesis"; type fetchOptions = { @@ -92,4 +93,8 @@ export class RestAPI { params: params, }); } + + async getPresets(): Promise { + return await this.request("GET", "/presets"); + } } diff --git a/src/types/preset.ts b/src/types/preset.ts new file mode 100644 index 0000000..9501a46 --- /dev/null +++ b/src/types/preset.ts @@ -0,0 +1,12 @@ +export interface preset { + id: number; + name: string; + speaker_uuid: string; + style_id: number; + speedScale: number; + pitchScale: number; + intonationScale: number; + volumeScale: number; + prePhonemeLength: number; + postPhonemeLength: number; +}