whispermix 1.4.2 → 1.4.4

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.
Files changed (2) hide show
  1. package/index.js +25 -16
  2. package/package.json +1 -3
package/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import axios from 'axios';
2
- import FormData from 'form-data';
3
1
  import fs from 'fs';
4
2
  import Bottleneck from 'bottleneck';
5
3
  import path from 'path';
@@ -136,29 +134,40 @@ class WhisperMix {
136
134
  if (this.isLocal) {
137
135
  throw new Error('fromStream is not supported for local Whisper model. Use fromFile instead.');
138
136
  }
139
-
140
- return this.limiter.schedule(() => new Promise((resolve, reject) => {
141
- const formData = new FormData();
142
- formData.append('file', audioStream);
143
- formData.append('model', this.modelName);
144
137
 
145
- this._makeRequest(formData)
146
- .then(resolve)
147
- .catch(reject);
148
- }));
138
+ const chunks = [];
139
+ for await (const chunk of audioStream) {
140
+ chunks.push(chunk);
141
+ }
142
+ const buffer = Buffer.concat(chunks);
143
+
144
+ return this.limiter.schedule(() => this._makeRequest(buffer));
149
145
  }
150
146
 
151
- async _makeRequest(formData) {
147
+ async _makeRequest(buffer) {
152
148
  try {
153
- const response = await axios.post(this.apiUrl, formData, {
149
+ const blob = new Blob([buffer], { type: 'audio/mpeg' });
150
+ const formData = new FormData();
151
+ formData.append('file', blob, 'audio.mp3');
152
+ formData.append('model', this.modelName);
153
+
154
+ const response = await fetch(this.apiUrl, {
155
+ method: 'POST',
154
156
  headers: {
155
- ...formData.getHeaders(),
156
157
  'Authorization': `Bearer ${this.apiKey}`,
157
158
  },
159
+ body: formData,
158
160
  });
159
- return response.data.text.trim();
161
+
162
+ const responseData = await response.json();
163
+
164
+ if (!response.ok) {
165
+ throw responseData;
166
+ }
167
+
168
+ return responseData.text.trim();
160
169
  } catch (error) {
161
- throw error.response ? error.response.data : error.message;
170
+ throw error?.message || error;
162
171
  }
163
172
  }
164
173
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "whispermix",
3
3
  "description": "🎙️ WhisperMix is a versatile module for transcribing audio using OpenAI’s Whisper or Groq’s Whisper v3 model.",
4
- "version": "1.4.2",
4
+ "version": "1.4.4",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "whisper",
@@ -46,10 +46,8 @@
46
46
  "dependencies": {
47
47
  "@xenova/transformers": "^2.17.2",
48
48
  "audio-decode": "^2.1.3",
49
- "axios": "^1.13.5",
50
49
  "bottleneck": "^2.19.5",
51
50
  "fluent-ffmpeg": "^2.1.3",
52
- "form-data": "^4.0.4",
53
51
  "get-audio-duration": "^4.0.1"
54
52
  }
55
53
  }