@vdegenne/voicevox 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/lib/index.d.ts +6 -6
- package/lib/index.js +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { ReactiveController } from '@snar/lit';
|
|
2
|
-
interface
|
|
2
|
+
interface VoicevoxStyle {
|
|
3
3
|
id: number;
|
|
4
4
|
name: string;
|
|
5
5
|
}
|
|
6
|
-
interface
|
|
6
|
+
interface VoicevoxSpeaker {
|
|
7
7
|
name: string;
|
|
8
8
|
speaker_uuid: string;
|
|
9
|
-
styles:
|
|
9
|
+
styles: VoicevoxStyle[];
|
|
10
10
|
}
|
|
11
11
|
interface PlayOptions {
|
|
12
12
|
voiceId?: number;
|
|
13
13
|
speed?: number;
|
|
14
14
|
volume?: number;
|
|
15
15
|
}
|
|
16
|
-
export declare class
|
|
16
|
+
export declare class VoicevoxClient extends ReactiveController {
|
|
17
17
|
state: 'disconnected' | 'connecting' | 'connection_error' | 'connected';
|
|
18
|
-
speakers:
|
|
18
|
+
speakers: VoicevoxSpeaker[];
|
|
19
19
|
host: string;
|
|
20
20
|
port: number;
|
|
21
21
|
constructor({ host, port, }?: {
|
|
@@ -40,6 +40,6 @@ export declare class VoiceVoxClient extends ReactiveController {
|
|
|
40
40
|
getVoiceTitles(): string[];
|
|
41
41
|
getVoiceTitleFromId(voiceId: number): string | undefined;
|
|
42
42
|
}
|
|
43
|
-
export declare const voicevox:
|
|
43
|
+
export declare const voicevox: VoicevoxClient;
|
|
44
44
|
export {};
|
|
45
45
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { ReactiveController, state } from '@snar/lit';
|
|
8
|
-
export class
|
|
8
|
+
export class VoicevoxClient extends ReactiveController {
|
|
9
9
|
constructor({ host = '127.0.0.1', port = 50021, } = {}) {
|
|
10
10
|
super();
|
|
11
11
|
this.state = 'disconnected';
|
|
@@ -45,7 +45,7 @@ export class VoiceVoxClient extends ReactiveController {
|
|
|
45
45
|
}
|
|
46
46
|
async play(sentence, { voiceId = 0, speed = 1, volume = 1 } = {}) {
|
|
47
47
|
if (this.state !== 'connected') {
|
|
48
|
-
throw new Error('
|
|
48
|
+
throw new Error('VOICEVOX is not connected');
|
|
49
49
|
}
|
|
50
50
|
const key = this.getCacheKey(sentence, voiceId, speed);
|
|
51
51
|
if (this.pendingPlays.has(key)) {
|
|
@@ -95,7 +95,7 @@ export class VoiceVoxClient extends ReactiveController {
|
|
|
95
95
|
method: 'POST',
|
|
96
96
|
});
|
|
97
97
|
if (!queryResponse.ok) {
|
|
98
|
-
throw new Error(`
|
|
98
|
+
throw new Error(`VOICEVOX audio_query failed: HTTP ${queryResponse.status}`);
|
|
99
99
|
}
|
|
100
100
|
const query = await queryResponse.json();
|
|
101
101
|
query.speedScale = speed;
|
|
@@ -107,7 +107,7 @@ export class VoiceVoxClient extends ReactiveController {
|
|
|
107
107
|
body: JSON.stringify(query),
|
|
108
108
|
});
|
|
109
109
|
if (!synthesisResponse.ok) {
|
|
110
|
-
throw new Error(`
|
|
110
|
+
throw new Error(`VOICEVOX synthesis failed: HTTP ${synthesisResponse.status}`);
|
|
111
111
|
}
|
|
112
112
|
return synthesisResponse.blob();
|
|
113
113
|
}
|
|
@@ -175,7 +175,7 @@ export class VoiceVoxClient extends ReactiveController {
|
|
|
175
175
|
getRandomVoiceId() {
|
|
176
176
|
const styles = this.speakers.flatMap((speaker) => speaker.styles);
|
|
177
177
|
if (styles.length === 0) {
|
|
178
|
-
throw new Error('
|
|
178
|
+
throw new Error('VOICEVOX has no available voices');
|
|
179
179
|
}
|
|
180
180
|
return styles[Math.floor(Math.random() * styles.length)].id;
|
|
181
181
|
}
|
|
@@ -194,15 +194,15 @@ export class VoiceVoxClient extends ReactiveController {
|
|
|
194
194
|
}
|
|
195
195
|
__decorate([
|
|
196
196
|
state()
|
|
197
|
-
],
|
|
197
|
+
], VoicevoxClient.prototype, "state", void 0);
|
|
198
198
|
__decorate([
|
|
199
199
|
state()
|
|
200
|
-
],
|
|
200
|
+
], VoicevoxClient.prototype, "speakers", void 0);
|
|
201
201
|
__decorate([
|
|
202
202
|
state()
|
|
203
|
-
],
|
|
203
|
+
], VoicevoxClient.prototype, "host", void 0);
|
|
204
204
|
__decorate([
|
|
205
205
|
state()
|
|
206
|
-
],
|
|
207
|
-
export const voicevox = new
|
|
206
|
+
], VoicevoxClient.prototype, "port", void 0);
|
|
207
|
+
export const voicevox = new VoicevoxClient();
|
|
208
208
|
//# sourceMappingURL=index.js.map
|