feat: switch audio and storage providers to qwen3 tts and minio

This commit is contained in:
Codex
2026-02-18 13:58:23 +00:00
parent 31e8e07319
commit 445e5725b3
6 changed files with 273 additions and 258 deletions

View File

@@ -9,31 +9,38 @@ test("uploadAudio sends put command", async () => {
const adapter = createStorageAdapter({
bucket: "b1",
client: {
async send(command) {
sent.push(command.input);
async putObject(bucket, key, body, size, metadata) {
sent.push({ bucket, key, body, size, metadata });
},
async presignedGetObject() {},
},
signedUrlFactory: async () => "https://signed.example",
});
const payload = Buffer.from("abc");
const res = await adapter.uploadAudio({
key: "audio/1.mp3",
body: Buffer.from("abc"),
body: payload,
});
assert.equal(res.bucket, "b1");
assert.equal(sent.length, 1);
assert.equal(sent[0].Bucket, "b1");
assert.equal(sent[0].Key, "audio/1.mp3");
assert.equal(sent[0].bucket, "b1");
assert.equal(sent[0].key, "audio/1.mp3");
assert.equal(sent[0].size, payload.length);
assert.equal(sent[0].metadata["Content-Type"], "audio/mpeg");
});
test("getSignedDownloadUrl uses provided signer", async () => {
test("getSignedDownloadUrl uses minio presigner with ttl", async () => {
const adapter = createStorageAdapter({
bucket: "b1",
client: { async send() {} },
signedUrlFactory: async (_client, command, options) => `signed:${command.input.Key}:${options.expiresIn}`,
client: {
async putObject() {},
async presignedGetObject(bucket, key, expiresIn) {
return `signed:${bucket}:${key}:${expiresIn}`;
},
},
});
const url = await adapter.getSignedDownloadUrl("audio/2.mp3", 120);
assert.equal(url, "signed:audio/2.mp3:120");
assert.equal(url, "signed:b1:audio/2.mp3:120");
});

View File

@@ -4,29 +4,48 @@ const test = require("node:test");
const assert = require("node:assert/strict");
const { createTTSAdapter } = require("../src/integrations/tts-client");
test("synthesize returns buffer from openai response", async () => {
test("synthesize returns buffer from qwen-compatible audio endpoint", async () => {
const calls = [];
const adapter = createTTSAdapter({
client: {
audio: {
speech: {
async create() {
return {
async arrayBuffer() {
return Uint8Array.from([1, 2, 3]).buffer;
},
};
},
apiKey: "qwen-key",
baseURL: "https://qwen.example/v1",
fetchImpl: async (url, init) => {
calls.push({ url, init });
return {
ok: true,
status: 200,
async arrayBuffer() {
return Uint8Array.from([1, 2, 3]).buffer;
},
},
};
},
});
const bytes = await adapter.synthesize("hello");
assert.equal(Buffer.isBuffer(bytes), true);
assert.equal(bytes.length, 3);
assert.equal(calls.length, 1);
assert.equal(calls[0].url, "https://qwen.example/v1/audio/speech");
assert.match(String(calls[0].init.headers.authorization), /^Bearer qwen-key$/);
assert.match(String(calls[0].init.body), /"model":"qwen-tts-latest"/);
});
test("throws when tts adapter is not configured", async () => {
const adapter = createTTSAdapter({});
await assert.rejects(() => adapter.synthesize("hello"), /tts_not_configured/);
});
test("throws with upstream status code when synthesis fails", async () => {
const adapter = createTTSAdapter({
apiKey: "qwen-key",
fetchImpl: async () => ({
ok: false,
status: 401,
async arrayBuffer() {
return new ArrayBuffer(0);
},
}),
});
await assert.rejects(() => adapter.synthesize("hello"), /tts_request_failed:401/);
});