Skip to content
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
10 changes: 10 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RestAPI } from "./rest";
import { audioQuery } from "./audio_query";
import { Preset } from "./preset";
import { Speaker } from "./speaker";

// voicevox client
/**
Expand Down Expand Up @@ -103,4 +104,13 @@ export class Client {
async deletePreset(id: number): Promise<void> {
return await this.rest.deletePreset(id);
}

// Fetch speakers
/**
* @returns Speakers
*/
async fetchSpeakers(): Promise<Speaker[]> {
let speakers = await this.rest.getSpeakers();
return speakers.map((x) => new Speaker(x));
}
}
5 changes: 5 additions & 0 deletions src/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createAudioQueryFromPresetOptions,
} from "./types/audioquery";
import { Preset, DeletePresetOptions } from "./types/preset";
import { Speaker } from "./types/speaker";
import { synthesisParams } from "./types/synthesis";

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

async getSpeakers(): Promise<Speaker[]> {
return await this.request("GET", "/speakers");
}
}
18 changes: 18 additions & 0 deletions src/speaker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Speaker as SpeakerT, Styles, SupportedFeatures } from "./types/speaker";

// speaker
export class Speaker {
public name: string;
public speaker_uuid: string;
public styles: Styles[];
public version: string;
public supported_features: SupportedFeatures;

constructor(speaker: SpeakerT) {
this.name = speaker.name;
this.speaker_uuid = speaker.speaker_uuid;
this.styles = speaker.styles;
this.version = speaker.version;
this.supported_features = speaker.supported_features;
}
}
19 changes: 19 additions & 0 deletions src/types/speaker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type StyleType = "talk" | "singing_teacher" | "frame_decode" | "sing";

export interface Styles {
id: number;
name: string;
type: string;
}

export interface SupportedFeatures {
permitted_synthesis_morphing: "ALL" | "SELF_ONLY" | "NOTHING"
}

export interface Speaker {
name: string;
speaker_uuid: string;
styles: Styles[];
version: string;
supported_features: SupportedFeatures;
}
11 changes: 11 additions & 0 deletions tests/speakers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from "assert";
import Client from "../dist";

const client = new Client("http://127.0.0.1:50021");

async function main() {
const speakers = await client.fetchSpeakers();
assert(speakers.length > 0);
}

main();
Loading