Skip to content

Commit

Permalink
Merge pull request #46 from ryunix/add-fetch-presets
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna2134 authored Sep 17, 2023
2 parents 5dbf773 + b945e90 commit 84c580a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 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;
}
}
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;
}

0 comments on commit 84c580a

Please sign in to comment.