Skip to content

Commit 84c580a

Browse files
authored
Merge pull request #46 from ryunix/add-fetch-presets
2 parents 5dbf773 + b945e90 commit 84c580a

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RestAPI } from "./rest";
22
import { audioQuery } from "./audio_query";
3+
import { preset } from "./preset";
34

45
// voicevox client
56
/**
@@ -67,4 +68,10 @@ export class Client {
6768
);
6869
return new audioQuery(this.rest, audioquery);
6970
}
71+
72+
// Fetch presets
73+
async fetchPresets(): Promise<preset[]> {
74+
let presets = await this.rest.getPresets();
75+
return presets.map((x) => new preset(x));
76+
}
7077
}

src/preset.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { preset as presetT } from "./types/preset";
2+
3+
// preset
4+
export class preset {
5+
public id: number;
6+
public name: string;
7+
public speaker_uuid: string;
8+
public style_id: number;
9+
public speedScale: number;
10+
public pitchScale: number;
11+
public intonationScale: number;
12+
public volumeScale: number;
13+
public prePhonemeLength: number;
14+
public postPhonemeLength: number;
15+
16+
constructor(preset: presetT) {
17+
this.id = preset.id;
18+
this.name = preset.name;
19+
this.speaker_uuid = preset.speaker_uuid;
20+
this.style_id = preset.style_id;
21+
this.speedScale = preset.speedScale;
22+
this.pitchScale = preset.pitchScale;
23+
this.intonationScale = preset.intonationScale;
24+
this.volumeScale = preset.volumeScale;
25+
this.prePhonemeLength = preset.prePhonemeLength;
26+
this.postPhonemeLength = preset.postPhonemeLength;
27+
}
28+
}

src/rest.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createAudioQueryOptions,
44
createAudioQueryFromPresetOptions,
55
} from "./types/audioquery";
6+
import { preset } from "./types/preset";
67
import { synthesisParams } from "./types/synthesis";
78

89
type fetchOptions = {
@@ -21,19 +22,19 @@ export class RestAPI {
2122
async request(
2223
method: string,
2324
path: string,
24-
options: {
25+
options?: {
2526
body?: any;
2627
params?: any;
2728
}
2829
): Promise<any> {
2930
let url = this.engine_url + path;
30-
if (options.params) {
31+
if (options?.params) {
3132
url += "?" + new URLSearchParams(options.params).toString();
3233
}
3334
var fetch_options: fetchOptions = {
3435
method: method,
3536
};
36-
if (options.body) {
37+
if (options?.body) {
3738
fetch_options["headers"] = { "Content-Type": "application/json" };
3839
fetch_options["body"] = JSON.stringify(options.body);
3940
}
@@ -92,4 +93,8 @@ export class RestAPI {
9293
params: params,
9394
});
9495
}
96+
97+
async getPresets(): Promise<preset[]> {
98+
return await this.request("GET", "/presets");
99+
}
95100
}

src/types/preset.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export interface preset {
2+
id: number;
3+
name: string;
4+
speaker_uuid: string;
5+
style_id: number;
6+
speedScale: number;
7+
pitchScale: number;
8+
intonationScale: number;
9+
volumeScale: number;
10+
prePhonemeLength: number;
11+
postPhonemeLength: number;
12+
}

0 commit comments

Comments
 (0)