@vnejs/compatibility.text-with-audio.voice 0.1.1
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/dist/index.d.ts +26 -0
- package/dist/index.js +63 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.js +1 -0
- package/dist/utils/voice.d.ts +1 -0
- package/dist/utils/voice.js +1 -0
- package/package.json +42 -0
- package/src/index.ts +97 -0
- package/src/types.ts +17 -0
- package/src/utils/voice.ts +1 -0
- package/tsconfig.json +6 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "@vnejs/contracts.audio";
|
|
2
|
+
import "@vnejs/contracts.audio.voice";
|
|
3
|
+
import "@vnejs/contracts.text";
|
|
4
|
+
import { ModuleCore, type LineLoadHandlerArg, type SettingsChangedResult } from "@vnejs/module.core";
|
|
5
|
+
import type { TextEmitPayload } from "@vnejs/contracts.text";
|
|
6
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
7
|
+
type CompatState = {
|
|
8
|
+
currentName: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class CompatibilityTextVoice extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams, CompatState> {
|
|
11
|
+
name: string;
|
|
12
|
+
subscribe: () => void;
|
|
13
|
+
init: () => Promise<unknown[]> | undefined;
|
|
14
|
+
onLineLoad: ({ args, priority }?: LineLoadHandlerArg) => Promise<unknown[]> | undefined;
|
|
15
|
+
onTextEmitBefore: () => Promise<void>;
|
|
16
|
+
onTextEmit: (payload?: TextEmitPayload) => Promise<void>;
|
|
17
|
+
onInteractStarted: () => Promise<void>;
|
|
18
|
+
onSettingsChanged: ({ name }: SettingsChangedResult) => false | Promise<void>;
|
|
19
|
+
onStateClear: () => Promise<void>;
|
|
20
|
+
stopVoice: () => Promise<void>;
|
|
21
|
+
getDefaultState: () => CompatState;
|
|
22
|
+
getVoiceFromPayload: ({ args, isExtend, texts }?: TextEmitPayload) => string | undefined;
|
|
23
|
+
getVoiceArg: (args?: Record<string, unknown>) => string | undefined;
|
|
24
|
+
getVoiceVolume: () => number;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import "@vnejs/contracts.audio";
|
|
2
|
+
import "@vnejs/contracts.audio.voice";
|
|
3
|
+
import "@vnejs/contracts.text";
|
|
4
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
5
|
+
import { SETTINGS_KEYS as VOICE_SETTINGS_KEYS } from "@vnejs/contracts.audio.voice";
|
|
6
|
+
import { regModule } from "@vnejs/shared";
|
|
7
|
+
import { resolveVoicePath } from "./utils/voice.js";
|
|
8
|
+
export class CompatibilityTextVoice extends ModuleCore {
|
|
9
|
+
name = "compatibility.text-with-audio.voice";
|
|
10
|
+
subscribe = () => {
|
|
11
|
+
this.on(this.EVENTS.TEXT.EMIT, this.onTextEmit);
|
|
12
|
+
this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
|
|
13
|
+
this.on(this.EVENTS.INTERACT.STARTED, this.onInteractStarted);
|
|
14
|
+
this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingsChanged);
|
|
15
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
16
|
+
};
|
|
17
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.CONST.SCENARIO.OTHER_MODULE, handler: this.onLineLoad });
|
|
18
|
+
onLineLoad = ({ args = {}, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND } = {}) => {
|
|
19
|
+
const voice = this.getVoiceArg(args);
|
|
20
|
+
if (!voice || this.shared.voiceDisableSources.isNotEmpty())
|
|
21
|
+
return;
|
|
22
|
+
const name = resolveVoicePath(voice, this.shared.voiceLang);
|
|
23
|
+
return this.emit(this.EVENTS.AUDIO.MEDIA_LOAD, { layer: this.CONST.VOICE.LAYER, name, priority });
|
|
24
|
+
};
|
|
25
|
+
onTextEmitBefore = () => this.stopVoice();
|
|
26
|
+
onTextEmit = async (payload = {}) => {
|
|
27
|
+
await this.stopVoice();
|
|
28
|
+
const voice = this.getVoiceFromPayload(payload);
|
|
29
|
+
if (!voice || this.shared.voiceDisableSources.isNotEmpty())
|
|
30
|
+
return;
|
|
31
|
+
const name = resolveVoicePath(voice, this.shared.voiceLang);
|
|
32
|
+
this.state.currentName = name;
|
|
33
|
+
await this.emit(this.EVENTS.AUDIO.PLAY, {
|
|
34
|
+
layer: this.CONST.VOICE.LAYER,
|
|
35
|
+
name,
|
|
36
|
+
volume: this.getVoiceVolume(),
|
|
37
|
+
isLoop: false,
|
|
38
|
+
startDuration: 0,
|
|
39
|
+
finishDuration: 0,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
onInteractStarted = () => this.stopVoice();
|
|
43
|
+
onSettingsChanged = ({ name }) => name === VOICE_SETTINGS_KEYS.LANG && this.stopVoice();
|
|
44
|
+
onStateClear = () => this.stopVoice();
|
|
45
|
+
stopVoice = async () => {
|
|
46
|
+
const { currentName } = this.state;
|
|
47
|
+
if (!currentName)
|
|
48
|
+
return;
|
|
49
|
+
await this.emit(this.EVENTS.AUDIO.STOP, { layer: this.CONST.VOICE.LAYER, name: currentName, duration: 0 });
|
|
50
|
+
this.state.currentName = "";
|
|
51
|
+
};
|
|
52
|
+
getDefaultState = () => ({ currentName: "" });
|
|
53
|
+
getVoiceFromPayload = ({ args = {}, isExtend = false, texts = [] } = {}) => {
|
|
54
|
+
const lineArgs = isExtend && texts.length ? texts[texts.length - 1]?.args ?? {} : args;
|
|
55
|
+
return this.getVoiceArg(lineArgs);
|
|
56
|
+
};
|
|
57
|
+
getVoiceArg = (args = {}) => {
|
|
58
|
+
const voice = args.voice;
|
|
59
|
+
return typeof voice === "string" && voice ? voice : undefined;
|
|
60
|
+
};
|
|
61
|
+
getVoiceVolume = () => this.shared.settings[VOICE_SETTINGS_KEYS.VOLUME] ?? 100;
|
|
62
|
+
}
|
|
63
|
+
regModule(CompatibilityTextVoice);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { Constants as AudioConstants, PluginName as AudioPluginName, SubscribeEvents as AudioSubscribeEvents } from "@vnejs/contracts.audio";
|
|
3
|
+
import type { Constants as VoiceConstants, PluginName as VoicePluginName } from "@vnejs/contracts.audio.voice";
|
|
4
|
+
import type { Constants as TextConstants, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
5
|
+
export type PluginEvents = ModuleCoreEvents & Record<TextPluginName, TextSubscribeEvents> & Record<AudioPluginName, AudioSubscribeEvents>;
|
|
6
|
+
export type PluginConstants = ModuleCoreConstants & Record<TextPluginName, TextConstants> & Record<AudioPluginName, AudioConstants> & Record<VoicePluginName, VoiceConstants>;
|
|
7
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
8
|
+
export type PluginParams = ModuleCoreParams;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveVoicePath: (voice: string, voiceLang: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const resolveVoicePath = (voice, voiceLang) => `${voiceLang}/${voice}`;
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/compatibility.text-with-audio.voice",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@vnejs/contracts.audio": "~0.1.0",
|
|
34
|
+
"@vnejs/contracts.audio.voice": "~0.1.0",
|
|
35
|
+
"@vnejs/contracts.text": "~0.1.0",
|
|
36
|
+
"@vnejs/module.core": "~0.1.0",
|
|
37
|
+
"@vnejs/shared": "~0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@vnejs/configs.ts-common": "~0.1.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import "@vnejs/contracts.audio";
|
|
2
|
+
import "@vnejs/contracts.audio.voice";
|
|
3
|
+
import "@vnejs/contracts.text";
|
|
4
|
+
|
|
5
|
+
import { ModuleCore, type LineLoadHandlerArg, type SettingsChangedResult } from "@vnejs/module.core";
|
|
6
|
+
import type { TextEmitPayload } from "@vnejs/contracts.text";
|
|
7
|
+
import { SETTINGS_KEYS as VOICE_SETTINGS_KEYS } from "@vnejs/contracts.audio.voice";
|
|
8
|
+
import { regModule } from "@vnejs/shared";
|
|
9
|
+
|
|
10
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
11
|
+
import { resolveVoicePath } from "./utils/voice.js";
|
|
12
|
+
|
|
13
|
+
type CompatState = {
|
|
14
|
+
currentName: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class CompatibilityTextVoice extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams, CompatState> {
|
|
18
|
+
name = "compatibility.text-with-audio.voice";
|
|
19
|
+
|
|
20
|
+
subscribe = () => {
|
|
21
|
+
this.on(this.EVENTS.TEXT.EMIT, this.onTextEmit);
|
|
22
|
+
this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
|
|
23
|
+
this.on(this.EVENTS.INTERACT.STARTED, this.onInteractStarted);
|
|
24
|
+
this.on(this.EVENTS.SETTINGS.CHANGED, this.onSettingsChanged);
|
|
25
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
init = () =>
|
|
29
|
+
this.emit(this.EVENTS.SCENARIO.LINE_LOAD_REG, { module: this.CONST.SCENARIO.OTHER_MODULE, handler: this.onLineLoad });
|
|
30
|
+
|
|
31
|
+
onLineLoad = ({ args = {}, priority = this.CONST.MEDIA.PRIORITIES.BACKGROUND }: LineLoadHandlerArg = {}) => {
|
|
32
|
+
const voice = this.getVoiceArg(args);
|
|
33
|
+
|
|
34
|
+
if (!voice || this.shared.voiceDisableSources.isNotEmpty()) return;
|
|
35
|
+
|
|
36
|
+
const name = resolveVoicePath(voice, this.shared.voiceLang);
|
|
37
|
+
|
|
38
|
+
return this.emit(this.EVENTS.AUDIO.MEDIA_LOAD, { layer: this.CONST.VOICE.LAYER, name, priority });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
onTextEmitBefore = () => this.stopVoice();
|
|
42
|
+
|
|
43
|
+
onTextEmit = async (payload: TextEmitPayload = {}) => {
|
|
44
|
+
await this.stopVoice();
|
|
45
|
+
|
|
46
|
+
const voice = this.getVoiceFromPayload(payload);
|
|
47
|
+
|
|
48
|
+
if (!voice || this.shared.voiceDisableSources.isNotEmpty()) return;
|
|
49
|
+
|
|
50
|
+
const name = resolveVoicePath(voice, this.shared.voiceLang);
|
|
51
|
+
|
|
52
|
+
this.state.currentName = name;
|
|
53
|
+
|
|
54
|
+
await this.emit(this.EVENTS.AUDIO.PLAY, {
|
|
55
|
+
layer: this.CONST.VOICE.LAYER,
|
|
56
|
+
name,
|
|
57
|
+
volume: this.getVoiceVolume(),
|
|
58
|
+
isLoop: false,
|
|
59
|
+
startDuration: 0,
|
|
60
|
+
finishDuration: 0,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
onInteractStarted = () => this.stopVoice();
|
|
65
|
+
|
|
66
|
+
onSettingsChanged = ({ name }: SettingsChangedResult) => name === VOICE_SETTINGS_KEYS.LANG && this.stopVoice();
|
|
67
|
+
|
|
68
|
+
onStateClear = () => this.stopVoice();
|
|
69
|
+
|
|
70
|
+
stopVoice = async () => {
|
|
71
|
+
const { currentName } = this.state;
|
|
72
|
+
|
|
73
|
+
if (!currentName) return;
|
|
74
|
+
|
|
75
|
+
await this.emit(this.EVENTS.AUDIO.STOP, { layer: this.CONST.VOICE.LAYER, name: currentName, duration: 0 });
|
|
76
|
+
|
|
77
|
+
this.state.currentName = "";
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
getDefaultState = (): CompatState => ({ currentName: "" });
|
|
81
|
+
|
|
82
|
+
getVoiceFromPayload = ({ args = {}, isExtend = false, texts = [] }: TextEmitPayload = {}) => {
|
|
83
|
+
const lineArgs = isExtend && texts.length ? texts[texts.length - 1]?.args ?? {} : args;
|
|
84
|
+
|
|
85
|
+
return this.getVoiceArg(lineArgs);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
getVoiceArg = (args: Record<string, unknown> = {}) => {
|
|
89
|
+
const voice = args.voice;
|
|
90
|
+
|
|
91
|
+
return typeof voice === "string" && voice ? voice : undefined;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
getVoiceVolume = () => (this.shared.settings[VOICE_SETTINGS_KEYS.VOLUME] as number | undefined) ?? 100;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
regModule(CompatibilityTextVoice);
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { Constants as AudioConstants, PluginName as AudioPluginName, SubscribeEvents as AudioSubscribeEvents } from "@vnejs/contracts.audio";
|
|
3
|
+
import type { Constants as VoiceConstants, PluginName as VoicePluginName } from "@vnejs/contracts.audio.voice";
|
|
4
|
+
import type { Constants as TextConstants, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
5
|
+
|
|
6
|
+
export type PluginEvents = ModuleCoreEvents &
|
|
7
|
+
Record<TextPluginName, TextSubscribeEvents> &
|
|
8
|
+
Record<AudioPluginName, AudioSubscribeEvents>;
|
|
9
|
+
|
|
10
|
+
export type PluginConstants = ModuleCoreConstants &
|
|
11
|
+
Record<TextPluginName, TextConstants> &
|
|
12
|
+
Record<AudioPluginName, AudioConstants> &
|
|
13
|
+
Record<VoicePluginName, VoiceConstants>;
|
|
14
|
+
|
|
15
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
16
|
+
|
|
17
|
+
export type PluginParams = ModuleCoreParams;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const resolveVoicePath = (voice: string, voiceLang: string) => `${voiceLang}/${voice}`;
|