pendra 0.17.2 → 0.17.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/dist/index.js CHANGED
@@ -1083,17 +1083,27 @@ var MIME_EXT = {
1083
1083
  "audio/x-flac": "flac"
1084
1084
  };
1085
1085
  function extFromMime(type) {
1086
- if (!type) return "mp3";
1086
+ if (!type) return void 0;
1087
1087
  const base = type.split(";")[0].trim().toLowerCase();
1088
- return MIME_EXT[base] ?? "mp3";
1089
- }
1090
- function asBlob(file) {
1088
+ return MIME_EXT[base];
1089
+ }
1090
+ async function extFromHeader(blob) {
1091
+ const head = new Uint8Array(await blob.slice(0, 12).arrayBuffer());
1092
+ const ascii = (from, to) => String.fromCharCode(...head.subarray(from, to));
1093
+ if (head.length >= 12 && ascii(0, 4) === "RIFF" && ascii(8, 12) === "WAVE") return "wav";
1094
+ if (head.length >= 4 && ascii(0, 4) === "fLaC") return "flac";
1095
+ if (head.length >= 3 && ascii(0, 3) === "ID3") return "mp3";
1096
+ if (head.length >= 2 && head[0] === 255 && (head[1] & 224) === 224) return "mp3";
1097
+ return void 0;
1098
+ }
1099
+ async function asBlob(file) {
1091
1100
  if (file instanceof Blob) {
1092
1101
  const asFile = file;
1093
1102
  if (asFile.name) {
1094
1103
  return { blob: file, filename: asFile.name };
1095
1104
  }
1096
- return { blob: file, filename: `audio.${extFromMime(file.type)}` };
1105
+ const ext = extFromMime(file.type) ?? await extFromHeader(file);
1106
+ return { blob: file, filename: ext ? `audio.${ext}` : "audio" };
1097
1107
  }
1098
1108
  const { filename, content } = file;
1099
1109
  if (content instanceof Blob) {
@@ -1112,7 +1122,7 @@ var Transcriptions = class {
1112
1122
  if (params.beam_size != null && !(Number.isInteger(params.beam_size) && params.beam_size >= 1 && params.beam_size <= 8)) {
1113
1123
  throw new Error(`beam_size must be an integer between 1 and 8 (got ${params.beam_size})`);
1114
1124
  }
1115
- const { blob, filename } = asBlob(params.file);
1125
+ const { blob, filename } = await asBlob(params.file);
1116
1126
  if (blob.size === 0) {
1117
1127
  throw new Error("audio file is empty");
1118
1128
  }
@@ -1826,7 +1836,7 @@ var Rerank = class {
1826
1836
  };
1827
1837
 
1828
1838
  // src/version.ts
1829
- var VERSION = "0.17.2";
1839
+ var VERSION = "0.17.3";
1830
1840
  var USER_AGENT = `pendra-node/${VERSION}`;
1831
1841
 
1832
1842
  // src/client.ts