Skip to content

Commit

Permalink
Merge pull request #44 from ryunix/add-create-audio-query-from-preset
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna2134 authored Sep 16, 2023
2 parents 6048ab6 + 17804b7 commit 084e9d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,27 @@ export class Client {
let audioquery = await this.rest.createAudioQuery(text, speaker, options);
return new audioQuery(this.rest, audioquery);
}

// Create audio query from preset
/**
* @param text - Japanese text
* @param preset_id - Preset ID
* @param options - Options
* @param options.core_version - Core version
*/
async createAudioQueryFromPreset(
text: string,
preset_id: number,
options?: {
core_version?: string;
}
): Promise<audioQuery> {
options ??= {};
let audioquery = await this.rest.createAudioQueryFromPreset(
text,
preset_id,
options
);
return new audioQuery(this.rest, audioquery);
}
}
25 changes: 24 additions & 1 deletion src/rest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { audioQuery, createAudioQueryOptions } from "./types/audioquery";
import {
audioQuery,
createAudioQueryOptions,
createAudioQueryFromPresetOptions,
} from "./types/audioquery";
import { synthesisParams } from "./types/synthesis";

type fetchOptions = {
Expand Down Expand Up @@ -60,6 +64,25 @@ export class RestAPI {
});
}

async createAudioQueryFromPreset(
text: string,
preset_id: number,
options: {
core_version?: string;
}
): Promise<audioQuery> {
let params: createAudioQueryFromPresetOptions = {
text: text,
preset_id: preset_id,
};
if (options.core_version) {
params["core_version"] = options.core_version;
}
return await this.request("POST", "/audio_query_from_preset", {
params: params,
});
}

async synthesis(
audioQuery: audioQuery,
params: synthesisParams
Expand Down
6 changes: 6 additions & 0 deletions src/types/audioquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ export interface createAudioQueryOptions {
speaker: number;
core_version?: string;
}

export interface createAudioQueryFromPresetOptions {
text: string;
preset_id: number;
core_version?: string;
}

0 comments on commit 084e9d6

Please sign in to comment.