Skip to content

Commit

Permalink
Add fetchPresets
Browse files Browse the repository at this point in the history
  • Loading branch information
ryunix committed Sep 17, 2023
1 parent 8d0c301 commit b945e90
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RestAPI } from "./rest";
import { audioQuery } from "./audio_query";
import { preset } from "./preset";

// voicevox client
/**
Expand Down Expand Up @@ -67,4 +68,10 @@ export class Client {
);
return new audioQuery(this.rest, audioquery);
}

// Fetch presets
async fetchPresets(): Promise<preset[]> {
let presets = await this.rest.getPresets();
return presets.map((x) => new preset(x));
}
}
28 changes: 28 additions & 0 deletions src/preset.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
createAudioQueryOptions,
createAudioQueryFromPresetOptions,
} from "./types/audioquery";
import { preset } from "./types/preset";
import { synthesisParams } from "./types/synthesis";

type fetchOptions = {
Expand Down Expand Up @@ -92,4 +93,8 @@ export class RestAPI {
params: params,
});
}

async getPresets(): Promise<preset[]> {
return await this.request("GET", "/presets");
}
}
12 changes: 12 additions & 0 deletions src/types/preset.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b945e90

Please sign in to comment.