@nebutra/audio-pipeline 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebutra/audio-pipeline",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "BrandContext-first audio generation, license metadata, and loudness utilities",
5
5
  "private": false,
6
6
  "license": "MIT",
@@ -22,15 +22,19 @@
22
22
  "category": "ai",
23
23
  "summary": "License-aware BGM, SFX, and song generation surface"
24
24
  },
25
- "main": "./src/index.ts",
26
- "types": "./src/index.ts",
25
+ "main": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
27
  "exports": {
28
- ".": "./src/index.ts"
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
32
+ }
29
33
  },
30
34
  "dependencies": {
31
- "@nebutra/capability-kit": "0.2.2",
35
+ "@nebutra/capability-kit": "0.2.4",
32
36
  "@nebutra/errors": "0.1.2",
33
- "@nebutra/generation-context": "0.1.2"
37
+ "@nebutra/generation-context": "0.1.3"
34
38
  },
35
39
  "devDependencies": {
36
40
  "@types/node": "^25.9.1",
@@ -51,6 +55,12 @@
51
55
  "publishConfig": {
52
56
  "access": "public"
53
57
  },
58
+ "files": [
59
+ "dist",
60
+ "README.md",
61
+ "LICENSE",
62
+ "CHANGELOG.md"
63
+ ],
54
64
  "scripts": {
55
65
  "build": "tsup",
56
66
  "test": "vitest run",
@@ -1,22 +0,0 @@
1
-
2
- > @nebutra/audio-pipeline@0.1.2 build /Users/tseka_luk/Documents/Nebutra-SaaS-Lab/Nebutra-Sailor/packages/ai/audio-pipeline
3
- > tsup
4
-
5
- CLI Building entry: src/cli.ts, src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Using tsup config: /Users/tseka_luk/Documents/Nebutra-SaaS-Lab/Nebutra-Sailor/packages/ai/audio-pipeline/tsup.config.ts
9
- CLI Target: es2022
10
- CLI Cleaning output folder
11
- ESM Build start
12
- ESM dist/cli.js 1.32 KB
13
- ESM dist/index.js 186.00 B
14
- ESM dist/chunk-32LVUMTP.js 4.46 KB
15
- ESM dist/index.js.map 71.00 B
16
- ESM dist/cli.js.map 2.35 KB
17
- ESM dist/chunk-32LVUMTP.js.map 8.83 KB
18
- ESM ⚡️ Build success in 31ms
19
- DTS Build start
20
- DTS ⚡️ Build success in 2126ms
21
- DTS dist/cli.d.ts 13.00 B
22
- DTS dist/index.d.ts 1.47 KB
@@ -1,14 +0,0 @@
1
-
2
- > @nebutra/audio-pipeline@0.1.1 test /Users/tseka_luk/Documents/Nebutra-SaaS-Lab/Nebutra-Sailor/packages/ai/audio-pipeline
3
- > vitest run
4
-
5
-
6
- RUN v4.1.4 /Users/tseka_luk/Documents/Nebutra-SaaS-Lab/Nebutra-Sailor/packages/ai/audio-pipeline
7
-
8
- ✓ src/index.test.ts (2 tests) 87ms
9
-
10
- Test Files 1 passed (1)
11
- Tests 2 passed (2)
12
- Start at 09:38:39
13
- Duration 1.52s (transform 223ms, setup 0ms, import 285ms, tests 87ms, environment 0ms)
14
-
@@ -1,4 +0,0 @@
1
-
2
- > @nebutra/audio-pipeline@0.1.2 typecheck /Users/tseka_luk/Documents/Nebutra-SaaS-Lab/Nebutra-Sailor/packages/ai/audio-pipeline
3
- > tsc --noEmit
4
-
package/examples/bgm.ts DELETED
@@ -1,10 +0,0 @@
1
- import { createDemoBrandContext } from "@nebutra/generation-context";
2
- import { AudioPipeline } from "../src/index";
3
-
4
- const asset = await new AudioPipeline().generate(
5
- { type: "bgm", durationS: 5, mood: "uplifting tech", bpm: 110 },
6
- createDemoBrandContext(),
7
- true,
8
- );
9
-
10
- process.stdout.write(`${asset.path}\n`);
@@ -1,11 +0,0 @@
1
- import { createDemoBrandContext } from "@nebutra/generation-context";
2
- import { AudioPipeline } from "../src/index";
3
-
4
- const pipeline = new AudioPipeline();
5
- const asset = await pipeline.generate(
6
- { type: "sfx", description: "keyboard typing", durationS: 2 },
7
- createDemoBrandContext(),
8
- true,
9
- );
10
-
11
- process.stdout.write(`${JSON.stringify(await pipeline.license(asset), null, 2)}\n`);
@@ -1,11 +0,0 @@
1
- import { createDemoBrandContext } from "@nebutra/generation-context";
2
- import { AudioPipeline } from "../src/index";
3
-
4
- const pipeline = new AudioPipeline();
5
- const asset = await pipeline.generate(
6
- { type: "song", lyricsPrompt: "indie developer anthem", durationS: 8 },
7
- createDemoBrandContext(),
8
- true,
9
- );
10
-
11
- process.stdout.write(`${JSON.stringify(await pipeline.loudness(asset), null, 2)}\n`);
package/src/cli.ts DELETED
@@ -1,36 +0,0 @@
1
- import { createDemoBrandContext } from "@nebutra/generation-context";
2
- import { AudioPipeline, readAudioDebug } from "./index";
3
-
4
- const command = process.argv[2] ?? "doctor";
5
- const pipeline = new AudioPipeline();
6
-
7
- if (command === "doctor") {
8
- process.stdout.write(
9
- `${JSON.stringify({ capability: "audio-pipeline", results: await pipeline.doctor() }, null, 2)}\n`,
10
- );
11
- } else if (command === "debug") {
12
- process.stdout.write(
13
- `${JSON.stringify({ capability: "audio-pipeline", entries: await readAudioDebug() }, null, 2)}\n`,
14
- );
15
- } else if (command === "license") {
16
- const asset = await pipeline.generate(
17
- { type: "bgm", durationS: 3, mood: "uplifting technical" },
18
- createDemoBrandContext(),
19
- true,
20
- );
21
- process.stdout.write(
22
- `${JSON.stringify({ capability: "audio-pipeline", license: await pipeline.license(asset) }, null, 2)}\n`,
23
- );
24
- } else if (command === "loudness") {
25
- const asset = await pipeline.generate(
26
- { type: "sfx", description: "keyboard typing", durationS: 1 },
27
- createDemoBrandContext(),
28
- true,
29
- );
30
- process.stdout.write(
31
- `${JSON.stringify({ capability: "audio-pipeline", loudness: await pipeline.loudness(asset) }, null, 2)}\n`,
32
- );
33
- } else {
34
- process.stderr.write(`Unknown audio-pipeline command: ${command}\n`);
35
- process.exitCode = 1;
36
- }
package/src/index.test.ts DELETED
@@ -1,33 +0,0 @@
1
- import { mkdtemp, readFile, rm } from "node:fs/promises";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { createDemoBrandContext } from "@nebutra/generation-context";
5
- import { afterEach, describe, expect, it } from "vitest";
6
- import { AudioPipeline, readAudioDebug } from "./index";
7
-
8
- let root: string | undefined;
9
-
10
- afterEach(async () => {
11
- if (root) await rm(root, { recursive: true, force: true });
12
- root = undefined;
13
- });
14
-
15
- describe("AudioPipeline", () => {
16
- it("requires BrandContext", async () => {
17
- await expect(
18
- new AudioPipeline().generate({ type: "sfx", description: "click" }, undefined, true),
19
- ).rejects.toMatchObject({ capability: "audio-pipeline" });
20
- });
21
-
22
- it("writes a valid WAV header with commercial metadata", async () => {
23
- root = await mkdtemp(join(tmpdir(), "audio-pipeline-"));
24
- const asset = await new AudioPipeline({ root }).generate(
25
- { type: "bgm", durationS: 4, mood: "calm technical" },
26
- createDemoBrandContext(),
27
- true,
28
- );
29
- expect((await readFile(asset.path)).subarray(0, 4).toString()).toBe("RIFF");
30
- expect(asset.license.status).toBe("commercial-ok");
31
- expect(await readAudioDebug(root)).toHaveLength(1);
32
- });
33
- });
package/src/index.ts DELETED
@@ -1,176 +0,0 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
2
- import { dirname, join } from "node:path";
3
- import { appendCapabilityDebug, readCapabilityDebug } from "@nebutra/capability-kit/debug";
4
- import { CapabilityError } from "@nebutra/errors";
5
- import {
6
- assetId,
7
- type BrandContext,
8
- type GeneratedAsset,
9
- type LicenseMetadata,
10
- requireBrandContext,
11
- } from "@nebutra/generation-context";
12
-
13
- export type AudioIntent =
14
- | { type: "bgm"; durationS: number; mood: string; bpm?: number }
15
- | { type: "sfx"; description: string; durationS?: number }
16
- | { type: "song"; lyricsPrompt: string; durationS: number };
17
-
18
- export interface AudioAsset extends GeneratedAsset {
19
- readonly kind: "audio";
20
- readonly durationS: number;
21
- readonly format: "wav";
22
- readonly loudnessLufs: number;
23
- }
24
-
25
- export interface AudioHealth {
26
- readonly provider: string;
27
- readonly ok: boolean;
28
- readonly suggestion?: string;
29
- }
30
-
31
- export interface AudioPipelineOptions {
32
- readonly root?: string;
33
- readonly provider?: "tone-local" | "local-model" | "remote";
34
- }
35
-
36
- export async function readAudioDebug(root = process.cwd(), limit = 10): Promise<unknown[]> {
37
- return readCapabilityDebug("audio-pipeline", { root, limit });
38
- }
39
-
40
- function intentLabel(intent: AudioIntent): string {
41
- switch (intent.type) {
42
- case "bgm":
43
- return intent.mood;
44
- case "sfx":
45
- return intent.description;
46
- case "song":
47
- return intent.lyricsPrompt;
48
- }
49
- }
50
-
51
- function durationFor(intent: AudioIntent): number {
52
- if (intent.type === "sfx") return Math.max(1, Math.min(intent.durationS ?? 3, 8));
53
- return Math.max(1, Math.min(intent.durationS, 12));
54
- }
55
-
56
- export function createToneWav(durationS: number, frequency = 440, sampleRate = 24_000): Buffer {
57
- const samples = Math.max(1, Math.floor(durationS * sampleRate));
58
- const dataBytes = samples * 2;
59
- const buffer = Buffer.alloc(44 + dataBytes);
60
- buffer.write("RIFF", 0);
61
- buffer.writeUInt32LE(36 + dataBytes, 4);
62
- buffer.write("WAVE", 8);
63
- buffer.write("fmt ", 12);
64
- buffer.writeUInt32LE(16, 16);
65
- buffer.writeUInt16LE(1, 20);
66
- buffer.writeUInt16LE(1, 22);
67
- buffer.writeUInt32LE(sampleRate, 24);
68
- buffer.writeUInt32LE(sampleRate * 2, 28);
69
- buffer.writeUInt16LE(2, 32);
70
- buffer.writeUInt16LE(16, 34);
71
- buffer.write("data", 36);
72
- buffer.writeUInt32LE(dataBytes, 40);
73
- for (let index = 0; index < samples; index += 1) {
74
- const fade = Math.min(index / 1200, (samples - index) / 1200, 1);
75
- const sample = Math.round(
76
- Math.sin((2 * Math.PI * frequency * index) / sampleRate) * 9000 * fade,
77
- );
78
- buffer.writeInt16LE(sample, 44 + index * 2);
79
- }
80
- return buffer;
81
- }
82
-
83
- function frequencyFor(brand: BrandContext, intent: AudioIntent): number {
84
- const base = brand.toneKeywords.join("").length + intentLabel(intent).length;
85
- return 220 + (base % 9) * 55;
86
- }
87
-
88
- function licenseFor(requireCommercial: boolean, provider: string): LicenseMetadata {
89
- if (requireCommercial && provider !== "tone-local") {
90
- return {
91
- status: "unknown",
92
- source: provider,
93
- suggestion: "Verify the provider plan and model terms before commercial use.",
94
- };
95
- }
96
- return { status: "commercial-ok", source: "deterministic local renderer" };
97
- }
98
-
99
- export class AudioPipeline {
100
- readonly #root: string;
101
- readonly #provider: "tone-local" | "local-model" | "remote";
102
-
103
- constructor(options: AudioPipelineOptions = {}) {
104
- this.#root = options.root ?? process.cwd();
105
- this.#provider = options.provider ?? "tone-local";
106
- }
107
-
108
- async generate(
109
- intent: AudioIntent,
110
- brandInput: BrandContext | undefined,
111
- requireCommercial = true,
112
- ): Promise<AudioAsset> {
113
- const brand = requireBrandContext(brandInput, "audio-pipeline");
114
- if (requireCommercial && this.#provider !== "tone-local") {
115
- throw new CapabilityError(
116
- "audio-pipeline",
117
- "Selected audio provider lacks verified license",
118
- {
119
- suggestion: "Use tone-local or wire a provider with commercial license metadata.",
120
- statusCode: 409,
121
- },
122
- );
123
- }
124
- const durationS = durationFor(intent);
125
- const id = assetId("audio", `${intent.type}_${intentLabel(intent)}`);
126
- const path = join(this.#root, ".nebutra", "generated", "audio-pipeline", `${id}.wav`);
127
- await mkdir(dirname(path), { recursive: true });
128
- await writeFile(path, createToneWav(durationS, frequencyFor(brand, intent)));
129
-
130
- const asset: AudioAsset = {
131
- id,
132
- tenantId: brand.tenantId,
133
- kind: "audio",
134
- path,
135
- brandId: brand.brandId,
136
- provider: this.#provider,
137
- model: "brand-context-tone-v1",
138
- createdAt: new Date().toISOString(),
139
- license: licenseFor(requireCommercial, this.#provider),
140
- durationS,
141
- format: "wav",
142
- loudnessLufs: -18,
143
- metadata: { intent, brandSource: brand.sourcePath },
144
- };
145
- await appendCapabilityDebug(
146
- "audio-pipeline",
147
- { type: "generate", asset },
148
- { root: this.#root },
149
- );
150
- return asset;
151
- }
152
-
153
- async doctor(): Promise<AudioHealth[]> {
154
- return [
155
- { provider: "tone-local", ok: true },
156
- {
157
- provider: "local-model",
158
- ok: Boolean(process.env.AUDIO_LOCAL_MODEL_PATH),
159
- suggestion: "Set AUDIO_LOCAL_MODEL_PATH to enable local model generation.",
160
- },
161
- {
162
- provider: "remote",
163
- ok: Boolean(process.env.AUDIO_REMOTE_API_KEY),
164
- suggestion: "Set AUDIO_REMOTE_API_KEY to enable remote audio fallback.",
165
- },
166
- ];
167
- }
168
-
169
- async license(asset: Pick<AudioAsset, "license">): Promise<LicenseMetadata> {
170
- return asset.license;
171
- }
172
-
173
- async loudness(asset: Pick<AudioAsset, "loudnessLufs">): Promise<{ lufs: number }> {
174
- return { lufs: asset.loudnessLufs };
175
- }
176
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "target": "esnext",
7
- "types": ["node"],
8
- "incremental": false
9
- },
10
- "include": ["src", "examples"],
11
- "exclude": ["node_modules", "dist"]
12
- }
package/tsup.config.ts DELETED
@@ -1,11 +0,0 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts", "src/cli.ts"],
5
- format: ["esm"],
6
- dts: true,
7
- sourcemap: true,
8
- clean: true,
9
- target: "es2022",
10
- external: ["@nebutra/capability-kit/debug", "@nebutra/errors", "@nebutra/generation-context"],
11
- });