Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fetchPresets #46

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
11 changes: 8 additions & 3 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 All @@ -21,19 +22,19 @@ export class RestAPI {
async request(
method: string,
path: string,
options: {
options?: {
body?: any;
params?: any;
}
): Promise<any> {
let url = this.engine_url + path;
if (options.params) {
if (options?.params) {
url += "?" + new URLSearchParams(options.params).toString();
}
var fetch_options: fetchOptions = {
method: method,
};
if (options.body) {
if (options?.body) {
fetch_options["headers"] = { "Content-Type": "application/json" };
fetch_options["body"] = JSON.stringify(options.body);
}
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;
}