@zhivex-ai/qwen 0.15.3 → 0.16.2
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 +46 -1
- package/dist/browser-realtime.d.ts +58 -0
- package/dist/browser-realtime.d.ts.map +1 -0
- package/dist/browser-realtime.js +259 -0
- package/dist/browser-realtime.js.map +1 -0
- package/dist/browser.d.ts +9 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +7 -0
- package/dist/browser.js.map +1 -0
- package/dist/cloud-media.d.ts +89 -0
- package/dist/cloud-media.d.ts.map +1 -0
- package/dist/cloud-media.js +221 -0
- package/dist/cloud-media.js.map +1 -0
- package/dist/cloud-realtime.d.ts +58 -0
- package/dist/cloud-realtime.d.ts.map +1 -0
- package/dist/cloud-realtime.js +123 -0
- package/dist/cloud-realtime.js.map +1 -0
- package/dist/decision.d.ts +69 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +122 -0
- package/dist/decision.js.map +1 -0
- package/dist/embeddings.d.ts +30 -0
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +94 -0
- package/dist/embeddings.js.map +1 -0
- package/dist/index.d.ts +40 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -144
- package/dist/index.js.map +1 -1
- package/dist/inference-audio.d.ts +146 -0
- package/dist/inference-audio.d.ts.map +1 -0
- package/dist/inference-audio.js +256 -0
- package/dist/inference-audio.js.map +1 -0
- package/dist/native-asr.d.ts +52 -0
- package/dist/native-asr.d.ts.map +1 -0
- package/dist/native-asr.js +162 -0
- package/dist/native-asr.js.map +1 -0
- package/dist/rtc-protocol.d.ts +10 -0
- package/dist/rtc-protocol.d.ts.map +1 -0
- package/dist/rtc-protocol.js +10 -0
- package/dist/rtc-protocol.js.map +1 -0
- package/dist/sdp-exchange.d.ts +8 -0
- package/dist/sdp-exchange.d.ts.map +1 -0
- package/dist/sdp-exchange.js +25 -0
- package/dist/sdp-exchange.js.map +1 -0
- package/dist/temporary-keys.d.ts +15 -0
- package/dist/temporary-keys.d.ts.map +1 -0
- package/dist/temporary-keys.js +28 -0
- package/dist/temporary-keys.js.map +1 -0
- package/dist/text-profiles.d.ts +7 -0
- package/dist/text-profiles.d.ts.map +1 -0
- package/dist/text-profiles.js +55 -0
- package/dist/text-profiles.js.map +1 -0
- package/dist/url-path.d.ts +3 -0
- package/dist/url-path.d.ts.map +1 -0
- package/dist/url-path.js +8 -0
- package/dist/url-path.js.map +1 -0
- package/dist/world-rtc.d.ts +30 -0
- package/dist/world-rtc.d.ts.map +1 -0
- package/dist/world-rtc.js +33 -0
- package/dist/world-rtc.js.map +1 -0
- package/dist/worlds.d.ts +134 -0
- package/dist/worlds.d.ts.map +1 -0
- package/dist/worlds.js +196 -0
- package/dist/worlds.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type RealtimeConnectionFactory, type SpeechModel, type SpeechModelInput, type SpeechResult, type TranscriptionModel, type TranscriptionModelInput, type TranscriptionResult } from "@zhivex-ai/core";
|
|
2
|
+
export interface QwenCloudSpeechOptions extends Record<string, unknown> {
|
|
3
|
+
format?: "pcm" | "wav" | "mp3" | "opus";
|
|
4
|
+
sample_rate?: 8000 | 16000 | 22050 | 24000 | 44100 | 48000;
|
|
5
|
+
volume?: number;
|
|
6
|
+
rate?: number;
|
|
7
|
+
pitch?: number;
|
|
8
|
+
instruction?: string;
|
|
9
|
+
enable_ssml?: boolean;
|
|
10
|
+
seed?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface QwenCloudASROptions extends Record<string, unknown> {
|
|
13
|
+
format?: "pcm" | "wav" | "mp3" | "opus" | "speex" | "aac" | "amr";
|
|
14
|
+
sample_rate?: number;
|
|
15
|
+
vocabulary?: Record<string, number>;
|
|
16
|
+
vocabulary_id?: string;
|
|
17
|
+
language_hints?: string[];
|
|
18
|
+
semantic_punctuation_enabled?: boolean;
|
|
19
|
+
disfluency_removal_enabled?: boolean;
|
|
20
|
+
context?: Array<{
|
|
21
|
+
role: "user" | "assistant";
|
|
22
|
+
content: Array<{
|
|
23
|
+
type: "input_text" | "text";
|
|
24
|
+
text: string;
|
|
25
|
+
}>;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export interface QwenASRTranscript {
|
|
29
|
+
text: string;
|
|
30
|
+
isFinal: boolean;
|
|
31
|
+
beginTimeMs?: number;
|
|
32
|
+
endTimeMs?: number;
|
|
33
|
+
rawResponse: unknown;
|
|
34
|
+
}
|
|
35
|
+
export declare const isQwenCloudSpeech: (id: string) => boolean;
|
|
36
|
+
export declare const isQwenCloudStreamingASR: (id: string) => boolean;
|
|
37
|
+
/** DashScope duplex inference transport. Generates MP3 by default; no paid-task retries. */
|
|
38
|
+
export declare class QwenCloudSpeechModel implements SpeechModel<QwenCloudSpeechOptions> {
|
|
39
|
+
readonly modelId: string;
|
|
40
|
+
private readonly apiKey;
|
|
41
|
+
private readonly inferenceURL;
|
|
42
|
+
private readonly factory;
|
|
43
|
+
readonly provider = "qwen";
|
|
44
|
+
readonly capabilities: {
|
|
45
|
+
toolHistory?: "native" | "json";
|
|
46
|
+
streaming: boolean;
|
|
47
|
+
tools: boolean;
|
|
48
|
+
structuredOutput: boolean;
|
|
49
|
+
jsonMode: boolean;
|
|
50
|
+
toolChoice: boolean;
|
|
51
|
+
parallelToolCalls: boolean;
|
|
52
|
+
inputMediaTypes?: readonly string[];
|
|
53
|
+
vision: boolean;
|
|
54
|
+
files: boolean;
|
|
55
|
+
audioInput: boolean;
|
|
56
|
+
audioOutput: boolean;
|
|
57
|
+
imageGeneration?: boolean;
|
|
58
|
+
videoGeneration?: boolean;
|
|
59
|
+
musicGeneration?: boolean;
|
|
60
|
+
fileSearch?: boolean;
|
|
61
|
+
urlContext?: boolean;
|
|
62
|
+
contextCaching?: boolean;
|
|
63
|
+
explicitPromptCaching?: boolean;
|
|
64
|
+
batch?: boolean;
|
|
65
|
+
interactions?: boolean;
|
|
66
|
+
rawPrediction?: boolean;
|
|
67
|
+
reasoningEfforts?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["effort"]>>;
|
|
68
|
+
reasoningModes?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["mode"]>>;
|
|
69
|
+
reasoningContexts?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["context"]>>;
|
|
70
|
+
computerUse?: boolean;
|
|
71
|
+
reasoning: boolean;
|
|
72
|
+
webSearch: boolean;
|
|
73
|
+
realtime?: {
|
|
74
|
+
sessions: boolean;
|
|
75
|
+
audioInput: boolean;
|
|
76
|
+
audioOutput: boolean;
|
|
77
|
+
imageInput: boolean;
|
|
78
|
+
tools: boolean;
|
|
79
|
+
browserTokens: boolean;
|
|
80
|
+
fullDuplex?: boolean;
|
|
81
|
+
clientDelegation?: boolean;
|
|
82
|
+
};
|
|
83
|
+
agentCapabilities?: import("@zhivex-ai/core").AgentCapabilities;
|
|
84
|
+
embeddings: boolean;
|
|
85
|
+
};
|
|
86
|
+
constructor(modelId: string, apiKey: string, inferenceURL: string, factory?: RealtimeConnectionFactory);
|
|
87
|
+
streamSpeech(input: SpeechModelInput<QwenCloudSpeechOptions>): Promise<AsyncIterable<SpeechResult>>;
|
|
88
|
+
generateSpeech(input: SpeechModelInput<QwenCloudSpeechOptions>): Promise<SpeechResult>;
|
|
89
|
+
}
|
|
90
|
+
/** Streaming ASR over binary inference frames; supports recorded audio and incremental input. */
|
|
91
|
+
export declare class QwenCloudStreamingASRModel implements TranscriptionModel<QwenCloudASROptions> {
|
|
92
|
+
readonly modelId: string;
|
|
93
|
+
private readonly apiKey;
|
|
94
|
+
private readonly inferenceURL;
|
|
95
|
+
private readonly factory;
|
|
96
|
+
readonly provider = "qwen";
|
|
97
|
+
readonly capabilities: {
|
|
98
|
+
toolHistory?: "native" | "json";
|
|
99
|
+
streaming: boolean;
|
|
100
|
+
tools: boolean;
|
|
101
|
+
structuredOutput: boolean;
|
|
102
|
+
jsonMode: boolean;
|
|
103
|
+
toolChoice: boolean;
|
|
104
|
+
parallelToolCalls: boolean;
|
|
105
|
+
inputMediaTypes?: readonly string[];
|
|
106
|
+
vision: boolean;
|
|
107
|
+
files: boolean;
|
|
108
|
+
audioInput: boolean;
|
|
109
|
+
audioOutput: boolean;
|
|
110
|
+
imageGeneration?: boolean;
|
|
111
|
+
videoGeneration?: boolean;
|
|
112
|
+
musicGeneration?: boolean;
|
|
113
|
+
fileSearch?: boolean;
|
|
114
|
+
urlContext?: boolean;
|
|
115
|
+
contextCaching?: boolean;
|
|
116
|
+
explicitPromptCaching?: boolean;
|
|
117
|
+
batch?: boolean;
|
|
118
|
+
interactions?: boolean;
|
|
119
|
+
rawPrediction?: boolean;
|
|
120
|
+
reasoningEfforts?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["effort"]>>;
|
|
121
|
+
reasoningModes?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["mode"]>>;
|
|
122
|
+
reasoningContexts?: Array<NonNullable<import("@zhivex-ai/core").ReasoningConfig["context"]>>;
|
|
123
|
+
computerUse?: boolean;
|
|
124
|
+
reasoning: boolean;
|
|
125
|
+
webSearch: boolean;
|
|
126
|
+
realtime?: {
|
|
127
|
+
sessions: boolean;
|
|
128
|
+
audioInput: boolean;
|
|
129
|
+
audioOutput: boolean;
|
|
130
|
+
imageInput: boolean;
|
|
131
|
+
tools: boolean;
|
|
132
|
+
browserTokens: boolean;
|
|
133
|
+
fullDuplex?: boolean;
|
|
134
|
+
clientDelegation?: boolean;
|
|
135
|
+
};
|
|
136
|
+
agentCapabilities?: import("@zhivex-ai/core").AgentCapabilities;
|
|
137
|
+
embeddings: boolean;
|
|
138
|
+
};
|
|
139
|
+
constructor(modelId: string, apiKey: string, inferenceURL: string, factory?: RealtimeConnectionFactory);
|
|
140
|
+
streamTranscription(input: Omit<TranscriptionModelInput<QwenCloudASROptions>, "audio"> & {
|
|
141
|
+
audio: AsyncIterable<Uint8Array>;
|
|
142
|
+
format?: QwenCloudASROptions["format"];
|
|
143
|
+
}): Promise<AsyncIterable<QwenASRTranscript>>;
|
|
144
|
+
transcribe(input: TranscriptionModelInput<QwenCloudASROptions>): Promise<TranscriptionResult>;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=inference-audio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-audio.d.ts","sourceRoot":"","sources":["../src/inference-audio.ts"],"names":[],"mappings":"AAAA,OAAO,EAGoB,KAAK,yBAAyB,EAAE,KAAK,WAAW,EACzE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,kBAAkB,EAAE,KAAK,uBAAuB,EAC/F,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,sBAAuB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACrE,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IACxC,WAAW,CAAC,EAAE,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClE,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,aAAa,CAAC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,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAS3F;CACF;AAED,iGAAiG;AACjG,qBAAa,0BAA2B,YAAW,kBAAkB,CAAC,mBAAmB,CAAC;IAG5E,QAAQ,CAAC,OAAO,EAAE,MAAM;IAAE,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAU,OAAO,CAAC,QAAQ,CAAC,YAAY;IAClG,OAAO,CAAC,QAAQ,CAAC,OAAO;IAH1B,QAAQ,CAAC,QAAQ,UAAU;IAC3B,QAAQ,CAAC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAuD;IAC5E,YAAqB,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM,EAAmB,YAAY,EAAE,MAAM,EACzF,OAAO,GAAE,yBAAmD,EAAI;IAE7E,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,uBAAuB,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC,GAAG;QAC7F,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;KAC1E,GAAG,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CA0D5C;IACK,UAAU,CAAC,KAAK,EAAE,uBAAuB,CAAC,mBAAmB,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAWlG;CACF"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { ConfigurationError, ProviderHTTPError, UnsupportedFeatureError, openWebSocketConnection, withTimeoutSignal, decodeBase64WithLimit } from "@zhivex-ai/core";
|
|
2
|
+
import { speechCapabilities, transcriptionCapabilities } from "./capabilities.js";
|
|
3
|
+
export const isQwenCloudSpeech = (id) => /^qwen-audio-3\.[01]-tts-(flash|plus)(?:-|$)/i.test(id);
|
|
4
|
+
export const isQwenCloudStreamingASR = (id) => /^qwen-audio-3\.[01]-asr-flash-streaming(?:-|$)/i.test(id);
|
|
5
|
+
const MAX_AUDIO_BYTES = 32 * 1024 * 1024;
|
|
6
|
+
const envelope = (action, taskId, payload) => ({
|
|
7
|
+
header: { action, task_id: taskId, streaming: "duplex" }, payload
|
|
8
|
+
});
|
|
9
|
+
const record = (value) => {
|
|
10
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value instanceof Uint8Array) {
|
|
11
|
+
throw new ProviderHTTPError("Qwen inference returned an invalid event.", 502);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
const event = (value, taskId) => {
|
|
16
|
+
const message = record(value);
|
|
17
|
+
if (message.header?.task_id !== taskId)
|
|
18
|
+
throw new ProviderHTTPError("Qwen inference task ID mismatch.", 502);
|
|
19
|
+
if (message.header.event === "task-failed") {
|
|
20
|
+
throw new ProviderHTTPError(String(message.header.error_message ?? "Qwen inference task failed."), 502, {
|
|
21
|
+
responseBody: JSON.stringify({ code: message.header.error_code, task_id: taskId })
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return message;
|
|
25
|
+
};
|
|
26
|
+
const checkRange = (value, name, min, max) => {
|
|
27
|
+
if (value !== undefined && (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max)) {
|
|
28
|
+
throw new ConfigurationError(`${name} must be between ${min} and ${max}.`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const connect = async (factory, url, key, signal, timeoutMs) => {
|
|
32
|
+
const connection = await factory(url, { authorization: `Bearer ${key}` }, { signal, timeoutMs, maxIncomingFrameBytes: MAX_AUDIO_BYTES });
|
|
33
|
+
if (!connection.recvFrame || !connection.sendBinary) {
|
|
34
|
+
await connection.close();
|
|
35
|
+
throw new UnsupportedFeatureError("Qwen inference audio requires a binary-capable RealtimeConnection (recvFrame/sendBinary).");
|
|
36
|
+
}
|
|
37
|
+
return connection;
|
|
38
|
+
};
|
|
39
|
+
const waitWithSignal = async (pending, signal) => {
|
|
40
|
+
if (signal.aborted) {
|
|
41
|
+
void pending.catch(() => { });
|
|
42
|
+
throw signal.reason;
|
|
43
|
+
}
|
|
44
|
+
let onAbort = () => { };
|
|
45
|
+
try {
|
|
46
|
+
return await Promise.race([
|
|
47
|
+
pending,
|
|
48
|
+
new Promise((_, reject) => {
|
|
49
|
+
onAbort = () => reject(signal.reason);
|
|
50
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
51
|
+
if (signal.aborted)
|
|
52
|
+
onAbort();
|
|
53
|
+
})
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
signal.removeEventListener("abort", onAbort);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const receive = (connection, signal) => waitWithSignal(connection.recvFrame(), signal);
|
|
61
|
+
/** DashScope duplex inference transport. Generates MP3 by default; no paid-task retries. */
|
|
62
|
+
export class QwenCloudSpeechModel {
|
|
63
|
+
modelId;
|
|
64
|
+
apiKey;
|
|
65
|
+
inferenceURL;
|
|
66
|
+
factory;
|
|
67
|
+
provider = "qwen";
|
|
68
|
+
capabilities = { ...speechCapabilities, embeddings: false };
|
|
69
|
+
constructor(modelId, apiKey, inferenceURL, factory = openWebSocketConnection) {
|
|
70
|
+
this.modelId = modelId;
|
|
71
|
+
this.apiKey = apiKey;
|
|
72
|
+
this.inferenceURL = inferenceURL;
|
|
73
|
+
this.factory = factory;
|
|
74
|
+
}
|
|
75
|
+
async streamSpeech(input) {
|
|
76
|
+
if (!input.input.trim())
|
|
77
|
+
throw new ConfigurationError("Qwen speech requires nonempty text.");
|
|
78
|
+
const parameters = { ...(input.providerOptions ?? {}) };
|
|
79
|
+
const format = parameters.format ?? "mp3";
|
|
80
|
+
if (!["pcm", "wav", "mp3", "opus"].includes(format))
|
|
81
|
+
throw new ConfigurationError("Unsupported speech format.");
|
|
82
|
+
if (parameters.sample_rate !== undefined && ![8000, 16000, 22050, 24000, 44100, 48000].includes(parameters.sample_rate))
|
|
83
|
+
throw new ConfigurationError("Unsupported speech sample rate.");
|
|
84
|
+
checkRange(parameters.volume, "volume", 0, 100);
|
|
85
|
+
checkRange(parameters.rate, "rate", 0.5, 2);
|
|
86
|
+
checkRange(parameters.pitch, "pitch", 0.5, 2);
|
|
87
|
+
const mediaType = ({ pcm: "audio/pcm", wav: "audio/wav", mp3: "audio/mpeg", opus: "audio/opus" })[format];
|
|
88
|
+
const self = this;
|
|
89
|
+
return (async function* () {
|
|
90
|
+
const { signal, cleanup, abort } = withTimeoutSignal({ ...input, timeoutMs: input.timeoutMs ?? 60_000 });
|
|
91
|
+
let connection;
|
|
92
|
+
try {
|
|
93
|
+
connection = await connect(self.factory, self.inferenceURL, self.apiKey, signal, input.timeoutMs ?? 60_000);
|
|
94
|
+
const taskId = crypto.randomUUID();
|
|
95
|
+
await connection.sendJson(envelope("run-task", taskId, {
|
|
96
|
+
task_group: "audio", task: "tts", function: "SpeechSynthesizer", model: self.modelId,
|
|
97
|
+
parameters: { text_type: "PlainText", ...parameters, voice: input.voice ?? "longanhuan_v3.6", format }, input: {}
|
|
98
|
+
}));
|
|
99
|
+
const started = event(await receive(connection, signal), taskId);
|
|
100
|
+
if (started.header.event !== "task-started")
|
|
101
|
+
throw new ProviderHTTPError("Expected Qwen task-started event.", 502);
|
|
102
|
+
await connection.sendJson(envelope("continue-task", taskId, { input: { text: input.input } }));
|
|
103
|
+
await connection.sendJson(envelope("finish-task", taskId, { input: {} }));
|
|
104
|
+
let totalBytes = 0;
|
|
105
|
+
while (true) {
|
|
106
|
+
const frame = await receive(connection, signal);
|
|
107
|
+
if (frame === undefined)
|
|
108
|
+
throw new ProviderHTTPError("Qwen speech closed before task-finished.", 502);
|
|
109
|
+
if (frame instanceof Uint8Array) {
|
|
110
|
+
totalBytes += frame.byteLength;
|
|
111
|
+
if (totalBytes > MAX_AUDIO_BYTES)
|
|
112
|
+
throw new ProviderHTTPError("Qwen speech exceeds the 32 MiB output limit.", 502);
|
|
113
|
+
if (frame.byteLength)
|
|
114
|
+
yield { audio: frame, mediaType, rawResponse: { task_id: taskId } };
|
|
115
|
+
}
|
|
116
|
+
else if (event(frame, taskId).header.event === "task-finished") {
|
|
117
|
+
if (!totalBytes)
|
|
118
|
+
throw new ProviderHTTPError("Qwen speech returned no audio.", 502);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
abort();
|
|
125
|
+
cleanup();
|
|
126
|
+
await connection?.close();
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
}
|
|
130
|
+
async generateSpeech(input) {
|
|
131
|
+
const chunks = [];
|
|
132
|
+
let mediaType = "audio/mpeg";
|
|
133
|
+
let rawResponse;
|
|
134
|
+
for await (const chunk of await this.streamSpeech(input)) {
|
|
135
|
+
chunks.push(chunk.audio);
|
|
136
|
+
mediaType = chunk.mediaType;
|
|
137
|
+
rawResponse = chunk.rawResponse;
|
|
138
|
+
}
|
|
139
|
+
const audio = new Uint8Array(chunks.reduce((n, chunk) => n + chunk.length, 0));
|
|
140
|
+
let offset = 0;
|
|
141
|
+
for (const chunk of chunks) {
|
|
142
|
+
audio.set(chunk, offset);
|
|
143
|
+
offset += chunk.length;
|
|
144
|
+
}
|
|
145
|
+
return { audio, mediaType, rawResponse };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Streaming ASR over binary inference frames; supports recorded audio and incremental input. */
|
|
149
|
+
export class QwenCloudStreamingASRModel {
|
|
150
|
+
modelId;
|
|
151
|
+
apiKey;
|
|
152
|
+
inferenceURL;
|
|
153
|
+
factory;
|
|
154
|
+
provider = "qwen";
|
|
155
|
+
capabilities = { ...transcriptionCapabilities, embeddings: false };
|
|
156
|
+
constructor(modelId, apiKey, inferenceURL, factory = openWebSocketConnection) {
|
|
157
|
+
this.modelId = modelId;
|
|
158
|
+
this.apiKey = apiKey;
|
|
159
|
+
this.inferenceURL = inferenceURL;
|
|
160
|
+
this.factory = factory;
|
|
161
|
+
}
|
|
162
|
+
async streamTranscription(input) {
|
|
163
|
+
const { context, ...parameters } = input.providerOptions ?? {};
|
|
164
|
+
const format = input.format ?? parameters.format ?? "pcm";
|
|
165
|
+
if (!["pcm", "wav", "mp3", "opus", "speex", "aac", "amr"].includes(format))
|
|
166
|
+
throw new ConfigurationError("Unsupported ASR format.");
|
|
167
|
+
const sampleRate = parameters.sample_rate ?? 16000;
|
|
168
|
+
checkRange(sampleRate, "sample_rate", 8000, 48000);
|
|
169
|
+
if (!Number.isInteger(sampleRate))
|
|
170
|
+
throw new ConfigurationError("sample_rate must be an integer.");
|
|
171
|
+
if (input.prompt && context)
|
|
172
|
+
throw new ConfigurationError("Use prompt or context, not both.");
|
|
173
|
+
const self = this;
|
|
174
|
+
return (async function* () {
|
|
175
|
+
const { signal, cleanup, abort } = withTimeoutSignal({ ...input, timeoutMs: input.timeoutMs ?? 60_000 });
|
|
176
|
+
let connection;
|
|
177
|
+
let sending;
|
|
178
|
+
try {
|
|
179
|
+
connection = await connect(self.factory, self.inferenceURL, self.apiKey, signal, input.timeoutMs ?? 60_000);
|
|
180
|
+
const taskId = crypto.randomUUID();
|
|
181
|
+
await connection.sendJson(envelope("run-task", taskId, {
|
|
182
|
+
task_group: "audio", task: "asr", function: "recognition", model: self.modelId,
|
|
183
|
+
parameters: { ...parameters, format, sample_rate: sampleRate, ...(input.language ? { language_hints: [input.language] } : {}) },
|
|
184
|
+
input: { ...(context ? { context } : input.prompt ? { context: [{ role: "user", content: [{ type: "input_text", text: input.prompt }] }] } : {}) }
|
|
185
|
+
}));
|
|
186
|
+
if (event(await receive(connection, signal), taskId).header.event !== "task-started")
|
|
187
|
+
throw new ProviderHTTPError("Expected Qwen task-started event.", 502);
|
|
188
|
+
const socket = connection;
|
|
189
|
+
sending = (async () => {
|
|
190
|
+
let total = 0;
|
|
191
|
+
const iterator = input.audio[Symbol.asyncIterator]();
|
|
192
|
+
try {
|
|
193
|
+
while (true) {
|
|
194
|
+
const next = await waitWithSignal(iterator.next(), signal);
|
|
195
|
+
if (next.done)
|
|
196
|
+
break;
|
|
197
|
+
const chunk = next.value;
|
|
198
|
+
total += chunk.byteLength;
|
|
199
|
+
if (total > MAX_AUDIO_BYTES)
|
|
200
|
+
throw new ConfigurationError("Streaming ASR input exceeds the 32 MiB session limit.");
|
|
201
|
+
for (let offset = 0; offset < chunk.length; offset += 3200)
|
|
202
|
+
await waitWithSignal(socket.sendBinary(chunk.subarray(offset, offset + 3200)), signal);
|
|
203
|
+
}
|
|
204
|
+
await socket.sendJson(envelope("finish-task", taskId, { input: {} }));
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
// A caller's source may be stalled; request cancellation without blocking socket teardown.
|
|
208
|
+
void iterator.return?.().catch(() => { });
|
|
209
|
+
}
|
|
210
|
+
})();
|
|
211
|
+
// Attach rejection immediately while the receiver consumes incremental results.
|
|
212
|
+
const sendFailure = sending.then(() => new Promise(() => { }));
|
|
213
|
+
void sendFailure.catch(() => { });
|
|
214
|
+
while (true) {
|
|
215
|
+
const frame = await Promise.race([receive(connection, signal), sendFailure]);
|
|
216
|
+
if (frame === undefined)
|
|
217
|
+
throw new ProviderHTTPError("Qwen ASR closed before task-finished.", 502);
|
|
218
|
+
const message = event(frame, taskId);
|
|
219
|
+
if (message.header.event === "task-finished") {
|
|
220
|
+
await waitWithSignal(sending, signal);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (message.header.event === "result-generated") {
|
|
224
|
+
const sentence = message.payload?.output?.sentence;
|
|
225
|
+
if (!sentence || typeof sentence.text !== "string")
|
|
226
|
+
throw new ProviderHTTPError("Invalid ASR transcript event.", 502);
|
|
227
|
+
yield { text: sentence.text, isFinal: sentence.sentence_end === true, beginTimeMs: sentence.begin_time,
|
|
228
|
+
endTimeMs: sentence.end_time, rawResponse: message };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
abort();
|
|
234
|
+
cleanup();
|
|
235
|
+
await connection?.close();
|
|
236
|
+
void sending?.catch(() => { });
|
|
237
|
+
}
|
|
238
|
+
})();
|
|
239
|
+
}
|
|
240
|
+
async transcribe(input) {
|
|
241
|
+
const data = input.audio.data;
|
|
242
|
+
const bytes = typeof data === "string"
|
|
243
|
+
? decodeBase64WithLimit(data.startsWith("data:") ? data.slice(data.indexOf(",") + 1) : data, { maxBytes: MAX_AUDIO_BYTES, provider: "qwen", endpoint: "inference" })
|
|
244
|
+
: data instanceof Uint8Array ? data : new Uint8Array(data);
|
|
245
|
+
const format = input.providerOptions?.format ?? { "audio/pcm": "pcm", "audio/wav": "wav", "audio/mpeg": "mp3", "audio/opus": "opus", "audio/aac": "aac" }[input.audio.mediaType];
|
|
246
|
+
if (!format)
|
|
247
|
+
throw new ConfigurationError("Specify a supported ASR audio format.");
|
|
248
|
+
const sentences = [];
|
|
249
|
+
const source = (async function* () { yield bytes; })();
|
|
250
|
+
for await (const sentence of await this.streamTranscription({ ...input, audio: source, format }))
|
|
251
|
+
if (sentence.isFinal)
|
|
252
|
+
sentences.push(sentence);
|
|
253
|
+
return { text: sentences.map(sentence => sentence.text).join(""), rawResponse: { sentences } };
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=inference-audio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inference-audio.js","sourceRoot":"","sources":["../src/inference-audio.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,uBAAuB,EACvF,iBAAiB,EAAE,qBAAqB,EAIzC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AA6BlF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,8CAA8C,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzG,MAAM,CAAC,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EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAY,CAAC,KAAK,CAAC,KAAK,CAAC,SAAwB,CAAC,CAAC;QAC3M,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,kBAAkB,CAAC,uCAAuC,CAAC,CAAC;QACnF,MAAM,SAAS,GAAwB,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,CAAC,KAAK,SAAS,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,EAAE,MAAM,QAAQ,IAAI,MAAM,IAAI,CAAC,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YAAE,IAAI,QAAQ,CAAC,OAAO;gBAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjJ,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC;IACjG,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type TranscriptionModel } from "@zhivex-ai/core/provider";
|
|
2
|
+
export interface QwenNativeASROptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
taskBaseURL: string;
|
|
5
|
+
fetch?: typeof globalThis.fetch;
|
|
6
|
+
allowUnsafeEndpoints?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface QwenASRRequestOptions {
|
|
9
|
+
abortSignal?: AbortSignal;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface QwenFileTranscriptionInput extends QwenASRRequestOptions {
|
|
13
|
+
fileURL: string;
|
|
14
|
+
languageHints?: string[];
|
|
15
|
+
channelIds?: number[];
|
|
16
|
+
diarization?: boolean;
|
|
17
|
+
speakerCount?: number;
|
|
18
|
+
keepDialect?: boolean;
|
|
19
|
+
vocabularyId?: string;
|
|
20
|
+
vocabulary?: Record<string, number>;
|
|
21
|
+
context?: Array<{
|
|
22
|
+
role: "user" | "assistant";
|
|
23
|
+
content: Array<{
|
|
24
|
+
type: "input_text" | "text";
|
|
25
|
+
text: string;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
export interface QwenFileTranscriptionTask {
|
|
30
|
+
taskId: string;
|
|
31
|
+
status: "PENDING" | "RUNNING" | "SUCCEEDED" | "FAILED" | "CANCELED" | "UNKNOWN";
|
|
32
|
+
requestId?: string;
|
|
33
|
+
code?: string;
|
|
34
|
+
durationSeconds?: number;
|
|
35
|
+
results?: Array<{
|
|
36
|
+
fileURL: string;
|
|
37
|
+
status: "SUCCEEDED" | "FAILED";
|
|
38
|
+
transcriptionURL?: string;
|
|
39
|
+
code?: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export interface QwenFileTranscriptionModel {
|
|
43
|
+
readonly provider: "qwen";
|
|
44
|
+
readonly modelId: string;
|
|
45
|
+
submit(input: QwenFileTranscriptionInput): Promise<QwenFileTranscriptionTask>;
|
|
46
|
+
get(input: QwenASRRequestOptions & {
|
|
47
|
+
taskId: string;
|
|
48
|
+
}): Promise<QwenFileTranscriptionTask>;
|
|
49
|
+
}
|
|
50
|
+
export declare function createQwenFileTranscriptionModel(modelId: string, options: QwenNativeASROptions): QwenFileTranscriptionModel;
|
|
51
|
+
export declare function createQwenNativeTranscriptionModel(modelId: string, options: QwenNativeASROptions): TranscriptionModel;
|
|
52
|
+
//# sourceMappingURL=native-asr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-asr.d.ts","sourceRoot":"","sources":["../src/native-asr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuH,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEx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