@handsforbots/voice-effects 0.0.0-stage → 2.0.0-alpha.0

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.
@@ -0,0 +1,5 @@
1
+ import type { EffectChain } from './types.js';
2
+ export type PresetName = 'clean' | 'denoise' | 'radio' | 'telephone' | 'megaphone' | 'robot' | 'underwater' | 'cave' | 'ice' | 'chipmunk' | 'giant';
3
+ /** Ready-made chains. Copy one and change it: they are plain JSON. */
4
+ export declare const presets: Record<PresetName, EffectChain>;
5
+ //# sourceMappingURL=presets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.d.ts","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,SAAS,GACT,OAAO,GACP,WAAW,GACX,WAAW,GACX,OAAO,GACP,YAAY,GACZ,MAAM,GACN,KAAK,GACL,UAAU,GACV,OAAO,CAAA;AAIX,sEAAsE;AACtE,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,UAAU,EAAE,WAAW,CA0FnD,CAAA"}
@@ -0,0 +1,94 @@
1
+ const limiter = { type: 'limiter' };
2
+ /** Ready-made chains. Copy one and change it: they are plain JSON. */
3
+ export const presets = {
4
+ clean: { version: 1, name: 'clean', description: 'No effects', effects: [] },
5
+ denoise: {
6
+ version: 1,
7
+ name: 'denoise',
8
+ description: 'For quantized models that hiss: a gate in the pauses and a high-pass',
9
+ effects: [{ type: 'gate', threshold: -42, reduction: 30 }, { type: 'highpass', frequency: 80, Q: 0 }, limiter],
10
+ },
11
+ radio: {
12
+ version: 1,
13
+ name: 'radio',
14
+ description: 'AM radio: a narrow band, a bit of saturation, compressed',
15
+ effects: [
16
+ { type: 'highpass', frequency: 300, Q: 0 },
17
+ { type: 'lowpass', frequency: 3400, Q: 0 },
18
+ { type: 'peaking', frequency: 1800, Q: 1, gain: 5 },
19
+ { type: 'distortion', amount: 0.15 },
20
+ { type: 'compressor', threshold: -30, knee: 10, ratio: 6 },
21
+ limiter,
22
+ ],
23
+ },
24
+ telephone: {
25
+ version: 1,
26
+ name: 'telephone',
27
+ description: 'Phone line: 400–3000 Hz with steep edges',
28
+ effects: [
29
+ { type: 'highpass', frequency: 400, Q: 0 },
30
+ { type: 'highpass', frequency: 400, Q: 0 },
31
+ { type: 'lowpass', frequency: 3000, Q: 0 },
32
+ { type: 'lowpass', frequency: 3000, Q: 0 },
33
+ { type: 'peaking', frequency: 1500, Q: 1, gain: 3 },
34
+ limiter,
35
+ ],
36
+ },
37
+ megaphone: {
38
+ version: 1,
39
+ name: 'megaphone',
40
+ description: 'Horn: thin, loud and distorted',
41
+ effects: [
42
+ { type: 'highpass', frequency: 600, Q: 0 },
43
+ { type: 'lowpass', frequency: 3500, Q: 0 },
44
+ { type: 'peaking', frequency: 2000, Q: 1.5, gain: 8 },
45
+ { type: 'distortion', amount: 0.45 },
46
+ limiter,
47
+ ],
48
+ },
49
+ robot: {
50
+ version: 1,
51
+ name: 'robot',
52
+ description: 'Ring modulator at 40 Hz, the classic robot',
53
+ effects: [{ type: 'ringmod', frequency: 40, mix: 0.8 }, { type: 'highpass', frequency: 120, Q: 0 }, { type: 'distortion', amount: 0.1 }, limiter],
54
+ },
55
+ underwater: {
56
+ version: 1,
57
+ name: 'underwater',
58
+ description: 'Muffled, wobbling, in a wet room',
59
+ effects: [
60
+ { type: 'lowpass', frequency: 900, Q: 3 },
61
+ { type: 'chorus', depth: 0.006, mix: 0.6 },
62
+ { type: 'vibrato', rate: 1.5, depth: 0.002 },
63
+ { type: 'reverb', time: 1.5, mix: 0.4 },
64
+ limiter,
65
+ ],
66
+ },
67
+ cave: {
68
+ version: 1,
69
+ name: 'cave',
70
+ description: 'A big stone room with an echo',
71
+ effects: [{ type: 'reverb', time: 3, mix: 0.45 }, { type: 'delay', delayTime: 0.3, feedback: 0.3, mix: 0.25 }, limiter],
72
+ },
73
+ ice: {
74
+ version: 1,
75
+ name: 'ice',
76
+ description: 'The "pew" of a stone on ice over a slightly higher, faster voice',
77
+ effects: [{ type: 'varispeed', rate: 1.2 }, { type: 'dispersion' }, limiter],
78
+ },
79
+ chipmunk: {
80
+ version: 1,
81
+ name: 'chipmunk',
82
+ description: 'Higher and a bit faster (prosody only: works with the browser voice too)',
83
+ prosody: { pitch: 7, rate: 1.1 },
84
+ effects: [],
85
+ },
86
+ giant: {
87
+ version: 1,
88
+ name: 'giant',
89
+ description: 'Lower, slower, with body and some room',
90
+ prosody: { pitch: -5, rate: 0.9 },
91
+ effects: [{ type: 'lowshelf', frequency: 150, gain: 6 }, { type: 'reverb', time: 0.8, mix: 0.2 }, limiter],
92
+ },
93
+ };
94
+ //# sourceMappingURL=presets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.js","sourceRoot":"","sources":["../src/presets.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;AAEnC,sEAAsE;AACtE,MAAM,CAAC,MAAM,OAAO,GAAoC;IACtD,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,EAAE;IAC5E,OAAO,EAAE;QACP,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,sEAAsE;QACnF,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC;KAC/G;IACD,KAAK,EAAE;QACL,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0DAA0D;QACvE,OAAO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AE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC;KACxH;IACD,GAAG,EAAE;QACH,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,KAAK;QACX,WAAW,EAAE,kEAAkE;QAC/E,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC;KAC7E;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,UAAU;QAChB,WAAW,EAAE,0EAA0E;QACvF,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE;QAChC,OAAO,EAAE,EAAE;KACZ;IACD,KAAK,EAAE;QACL,OAAO,EAAE,CAAC;QACV,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,wCAAwC;QACrD,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE;QACjC,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC;KAC3G;CACF,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { type Registry } from './chain.js';
2
+ /**
3
+ * JSON Schema (draft 2020-12) of an effect chain for these effect types: for
4
+ * editors, validators in other languages and agents that write presets.
5
+ */
6
+ export declare function chainSchema(registry?: Registry): Record<string, unknown>;
7
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1D;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,GAAE,QAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgD1F"}
package/dist/schema.js ADDED
@@ -0,0 +1,53 @@
1
+ import { createRegistry } from './chain.js';
2
+ /**
3
+ * JSON Schema (draft 2020-12) of an effect chain for these effect types: for
4
+ * editors, validators in other languages and agents that write presets.
5
+ */
6
+ export function chainSchema(registry = createRegistry()) {
7
+ const effect = [...registry.values()].map((definition) => ({
8
+ type: 'object',
9
+ title: definition.label,
10
+ ...(definition.description ? { description: definition.description } : {}),
11
+ required: ['type'],
12
+ additionalProperties: false,
13
+ properties: {
14
+ type: { const: definition.type },
15
+ id: { type: 'string' },
16
+ bypass: { type: 'boolean' },
17
+ ...Object.fromEntries(Object.entries(definition.params).map(([key, info]) => [
18
+ key,
19
+ {
20
+ type: info.type === 'boolean' ? ['boolean', 'integer'] : info.type === 'float' || !info.type ? 'number' : 'integer',
21
+ title: info.label,
22
+ minimum: info.minValue,
23
+ maximum: info.maxValue,
24
+ default: info.defaultValue,
25
+ ...(info.units ? { description: info.units } : {}),
26
+ },
27
+ ])),
28
+ },
29
+ }));
30
+ return {
31
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
32
+ title: 'Voice effect chain',
33
+ type: 'object',
34
+ required: ['version', 'effects'],
35
+ additionalProperties: false,
36
+ properties: {
37
+ version: { const: 1 },
38
+ name: { type: 'string' },
39
+ description: { type: 'string' },
40
+ prosody: {
41
+ type: 'object',
42
+ additionalProperties: false,
43
+ properties: {
44
+ rate: { type: 'number', exclusiveMinimum: 0, description: 'multiplier, SSML rate="120%" = 1.2' },
45
+ pitch: { type: 'number', description: 'semitones, SSML pitch="+2st" = 2' },
46
+ volume: { type: 'number', description: 'dB, SSML volume="+6dB" = 6' },
47
+ },
48
+ },
49
+ effects: { type: 'array', items: { oneOf: effect } },
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,MAAM,YAAY,CAAA;AAE1D;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAQ,GAAa,cAAc,EAAE;IAC/D,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACzD,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,QAAQ,EAAE,CAAC,MAAM,CAAC;QAClB,oBAAoB,EAAE,KAAK;QAC3B,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE;YAChC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YACtB,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;YAC3B,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC;gBACrD,GAAG;gBACH;oBACE,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,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@@
1
+ import type { Prosody } from '@handsforbots/voice';
2
+ export type SsmlOptions = {
3
+ /** `xml:lang` of `<speak>`, e.g. 'pt-BR'. */
4
+ language?: string;
5
+ /** Wraps the text in `<voice name="…">`. */
6
+ voice?: string;
7
+ /**
8
+ * Unit for the pitch. `st` (default): semitones, as in SSML 1.1 (Azure,
9
+ * Google). `%`: a relative change, for services without semitones (Amazon Polly).
10
+ */
11
+ pitch?: 'st' | '%';
12
+ /** Only the `<prosody>` element, without `<speak>` (to embed in your own document). Default false. */
13
+ fragment?: boolean;
14
+ };
15
+ /** The `<prosody>` attributes (W3C SSML 1.1, section 3.2.4) for the prosody. */
16
+ export declare function prosodyAttributes(prosody?: Prosody, unit?: 'st' | '%'): Record<string, string>;
17
+ /** SSML for `text` with the prosody, for TTS services behind your backend. */
18
+ export declare function toSSML(text: string, prosody?: Prosody, options?: SsmlOptions): string;
19
+ //# sourceMappingURL=ssml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssml.d.ts","sourceRoot":"","sources":["../src/ssml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,MAAM,MAAM,WAAW,GAAG;IACxB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,GAAG,GAAG,CAAA;IAClB,sGAAsG;IACtG,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAOD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,OAAY,EAAE,IAAI,GAAE,IAAI,GAAG,GAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxG;AAED,8EAA8E;AAC9E,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM,CAU7F"}
package/dist/ssml.js ADDED
@@ -0,0 +1,30 @@
1
+ const escape = (text) => text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
2
+ const signed = (value, unit) => `${value >= 0 ? '+' : ''}${Number(value.toFixed(2))}${unit}`;
3
+ /** The `<prosody>` attributes (W3C SSML 1.1, section 3.2.4) for the prosody. */
4
+ export function prosodyAttributes(prosody = {}, unit = 'st') {
5
+ const attributes = {};
6
+ if (prosody.rate !== undefined && prosody.rate !== 1)
7
+ attributes.rate = `${Math.round(prosody.rate * 100)}%`;
8
+ if (prosody.pitch) {
9
+ attributes.pitch = unit === 'st' ? signed(prosody.pitch, 'st') : signed((2 ** (prosody.pitch / 12) - 1) * 100, '%');
10
+ }
11
+ if (prosody.volume)
12
+ attributes.volume = signed(prosody.volume, 'dB');
13
+ return attributes;
14
+ }
15
+ /** SSML for `text` with the prosody, for TTS services behind your backend. */
16
+ export function toSSML(text, prosody = {}, options = {}) {
17
+ const attributes = Object.entries(prosodyAttributes(prosody, options.pitch))
18
+ .map(([key, value]) => ` ${key}="${value}"`)
19
+ .join('');
20
+ let body = escape(text);
21
+ if (attributes)
22
+ body = `<prosody${attributes}>${body}</prosody>`;
23
+ if (options.voice)
24
+ body = `<voice name="${escape(options.voice)}">${body}</voice>`;
25
+ if (options.fragment)
26
+ return body;
27
+ const lang = options.language ? ` xml:lang="${escape(options.language)}"` : '';
28
+ return `<speak version="1.1" xmlns="http://www.w3.org/2001/10/synthesis"${lang}>${body}</speak>`;
29
+ }
30
+ //# sourceMappingURL=ssml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssml.js","sourceRoot":"","sources":["../src/ssml.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAC9B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,C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AY,EAAE,EAAE,OAAO,GAAgB,EAAE;IACnF,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;SACzE,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,KAAK,KAAK,GAAG,CAAC;SAC3C,IAAI,CAAC,EAAE,CAAC,CAAA;IACX,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,IAAI,UAAU;QAAE,IAAI,GAAG,WAAW,UAAU,IAAI,IAAI,YAAY,CAAA;IAChE,IAAI,OAAO,CAAC,KAAK;QAAE,IAAI,GAAG,gBAAgB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,UAAU,CAAA;IAClF,IAAI,OAAO,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;IAC9E,OAAO,mEAAmE,IAAI,IAAI,IAAI,UAAU,CAAA;AAClG,CAAC"}
@@ -0,0 +1,82 @@
1
+ import type { Prosody, SpeechAudio } from '@handsforbots/voice';
2
+ /**
3
+ * A parameter, described like a Web Audio Modules 2.0 `WamParameterConfiguration`
4
+ * (`label`, `type`, `defaultValue`, `minValue`, `maxValue`, `discreteStep`,
5
+ * `exponent`, `choices`, `units`), so UIs and validators can be generated.
6
+ * Times are in seconds and levels in decibels, as in the Web Audio API.
7
+ */
8
+ export type ParamInfo = {
9
+ label: string;
10
+ type?: 'float' | 'int' | 'boolean' | 'choice';
11
+ defaultValue: number;
12
+ minValue: number;
13
+ maxValue: number;
14
+ discreteStep?: number;
15
+ /** Skew for sliders: values above 1 give more room to the low end (frequencies). */
16
+ exponent?: number;
17
+ choices?: string[];
18
+ units?: string;
19
+ };
20
+ /**
21
+ * One effect in a chain: `type` plus its parameters, flat, named after the
22
+ * Web Audio option dictionaries (`BiquadFilterOptions`: `frequency`, `Q`,
23
+ * `gain`; `DynamicsCompressorOptions`: `threshold`, `knee`, `ratio`,
24
+ * `attack`, `release`; `DelayOptions`: `delayTime`…). Missing parameters take
25
+ * their default.
26
+ */
27
+ export type EffectSpec = {
28
+ type: string;
29
+ /** Optional name, to address the effect at runtime (`update('voz', …)`). */
30
+ id?: string;
31
+ /** Kept in the chain, but not applied. */
32
+ bypass?: boolean;
33
+ [param: string]: string | number | boolean | undefined;
34
+ };
35
+ /** A chain of effects, applied in order, plus the prosody asked of the synthesizer. */
36
+ export type EffectChain = {
37
+ /** Format version. */
38
+ version: 1;
39
+ name?: string;
40
+ description?: string;
41
+ /** SSML-style prosody: rate multiplier, pitch in semitones, volume in dB. */
42
+ prosody?: Prosody;
43
+ effects: EffectSpec[];
44
+ };
45
+ export type EffectParams = Record<string, number>;
46
+ /** What `build` returns: the nodes between the previous effect and the next. */
47
+ export type EffectNodes = {
48
+ input: AudioNode;
49
+ output: AudioNode;
50
+ dispose?(): void;
51
+ };
52
+ /** Context handed to the FFmpeg exporter of an effect. */
53
+ export type FfmpegContext = {
54
+ sampleRate: number;
55
+ };
56
+ /** An FFmpeg filter for an effect; `approximate` explains what differs from Web Audio. */
57
+ export type FfmpegFilter = {
58
+ filter: string;
59
+ approximate?: string;
60
+ } | string;
61
+ /**
62
+ * An effect type. Register your own with `defineEffect` and pass it in
63
+ * `voiceEffects(chain, { effects: [...] })`. Provide `build` (Web Audio
64
+ * nodes), `process` (samples, before playback), or both.
65
+ */
66
+ export type EffectDefinition = {
67
+ type: string;
68
+ label: string;
69
+ description?: string;
70
+ params: Record<string, ParamInfo>;
71
+ /** Sample-level processing (runs before the Web Audio graph). */
72
+ process?(audio: SpeechAudio, params: EffectParams): SpeechAudio;
73
+ /** Web Audio nodes; may change `source.playbackRate`. */
74
+ build?(context: BaseAudioContext, params: EffectParams, source: AudioBufferSourceNode): EffectNodes;
75
+ /** Seconds it keeps sounding after the input stops (reverb, echo). */
76
+ tail?(params: EffectParams): number;
77
+ /** Playback-rate factor the effect applies (for offline render lengths). */
78
+ speed?(params: EffectParams): number;
79
+ /** Equivalent FFmpeg filter, or `undefined` when there is none. */
80
+ ffmpeg?(params: EffectParams, context: FfmpegContext): FfmpegFilter | undefined;
81
+ };
82
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAA;IAC7C,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,4EAA4E;IAC5E,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,0CAA0C;IAC1C,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;CACvD,CAAA;AAED,uFAAuF;AACvF,MAAM,MAAM,WAAW,GAAG;IACxB,sBAAsB;IACtB,OAAO,EAAE,CAAC,CAAA;IACV,I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MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,GAAG,YAAY,GAAG,SAAS,CAAA;CAChF,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@handsforbots/voice-effects",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0-alpha.0",
4
+ "description": "Declarative effects for synthesized speech: a JSON chain in Web Audio terms, parameters described like Web Audio Modules, SSML prosody, presets, offline rendering and export to FFmpeg filtergraphs and SSML.",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/plugins.md#voice-effects",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/handsforbots/handsforbots.git",
10
+ "directory": "packages/voice-effects"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/handsforbots/handsforbots/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "peerDependencies": {
30
+ "@handsforbots/voice": "^2.0.0-alpha.0"
31
+ },
32
+ "peerDependenciesMeta": {
33
+ "@handsforbots/voice": {
34
+ "optional": true
35
+ }
36
+ },
37
+ "devDependencies": {
38
+ "@handsforbots/voice": "^2.0.0-alpha.0",
39
+ "@handsforbots/core": "^2.0.0-alpha.0"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.build.json",
43
+ "typecheck": "tsc -p tsconfig.json --noEmit"
44
+ }
6
45
  }