@amaster.ai/asr-http-client 1.0.0-beta.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/LICENSE +21 -0
- package/dist/index.cjs +204 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +34 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Amaster Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createASRHttpClient: () => createASRHttpClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/asr-http-client.ts
|
|
28
|
+
function createASRHttpClient(config) {
|
|
29
|
+
const {
|
|
30
|
+
url,
|
|
31
|
+
language = "zh",
|
|
32
|
+
sampleRate = 16e3,
|
|
33
|
+
onRecordingStart,
|
|
34
|
+
onRecordingStop,
|
|
35
|
+
onResult,
|
|
36
|
+
onError
|
|
37
|
+
} = config;
|
|
38
|
+
let mediaStream = null;
|
|
39
|
+
let audioContext = null;
|
|
40
|
+
let processor = null;
|
|
41
|
+
let audioChunks = [];
|
|
42
|
+
let isRecording = false;
|
|
43
|
+
async function startRecording() {
|
|
44
|
+
if (isRecording) return;
|
|
45
|
+
try {
|
|
46
|
+
mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
47
|
+
audio: { sampleRate, channelCount: 1, echoCancellation: true }
|
|
48
|
+
});
|
|
49
|
+
audioContext = new AudioContext({ sampleRate });
|
|
50
|
+
const source = audioContext.createMediaStreamSource(mediaStream);
|
|
51
|
+
processor = audioContext.createScriptProcessor(4096, 1, 1);
|
|
52
|
+
audioChunks = [];
|
|
53
|
+
processor.onaudioprocess = (e) => {
|
|
54
|
+
if (!isRecording) return;
|
|
55
|
+
const inputData = e.inputBuffer.getChannelData(0);
|
|
56
|
+
const pcm = new Int16Array(inputData.length);
|
|
57
|
+
for (let i = 0; i < inputData.length; i++) {
|
|
58
|
+
const s = Math.max(-1, Math.min(1, inputData[i]));
|
|
59
|
+
pcm[i] = s < 0 ? s * 32768 : s * 32767;
|
|
60
|
+
}
|
|
61
|
+
audioChunks.push(pcm);
|
|
62
|
+
};
|
|
63
|
+
source.connect(processor);
|
|
64
|
+
processor.connect(audioContext.destination);
|
|
65
|
+
isRecording = true;
|
|
66
|
+
onRecordingStart?.();
|
|
67
|
+
} catch (err) {
|
|
68
|
+
onError?.(err);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function stopRecording() {
|
|
73
|
+
if (!isRecording) throw new Error("Not recording");
|
|
74
|
+
isRecording = false;
|
|
75
|
+
onRecordingStop?.();
|
|
76
|
+
if (mediaStream) {
|
|
77
|
+
mediaStream.getTracks().forEach((t) => t.stop());
|
|
78
|
+
mediaStream = null;
|
|
79
|
+
}
|
|
80
|
+
if (processor) {
|
|
81
|
+
processor.disconnect();
|
|
82
|
+
processor = null;
|
|
83
|
+
}
|
|
84
|
+
if (audioContext) {
|
|
85
|
+
await audioContext.close();
|
|
86
|
+
audioContext = null;
|
|
87
|
+
}
|
|
88
|
+
const totalLength = audioChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
89
|
+
const combined = new Int16Array(totalLength);
|
|
90
|
+
let offset = 0;
|
|
91
|
+
for (const chunk of audioChunks) {
|
|
92
|
+
combined.set(chunk, offset);
|
|
93
|
+
offset += chunk.length;
|
|
94
|
+
}
|
|
95
|
+
audioChunks = [];
|
|
96
|
+
const wavBlob = createWavBlob(combined, sampleRate);
|
|
97
|
+
return recognizeBlob(wavBlob);
|
|
98
|
+
}
|
|
99
|
+
async function recordAndRecognize(durationMs) {
|
|
100
|
+
await startRecording();
|
|
101
|
+
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
102
|
+
return stopRecording();
|
|
103
|
+
}
|
|
104
|
+
async function recognizeFile(file) {
|
|
105
|
+
return recognizeBlob(file);
|
|
106
|
+
}
|
|
107
|
+
async function recognizeUrl(audioUrl) {
|
|
108
|
+
try {
|
|
109
|
+
const response = await fetch(url, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: { "Content-Type": "application/json" },
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
model: "qwen3-asr-flash",
|
|
114
|
+
messages: [{
|
|
115
|
+
role: "user",
|
|
116
|
+
content: [{ type: "input_audio", input_audio: { url: audioUrl } }]
|
|
117
|
+
}]
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
throw new Error(`HTTP ${response.status}`);
|
|
122
|
+
}
|
|
123
|
+
const data = await response.json();
|
|
124
|
+
const text = data.choices?.[0]?.message?.content || "";
|
|
125
|
+
onResult?.(text);
|
|
126
|
+
return text;
|
|
127
|
+
} catch (err) {
|
|
128
|
+
onError?.(err);
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function recognizeBlob(blob) {
|
|
133
|
+
try {
|
|
134
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
135
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
136
|
+
let binary = "";
|
|
137
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
138
|
+
binary += String.fromCharCode(bytes[i]);
|
|
139
|
+
}
|
|
140
|
+
const base64 = btoa(binary);
|
|
141
|
+
const dataUrl = `data:audio/wav;base64,${base64}`;
|
|
142
|
+
const response = await fetch(url, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers: { "Content-Type": "application/json" },
|
|
145
|
+
body: JSON.stringify({
|
|
146
|
+
model: "qwen3-asr-flash",
|
|
147
|
+
messages: [{
|
|
148
|
+
role: "user",
|
|
149
|
+
content: [{ type: "input_audio", input_audio: { data: dataUrl } }]
|
|
150
|
+
}]
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
throw new Error(`HTTP ${response.status}`);
|
|
155
|
+
}
|
|
156
|
+
const data = await response.json();
|
|
157
|
+
const text = data.choices?.[0]?.message?.content || "";
|
|
158
|
+
onResult?.(text);
|
|
159
|
+
return text;
|
|
160
|
+
} catch (err) {
|
|
161
|
+
onError?.(err);
|
|
162
|
+
throw err;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function createWavBlob(samples, rate) {
|
|
166
|
+
const buffer = new ArrayBuffer(44 + samples.length * 2);
|
|
167
|
+
const view = new DataView(buffer);
|
|
168
|
+
const writeString = (offset2, str) => {
|
|
169
|
+
for (let i = 0; i < str.length; i++) {
|
|
170
|
+
view.setUint8(offset2 + i, str.charCodeAt(i));
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
writeString(0, "RIFF");
|
|
174
|
+
view.setUint32(4, 36 + samples.length * 2, true);
|
|
175
|
+
writeString(8, "WAVE");
|
|
176
|
+
writeString(12, "fmt ");
|
|
177
|
+
view.setUint32(16, 16, true);
|
|
178
|
+
view.setUint16(20, 1, true);
|
|
179
|
+
view.setUint16(22, 1, true);
|
|
180
|
+
view.setUint32(24, rate, true);
|
|
181
|
+
view.setUint32(28, rate * 2, true);
|
|
182
|
+
view.setUint16(32, 2, true);
|
|
183
|
+
view.setUint16(34, 16, true);
|
|
184
|
+
writeString(36, "data");
|
|
185
|
+
view.setUint32(40, samples.length * 2, true);
|
|
186
|
+
const offset = 44;
|
|
187
|
+
for (let i = 0; i < samples.length; i++) {
|
|
188
|
+
view.setInt16(offset + i * 2, samples[i], true);
|
|
189
|
+
}
|
|
190
|
+
return new Blob([buffer], { type: "audio/wav" });
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
startRecording,
|
|
194
|
+
stopRecording,
|
|
195
|
+
recordAndRecognize,
|
|
196
|
+
recognizeFile,
|
|
197
|
+
recognizeUrl
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
createASRHttpClient
|
|
203
|
+
});
|
|
204
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/asr-http-client.ts"],"sourcesContent":["export type { ASRHttpClient, ASRHttpClientConfig } from './asr-http-client';\nexport { createASRHttpClient } from './asr-http-client';\n","/**\n * HTTP ASR Client - Press-to-talk style speech recognition\n */\n\nexport interface ASRHttpClientConfig {\n /** API endpoint URL */\n url: string;\n /** Language, default 'zh' */\n language?: string;\n /** Sample rate, default 16000 */\n sampleRate?: number;\n /** Called when recording starts */\n onRecordingStart?: () => void;\n /** Called when recording stops */\n onRecordingStop?: () => void;\n /** Called with recognition result */\n onResult?: (text: string) => void;\n /** Called on error */\n onError?: (error: Error) => void;\n}\n\nexport interface ASRHttpClient {\n /** Start recording (press-to-talk) */\n startRecording(): Promise<void>;\n /** Stop recording and get result */\n stopRecording(): Promise<string>;\n /** Record for specific duration then recognize */\n recordAndRecognize(durationMs: number): Promise<string>;\n /** Recognize audio file (File or Blob) */\n recognizeFile(file: File | Blob): Promise<string>;\n /** Recognize audio from URL */\n recognizeUrl(audioUrl: string): Promise<string>;\n}\n\nexport function createASRHttpClient(config: ASRHttpClientConfig): ASRHttpClient {\n const {\n url,\n language = 'zh',\n sampleRate = 16000,\n onRecordingStart,\n onRecordingStop,\n onResult,\n onError,\n } = config;\n\n let mediaStream: MediaStream | null = null;\n let audioContext: AudioContext | null = null;\n let processor: ScriptProcessorNode | null = null;\n let audioChunks: Int16Array[] = [];\n let isRecording = false;\n\n async function startRecording(): Promise<void> {\n if (isRecording) return;\n\n try {\n mediaStream = await navigator.mediaDevices.getUserMedia({\n audio: { sampleRate, channelCount: 1, echoCancellation: true }\n });\n\n audioContext = new AudioContext({ sampleRate });\n const source = audioContext.createMediaStreamSource(mediaStream);\n processor = audioContext.createScriptProcessor(4096, 1, 1);\n audioChunks = [];\n\n processor.onaudioprocess = (e) => {\n if (!isRecording) return;\n const inputData = e.inputBuffer.getChannelData(0);\n const pcm = new Int16Array(inputData.length);\n for (let i = 0; i < inputData.length; i++) {\n const s = Math.max(-1, Math.min(1, inputData[i]));\n pcm[i] = s < 0 ? s * 32768 : s * 32767;\n }\n audioChunks.push(pcm);\n };\n\n source.connect(processor);\n processor.connect(audioContext.destination);\n isRecording = true;\n onRecordingStart?.();\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n async function stopRecording(): Promise<string> {\n if (!isRecording) throw new Error('Not recording');\n\n isRecording = false;\n onRecordingStop?.();\n\n // Stop media\n if (mediaStream) {\n mediaStream.getTracks().forEach(t => t.stop());\n mediaStream = null;\n }\n if (processor) {\n processor.disconnect();\n processor = null;\n }\n if (audioContext) {\n await audioContext.close();\n audioContext = null;\n }\n\n // Combine audio chunks\n const totalLength = audioChunks.reduce((sum, chunk) => sum + chunk.length, 0);\n const combined = new Int16Array(totalLength);\n let offset = 0;\n for (const chunk of audioChunks) {\n combined.set(chunk, offset);\n offset += chunk.length;\n }\n audioChunks = [];\n\n // Convert to WAV\n const wavBlob = createWavBlob(combined, sampleRate);\n return recognizeBlob(wavBlob);\n }\n\n async function recordAndRecognize(durationMs: number): Promise<string> {\n await startRecording();\n await new Promise(resolve => setTimeout(resolve, durationMs));\n return stopRecording();\n }\n\n async function recognizeFile(file: File | Blob): Promise<string> {\n return recognizeBlob(file);\n }\n\n async function recognizeUrl(audioUrl: string): Promise<string> {\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: 'qwen3-asr-flash',\n messages: [{\n role: 'user',\n content: [{ type: 'input_audio', input_audio: { url: audioUrl } }]\n }]\n })\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n const text = data.choices?.[0]?.message?.content || '';\n onResult?.(text);\n return text;\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n async function recognizeBlob(blob: Blob): Promise<string> {\n try {\n // Convert to base64\n const arrayBuffer = await blob.arrayBuffer();\n const bytes = new Uint8Array(arrayBuffer);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n const base64 = btoa(binary);\n const dataUrl = `data:audio/wav;base64,${base64}`;\n\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: 'qwen3-asr-flash',\n messages: [{\n role: 'user',\n content: [{ type: 'input_audio', input_audio: { data: dataUrl } }]\n }]\n })\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n const text = data.choices?.[0]?.message?.content || '';\n onResult?.(text);\n return text;\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n function createWavBlob(samples: Int16Array, rate: number): Blob {\n const buffer = new ArrayBuffer(44 + samples.length * 2);\n const view = new DataView(buffer);\n\n // WAV header\n const writeString = (offset: number, str: string) => {\n for (let i = 0; i < str.length; i++) {\n view.setUint8(offset + i, str.charCodeAt(i));\n }\n };\n\n writeString(0, 'RIFF');\n view.setUint32(4, 36 + samples.length * 2, true);\n writeString(8, 'WAVE');\n writeString(12, 'fmt ');\n view.setUint32(16, 16, true);\n view.setUint16(20, 1, true);\n view.setUint16(22, 1, true);\n view.setUint32(24, rate, true);\n view.setUint32(28, rate * 2, true);\n view.setUint16(32, 2, true);\n view.setUint16(34, 16, true);\n writeString(36, 'data');\n view.setUint32(40, samples.length * 2, true);\n\n // Audio data\n const offset = 44;\n for (let i = 0; i < samples.length; i++) {\n view.setInt16(offset + i * 2, samples[i], true);\n }\n\n return new Blob([buffer], { type: 'audio/wav' });\n }\n\n return {\n startRecording,\n stopRecording,\n recordAndRecognize,\n recognizeFile,\n recognizeUrl,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkCO,SAAS,oBAAoB,QAA4C;AAC9E,QAAM;AAAA,IACJ;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,cAAkC;AACtC,MAAI,eAAoC;AACxC,MAAI,YAAwC;AAC5C,MAAI,cAA4B,CAAC;AACjC,MAAI,cAAc;AAElB,iBAAe,iBAAgC;AAC7C,QAAI,YAAa;AAEjB,QAAI;AACF,oBAAc,MAAM,UAAU,aAAa,aAAa;AAAA,QACtD,OAAO,EAAE,YAAY,cAAc,GAAG,kBAAkB,KAAK;AAAA,MAC/D,CAAC;AAED,qBAAe,IAAI,aAAa,EAAE,WAAW,CAAC;AAC9C,YAAM,SAAS,aAAa,wBAAwB,WAAW;AAC/D,kBAAY,aAAa,sBAAsB,MAAM,GAAG,CAAC;AACzD,oBAAc,CAAC;AAEf,gBAAU,iBAAiB,CAAC,MAAM;AAChC,YAAI,CAAC,YAAa;AAClB,cAAM,YAAY,EAAE,YAAY,eAAe,CAAC;AAChD,cAAM,MAAM,IAAI,WAAW,UAAU,MAAM;AAC3C,iBAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,gBAAM,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;AAChD,cAAI,CAAC,IAAI,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,QACnC;AACA,oBAAY,KAAK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|
2
|
+
* HTTP ASR Client - Press-to-talk style speech recognition
|
|
3
|
+
*/
|
|
4
|
+
interface ASRHttpClientConfig {
|
|
5
|
+
/** API endpoint URL */
|
|
6
|
+
url: string;
|
|
7
|
+
/** Language, default 'zh' */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Sample rate, default 16000 */
|
|
10
|
+
sampleRate?: number;
|
|
11
|
+
/** Called when recording starts */
|
|
12
|
+
onRecordingStart?: () => void;
|
|
13
|
+
/** Called when recording stops */
|
|
14
|
+
onRecordingStop?: () => void;
|
|
15
|
+
/** Called with recognition result */
|
|
16
|
+
onResult?: (text: string) => void;
|
|
17
|
+
/** Called on error */
|
|
18
|
+
onError?: (error: Error) => void;
|
|
19
|
+
}
|
|
20
|
+
interface ASRHttpClient {
|
|
21
|
+
/** Start recording (press-to-talk) */
|
|
22
|
+
startRecording(): Promise<void>;
|
|
23
|
+
/** Stop recording and get result */
|
|
24
|
+
stopRecording(): Promise<string>;
|
|
25
|
+
/** Record for specific duration then recognize */
|
|
26
|
+
recordAndRecognize(durationMs: number): Promise<string>;
|
|
27
|
+
/** Recognize audio file (File or Blob) */
|
|
28
|
+
recognizeFile(file: File | Blob): Promise<string>;
|
|
29
|
+
/** Recognize audio from URL */
|
|
30
|
+
recognizeUrl(audioUrl: string): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
declare function createASRHttpClient(config: ASRHttpClientConfig): ASRHttpClient;
|
|
33
|
+
|
|
34
|
+
export { type ASRHttpClient, type ASRHttpClientConfig, createASRHttpClient };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP ASR Client - Press-to-talk style speech recognition
|
|
3
|
+
*/
|
|
4
|
+
interface ASRHttpClientConfig {
|
|
5
|
+
/** API endpoint URL */
|
|
6
|
+
url: string;
|
|
7
|
+
/** Language, default 'zh' */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Sample rate, default 16000 */
|
|
10
|
+
sampleRate?: number;
|
|
11
|
+
/** Called when recording starts */
|
|
12
|
+
onRecordingStart?: () => void;
|
|
13
|
+
/** Called when recording stops */
|
|
14
|
+
onRecordingStop?: () => void;
|
|
15
|
+
/** Called with recognition result */
|
|
16
|
+
onResult?: (text: string) => void;
|
|
17
|
+
/** Called on error */
|
|
18
|
+
onError?: (error: Error) => void;
|
|
19
|
+
}
|
|
20
|
+
interface ASRHttpClient {
|
|
21
|
+
/** Start recording (press-to-talk) */
|
|
22
|
+
startRecording(): Promise<void>;
|
|
23
|
+
/** Stop recording and get result */
|
|
24
|
+
stopRecording(): Promise<string>;
|
|
25
|
+
/** Record for specific duration then recognize */
|
|
26
|
+
recordAndRecognize(durationMs: number): Promise<string>;
|
|
27
|
+
/** Recognize audio file (File or Blob) */
|
|
28
|
+
recognizeFile(file: File | Blob): Promise<string>;
|
|
29
|
+
/** Recognize audio from URL */
|
|
30
|
+
recognizeUrl(audioUrl: string): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
declare function createASRHttpClient(config: ASRHttpClientConfig): ASRHttpClient;
|
|
33
|
+
|
|
34
|
+
export { type ASRHttpClient, type ASRHttpClientConfig, createASRHttpClient };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// src/asr-http-client.ts
|
|
2
|
+
function createASRHttpClient(config) {
|
|
3
|
+
const {
|
|
4
|
+
url,
|
|
5
|
+
language = "zh",
|
|
6
|
+
sampleRate = 16e3,
|
|
7
|
+
onRecordingStart,
|
|
8
|
+
onRecordingStop,
|
|
9
|
+
onResult,
|
|
10
|
+
onError
|
|
11
|
+
} = config;
|
|
12
|
+
let mediaStream = null;
|
|
13
|
+
let audioContext = null;
|
|
14
|
+
let processor = null;
|
|
15
|
+
let audioChunks = [];
|
|
16
|
+
let isRecording = false;
|
|
17
|
+
async function startRecording() {
|
|
18
|
+
if (isRecording) return;
|
|
19
|
+
try {
|
|
20
|
+
mediaStream = await navigator.mediaDevices.getUserMedia({
|
|
21
|
+
audio: { sampleRate, channelCount: 1, echoCancellation: true }
|
|
22
|
+
});
|
|
23
|
+
audioContext = new AudioContext({ sampleRate });
|
|
24
|
+
const source = audioContext.createMediaStreamSource(mediaStream);
|
|
25
|
+
processor = audioContext.createScriptProcessor(4096, 1, 1);
|
|
26
|
+
audioChunks = [];
|
|
27
|
+
processor.onaudioprocess = (e) => {
|
|
28
|
+
if (!isRecording) return;
|
|
29
|
+
const inputData = e.inputBuffer.getChannelData(0);
|
|
30
|
+
const pcm = new Int16Array(inputData.length);
|
|
31
|
+
for (let i = 0; i < inputData.length; i++) {
|
|
32
|
+
const s = Math.max(-1, Math.min(1, inputData[i]));
|
|
33
|
+
pcm[i] = s < 0 ? s * 32768 : s * 32767;
|
|
34
|
+
}
|
|
35
|
+
audioChunks.push(pcm);
|
|
36
|
+
};
|
|
37
|
+
source.connect(processor);
|
|
38
|
+
processor.connect(audioContext.destination);
|
|
39
|
+
isRecording = true;
|
|
40
|
+
onRecordingStart?.();
|
|
41
|
+
} catch (err) {
|
|
42
|
+
onError?.(err);
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function stopRecording() {
|
|
47
|
+
if (!isRecording) throw new Error("Not recording");
|
|
48
|
+
isRecording = false;
|
|
49
|
+
onRecordingStop?.();
|
|
50
|
+
if (mediaStream) {
|
|
51
|
+
mediaStream.getTracks().forEach((t) => t.stop());
|
|
52
|
+
mediaStream = null;
|
|
53
|
+
}
|
|
54
|
+
if (processor) {
|
|
55
|
+
processor.disconnect();
|
|
56
|
+
processor = null;
|
|
57
|
+
}
|
|
58
|
+
if (audioContext) {
|
|
59
|
+
await audioContext.close();
|
|
60
|
+
audioContext = null;
|
|
61
|
+
}
|
|
62
|
+
const totalLength = audioChunks.reduce((sum, chunk) => sum + chunk.length, 0);
|
|
63
|
+
const combined = new Int16Array(totalLength);
|
|
64
|
+
let offset = 0;
|
|
65
|
+
for (const chunk of audioChunks) {
|
|
66
|
+
combined.set(chunk, offset);
|
|
67
|
+
offset += chunk.length;
|
|
68
|
+
}
|
|
69
|
+
audioChunks = [];
|
|
70
|
+
const wavBlob = createWavBlob(combined, sampleRate);
|
|
71
|
+
return recognizeBlob(wavBlob);
|
|
72
|
+
}
|
|
73
|
+
async function recordAndRecognize(durationMs) {
|
|
74
|
+
await startRecording();
|
|
75
|
+
await new Promise((resolve) => setTimeout(resolve, durationMs));
|
|
76
|
+
return stopRecording();
|
|
77
|
+
}
|
|
78
|
+
async function recognizeFile(file) {
|
|
79
|
+
return recognizeBlob(file);
|
|
80
|
+
}
|
|
81
|
+
async function recognizeUrl(audioUrl) {
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(url, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: { "Content-Type": "application/json" },
|
|
86
|
+
body: JSON.stringify({
|
|
87
|
+
model: "qwen3-asr-flash",
|
|
88
|
+
messages: [{
|
|
89
|
+
role: "user",
|
|
90
|
+
content: [{ type: "input_audio", input_audio: { url: audioUrl } }]
|
|
91
|
+
}]
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`HTTP ${response.status}`);
|
|
96
|
+
}
|
|
97
|
+
const data = await response.json();
|
|
98
|
+
const text = data.choices?.[0]?.message?.content || "";
|
|
99
|
+
onResult?.(text);
|
|
100
|
+
return text;
|
|
101
|
+
} catch (err) {
|
|
102
|
+
onError?.(err);
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function recognizeBlob(blob) {
|
|
107
|
+
try {
|
|
108
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
109
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
110
|
+
let binary = "";
|
|
111
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
112
|
+
binary += String.fromCharCode(bytes[i]);
|
|
113
|
+
}
|
|
114
|
+
const base64 = btoa(binary);
|
|
115
|
+
const dataUrl = `data:audio/wav;base64,${base64}`;
|
|
116
|
+
const response = await fetch(url, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({
|
|
120
|
+
model: "qwen3-asr-flash",
|
|
121
|
+
messages: [{
|
|
122
|
+
role: "user",
|
|
123
|
+
content: [{ type: "input_audio", input_audio: { data: dataUrl } }]
|
|
124
|
+
}]
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new Error(`HTTP ${response.status}`);
|
|
129
|
+
}
|
|
130
|
+
const data = await response.json();
|
|
131
|
+
const text = data.choices?.[0]?.message?.content || "";
|
|
132
|
+
onResult?.(text);
|
|
133
|
+
return text;
|
|
134
|
+
} catch (err) {
|
|
135
|
+
onError?.(err);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function createWavBlob(samples, rate) {
|
|
140
|
+
const buffer = new ArrayBuffer(44 + samples.length * 2);
|
|
141
|
+
const view = new DataView(buffer);
|
|
142
|
+
const writeString = (offset2, str) => {
|
|
143
|
+
for (let i = 0; i < str.length; i++) {
|
|
144
|
+
view.setUint8(offset2 + i, str.charCodeAt(i));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
writeString(0, "RIFF");
|
|
148
|
+
view.setUint32(4, 36 + samples.length * 2, true);
|
|
149
|
+
writeString(8, "WAVE");
|
|
150
|
+
writeString(12, "fmt ");
|
|
151
|
+
view.setUint32(16, 16, true);
|
|
152
|
+
view.setUint16(20, 1, true);
|
|
153
|
+
view.setUint16(22, 1, true);
|
|
154
|
+
view.setUint32(24, rate, true);
|
|
155
|
+
view.setUint32(28, rate * 2, true);
|
|
156
|
+
view.setUint16(32, 2, true);
|
|
157
|
+
view.setUint16(34, 16, true);
|
|
158
|
+
writeString(36, "data");
|
|
159
|
+
view.setUint32(40, samples.length * 2, true);
|
|
160
|
+
const offset = 44;
|
|
161
|
+
for (let i = 0; i < samples.length; i++) {
|
|
162
|
+
view.setInt16(offset + i * 2, samples[i], true);
|
|
163
|
+
}
|
|
164
|
+
return new Blob([buffer], { type: "audio/wav" });
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
startRecording,
|
|
168
|
+
stopRecording,
|
|
169
|
+
recordAndRecognize,
|
|
170
|
+
recognizeFile,
|
|
171
|
+
recognizeUrl
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
createASRHttpClient
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/asr-http-client.ts"],"sourcesContent":["/**\n * HTTP ASR Client - Press-to-talk style speech recognition\n */\n\nexport interface ASRHttpClientConfig {\n /** API endpoint URL */\n url: string;\n /** Language, default 'zh' */\n language?: string;\n /** Sample rate, default 16000 */\n sampleRate?: number;\n /** Called when recording starts */\n onRecordingStart?: () => void;\n /** Called when recording stops */\n onRecordingStop?: () => void;\n /** Called with recognition result */\n onResult?: (text: string) => void;\n /** Called on error */\n onError?: (error: Error) => void;\n}\n\nexport interface ASRHttpClient {\n /** Start recording (press-to-talk) */\n startRecording(): Promise<void>;\n /** Stop recording and get result */\n stopRecording(): Promise<string>;\n /** Record for specific duration then recognize */\n recordAndRecognize(durationMs: number): Promise<string>;\n /** Recognize audio file (File or Blob) */\n recognizeFile(file: File | Blob): Promise<string>;\n /** Recognize audio from URL */\n recognizeUrl(audioUrl: string): Promise<string>;\n}\n\nexport function createASRHttpClient(config: ASRHttpClientConfig): ASRHttpClient {\n const {\n url,\n language = 'zh',\n sampleRate = 16000,\n onRecordingStart,\n onRecordingStop,\n onResult,\n onError,\n } = config;\n\n let mediaStream: MediaStream | null = null;\n let audioContext: AudioContext | null = null;\n let processor: ScriptProcessorNode | null = null;\n let audioChunks: Int16Array[] = [];\n let isRecording = false;\n\n async function startRecording(): Promise<void> {\n if (isRecording) return;\n\n try {\n mediaStream = await navigator.mediaDevices.getUserMedia({\n audio: { sampleRate, channelCount: 1, echoCancellation: true }\n });\n\n audioContext = new AudioContext({ sampleRate });\n const source = audioContext.createMediaStreamSource(mediaStream);\n processor = audioContext.createScriptProcessor(4096, 1, 1);\n audioChunks = [];\n\n processor.onaudioprocess = (e) => {\n if (!isRecording) return;\n const inputData = e.inputBuffer.getChannelData(0);\n const pcm = new Int16Array(inputData.length);\n for (let i = 0; i < inputData.length; i++) {\n const s = Math.max(-1, Math.min(1, inputData[i]));\n pcm[i] = s < 0 ? s * 32768 : s * 32767;\n }\n audioChunks.push(pcm);\n };\n\n source.connect(processor);\n processor.connect(audioContext.destination);\n isRecording = true;\n onRecordingStart?.();\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n async function stopRecording(): Promise<string> {\n if (!isRecording) throw new Error('Not recording');\n\n isRecording = false;\n onRecordingStop?.();\n\n // Stop media\n if (mediaStream) {\n mediaStream.getTracks().forEach(t => t.stop());\n mediaStream = null;\n }\n if (processor) {\n processor.disconnect();\n processor = null;\n }\n if (audioContext) {\n await audioContext.close();\n audioContext = null;\n }\n\n // Combine audio chunks\n const totalLength = audioChunks.reduce((sum, chunk) => sum + chunk.length, 0);\n const combined = new Int16Array(totalLength);\n let offset = 0;\n for (const chunk of audioChunks) {\n combined.set(chunk, offset);\n offset += chunk.length;\n }\n audioChunks = [];\n\n // Convert to WAV\n const wavBlob = createWavBlob(combined, sampleRate);\n return recognizeBlob(wavBlob);\n }\n\n async function recordAndRecognize(durationMs: number): Promise<string> {\n await startRecording();\n await new Promise(resolve => setTimeout(resolve, durationMs));\n return stopRecording();\n }\n\n async function recognizeFile(file: File | Blob): Promise<string> {\n return recognizeBlob(file);\n }\n\n async function recognizeUrl(audioUrl: string): Promise<string> {\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: 'qwen3-asr-flash',\n messages: [{\n role: 'user',\n content: [{ type: 'input_audio', input_audio: { url: audioUrl } }]\n }]\n })\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n const text = data.choices?.[0]?.message?.content || '';\n onResult?.(text);\n return text;\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n async function recognizeBlob(blob: Blob): Promise<string> {\n try {\n // Convert to base64\n const arrayBuffer = await blob.arrayBuffer();\n const bytes = new Uint8Array(arrayBuffer);\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n const base64 = btoa(binary);\n const dataUrl = `data:audio/wav;base64,${base64}`;\n\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n model: 'qwen3-asr-flash',\n messages: [{\n role: 'user',\n content: [{ type: 'input_audio', input_audio: { data: dataUrl } }]\n }]\n })\n });\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n\n const data = await response.json();\n const text = data.choices?.[0]?.message?.content || '';\n onResult?.(text);\n return text;\n } catch (err) {\n onError?.(err as Error);\n throw err;\n }\n }\n\n function createWavBlob(samples: Int16Array, rate: number): Blob {\n const buffer = new ArrayBuffer(44 + samples.length * 2);\n const view = new DataView(buffer);\n\n // WAV header\n const writeString = (offset: number, str: string) => {\n for (let i = 0; i < str.length; i++) {\n view.setUint8(offset + i, str.charCodeAt(i));\n }\n };\n\n writeString(0, 'RIFF');\n view.setUint32(4, 36 + samples.length * 2, true);\n writeString(8, 'WAVE');\n writeString(12, 'fmt ');\n view.setUint32(16, 16, true);\n view.setUint16(20, 1, true);\n view.setUint16(22, 1, true);\n view.setUint32(24, rate, true);\n view.setUint32(28, rate * 2, true);\n view.setUint16(32, 2, true);\n view.setUint16(34, 16, true);\n writeString(36, 'data');\n view.setUint32(40, samples.length * 2, true);\n\n // Audio data\n const offset = 44;\n for (let i = 0; i < samples.length; i++) {\n view.setInt16(offset + i * 2, samples[i], true);\n }\n\n return new Blob([buffer], { type: 'audio/wav' });\n }\n\n return {\n startRecording,\n stopRecording,\n recordAndRecognize,\n recognizeFile,\n recognizeUrl,\n };\n}\n"],"mappings":";AAkCO,SAAS,oBAAoB,QAA4C;AAC9E,QAAM;AAAA,IACJ;AAAA,IACA,WAAW;AAAA,IACX,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,cAAkC;AACtC,MAAI,eAAoC;AACxC,MAAI,YAAwC;AAC5C,MAAI,cAA4B,CAAC;AACjC,MAAI,cAAc;AAElB,iBAAe,iBAAgC;AAC7C,QAAI,YAAa;AAEjB,QAAI;AACF,oBAAc,MAAM,UAAU,aAAa,aAAa;AAAA,QACtD,OAAO,EAAE,YAAY,cAAc,GAAG,kBAAkB,KAAK;AAAA,MAC/D,CAAC;AAED,qBAAe,IAAI,aAAa,EAAE,WAAW,CAAC;AAC9C,YAAM,SAAS,aAAa,wBAAwB,WAAW;AAC/D,kBAAY,aAAa,sBAAsB,MAAM,GAAG,CAAC;AACzD,oBAAc,CAAC;AAEf,gBAAU,iBAAiB,CAAC,MAAM;AAChC,YAAI,CAAC,YAAa;AAClB,cAAM,YAAY,EAAE,YAAY,eAAe,CAAC;AAChD,cAAM,MAAM,IAAI,WAAW,UAAU,MAAM;AAC3C,iBAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,gBAAM,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC;AAChD,cAAI,CAAC,IAAI,IAAI,IAAI,IAAI,QAAQ,IAAI;AAAA,QACnC;AACA,oBAAY,KAAK,GAAG;AAAA,MACtB;AAEA,aAAO,QAAQ,SAAS;AACxB,gBAAU,QAAQ,aAAa,WAAW;AAC1C,oBAAc;AACd,yBAAmB;AAAA,IACrB,SAAS,KAAK;AACZ,gBAAU,GAAY;AACtB,YAAM;AAAA,IACR;AAAA,EACF;AAEA,iBAAe,gBAAiC;A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S,MAAM;AAGhC,UAAM,cAAc,CAACA,SAAgB,QAAgB;AACnD,eAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,aAAK,SAASA,UAAS,GAAG,IAAI,WAAW,CAAC,CAAC;AAAA,MAC7C;AAAA,IACF;AAEA,gBAAY,GAAG,MAAM;AACrB,SAAK,UAAU,GAAG,KAAK,QAAQ,SAAS,GAAG,IAAI;AAC/C,gBAAY,GAAG,MAAM;AACrB,gBAAY,IAAI,MAAM;AACtB,SAAK,UAAU,IAAI,IAAI,IAAI;AAC3B,SAAK,UAAU,IAAI,GAAG,IAAI;AAC1B,SAAK,UAAU,IAAI,GAAG,IAAI;AAC1B,SAAK,UAAU,IAAI,MAAM,IAAI;AAC7B,SAAK,UAAU,IAAI,OAAO,GAAG,IAAI;AACjC,SAAK,UAAU,IAAI,GAAG,IAAI;AAC1B,SAAK,UAAU,IAAI,IAAI,IAAI;AAC3B,gBAAY,IAAI,MAAM;AACtB,SAAK,UAAU,IAAI,QAAQ,SAAS,GAAG,IAAI;AAG3C,UAAM,SAAS;AACf,aAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,WAAK,SAAS,SAAS,IAAI,GAAG,QAAQ,CAAC,GAAG,IAAI;AAAA,IAChD;AAEA,WAAO,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,MAAM,YAAY,CAAC;AAAA,EACjD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["offset"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amaster.ai/asr-http-client",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"description": "HTTP ASR client with press-to-talk recording",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"asr",
|
|
22
|
+
"speech-to-text",
|
|
23
|
+
"http",
|
|
24
|
+
"press-to-talk",
|
|
25
|
+
"audio",
|
|
26
|
+
"speech-recognition"
|
|
27
|
+
],
|
|
28
|
+
"author": "Amaster Team",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsup": "^8.3.5",
|
|
36
|
+
"typescript": "~5.7.2"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup",
|
|
40
|
+
"dev": "tsup --watch",
|
|
41
|
+
"clean": "rm -rf dist *.tsbuildinfo",
|
|
42
|
+
"type-check": "tsc --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|