Skip to content

Commit ca01239

Browse files
authored
Merge pull request #70 from jacknkandy/add-fetch-speakers
Add fetchSpeakers
2 parents a586816 + 5bf9204 commit ca01239

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

src/client.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RestAPI } from "./rest";
22
import { audioQuery } from "./audio_query";
33
import { Preset } from "./preset";
4+
import { Speaker } from "./speaker";
45

56
// voicevox client
67
/**
@@ -103,4 +104,13 @@ export class Client {
103104
async deletePreset(id: number): Promise<void> {
104105
return await this.rest.deletePreset(id);
105106
}
107+
108+
// Fetch speakers
109+
/**
110+
* @returns Speakers
111+
*/
112+
async fetchSpeakers(): Promise<Speaker[]> {
113+
let speakers = await this.rest.getSpeakers();
114+
return speakers.map((x) => new Speaker(x));
115+
}
106116
}

src/rest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createAudioQueryFromPresetOptions,
55
} from "./types/audioquery";
66
import { Preset, DeletePresetOptions } from "./types/preset";
7+
import { Speaker } from "./types/speaker";
78
import { synthesisParams } from "./types/synthesis";
89

910
type fetchOptions = {
@@ -118,4 +119,8 @@ export class RestAPI {
118119
params: params,
119120
});
120121
}
122+
123+
async getSpeakers(): Promise<Speaker[]> {
124+
return await this.request("GET", "/speakers");
125+
}
121126
}

src/speaker.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Speaker as SpeakerT, Styles, SupportedFeatures } from "./types/speaker";
2+
3+
// speaker
4+
export class Speaker {
5+
public name: string;
6+
public speaker_uuid: string;
7+
public styles: Styles[];
8+
public version: string;
9+
public supported_features: SupportedFeatures;
10+
11+
constructor(speaker: SpeakerT) {
12+
this.name = speaker.name;
13+
this.speaker_uuid = speaker.speaker_uuid;
14+
this.styles = speaker.styles;
15+
this.version = speaker.version;
16+
this.supported_features = speaker.supported_features;
17+
}
18+
}

src/types/speaker.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export type StyleType = "talk" | "singing_teacher" | "frame_decode" | "sing";
2+
3+
export interface Styles {
4+
id: number;
5+
name: string;
6+
type: string;
7+
}
8+
9+
export interface SupportedFeatures {
10+
permitted_synthesis_morphing: "ALL" | "SELF_ONLY" | "NOTHING"
11+
}
12+
13+
export interface Speaker {
14+
name: string;
15+
speaker_uuid: string;
16+
styles: Styles[];
17+
version: string;
18+
supported_features: SupportedFeatures;
19+
}

tests/speakers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import assert from "assert";
2+
import Client from "../dist";
3+
4+
const client = new Client("http://127.0.0.1:50021");
5+
6+
async function main() {
7+
const speakers = await client.fetchSpeakers();
8+
assert(speakers.length > 0);
9+
}
10+
11+
main();

0 commit comments

Comments
 (0)