@seastart/srtc-plugin-deepfilternet 0.1.0 → 0.1.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/README.md CHANGED
@@ -29,15 +29,7 @@ npm run fetch-assets --prefix node_modules/@seastart/srtc-plugin-deepfilternet
29
29
  cp -r node_modules/@seastart/srtc-plugin-deepfilternet/assets/v2 public/deepfilternet/v2
30
30
  ```
31
31
 
32
- (发布流程见下;npm 上的版本已内置 `assets/v2`,安装后即存在,上面的 `fetch-assets` 仅作兜底。)
33
-
34
- ## 发布
35
-
36
- 在仓库根目录执行(会先构建 web SDK 产出类型、再拉取资源、编译并发布):
37
-
38
- ```bash
39
- npm run publishdeepfilternet
40
- ```
32
+ npm 上的版本已内置 `assets/v2`,安装后即存在;上面的 `fetch-assets` 仅在缺失时作兜底。)
41
33
 
42
34
  ## 使用
43
35
 
@@ -93,3 +85,9 @@ await mic.removeProcessor();
93
85
  - DeepFilterNet 计算量高于 RNNoise,STFT 最小延迟约 20ms;请在目标设备实测 CPU 与延迟。
94
86
  - 切换设备(`changeDeviceId`)或重新 `startCapture` 后,SDK 会自动重建处理器,无需再次 `setProcessor`。
95
87
  - 许可:DeepFilterNet 本体为 Apache-2.0/MIT;模型权重的授权请在分发前自行核实。
88
+
89
+ ### 关于模型 `.tar.gz` 与 `Content-Encoding`
90
+
91
+ 模型文件本身是 gzip。部分服务器/代理会对 `.gz` 再加 `Content-Encoding: gzip`,浏览器据此自动解压一次,导致底层拿到的是未压缩的 `.tar` 而初始化崩溃(`RuntimeError: unreachable`)。
92
+
93
+ 本插件已**自动兜底**:检测到模型被解压后会在浏览器内重新 gzip 还原,无需改服务器配置。该还原依赖 [`CompressionStream`](https://developer.mozilla.org/docs/Web/API/CompressionStream)(Chrome 80+ / Edge 80+ / Safari 16.4+ / Firefox 113+);若环境不支持,会抛出明确错误提示你关闭该响应头。此外,若资源路径错误返回了 HTML(如 SPA fallback),也会抛出清晰的内容无效错误,而非晦涩的 `unreachable`。
@@ -1,5 +1,36 @@
1
1
  import { TrackKind } from "@seastart/srtc-web-sdk";
2
- import { DeepFilterNet3Core } from "deepfilternet3-noise-filter";
2
+ import { AssetLoader, DeepFilterNet3Core } from "deepfilternet3-noise-filter";
3
+ const GZIP_FIX_FLAG = "__srtcGzipFix";
4
+ function patchAssetLoaderGzipFix() {
5
+ const proto = AssetLoader.prototype;
6
+ if (proto[GZIP_FIX_FLAG]) {
7
+ return;
8
+ }
9
+ const original = proto.fetchAsset;
10
+ proto.fetchAsset = async function (url) {
11
+ const buf = await original.call(this, url);
12
+ if (!url.endsWith(".tar.gz")) {
13
+ return buf;
14
+ }
15
+ const head = new Uint8Array(buf);
16
+ if (head[0] === 0x1f && head[1] === 0x8b) {
17
+ return buf;
18
+ }
19
+ const isTar = head.length > 262 &&
20
+ head[257] === 0x75 && head[258] === 0x73 && head[259] === 0x74 &&
21
+ head[260] === 0x61 && head[261] === 0x72;
22
+ if (isTar) {
23
+ if (typeof CompressionStream === "undefined") {
24
+ throw new Error("DeepFilterNet 模型被服务器以 Content-Encoding 解压,且当前环境不支持 CompressionStream 无法自动还原;" +
25
+ "请让服务器对 .tar.gz 不要设置 Content-Encoding: gzip。");
26
+ }
27
+ const stream = new Response(buf).body.pipeThrough(new CompressionStream("gzip"));
28
+ return await new Response(stream).arrayBuffer();
29
+ }
30
+ throw new Error(`DeepFilterNet 模型内容无效(既非 gzip 也非 tar,可能路径错误或命中 SPA fallback):${url}`);
31
+ };
32
+ proto[GZIP_FIX_FLAG] = true;
33
+ }
3
34
  export class DeepFilterNetProcessor {
4
35
  constructor(options = {}) {
5
36
  this.name = "deepfilternet";
@@ -26,6 +57,7 @@ export class DeepFilterNetProcessor {
26
57
  });
27
58
  this.ownContext = true;
28
59
  }
60
+ patchAssetLoaderGzipFix();
29
61
  this.core = new DeepFilterNet3Core({
30
62
  sampleRate: 48000,
31
63
  noiseReductionLevel: this.suppressionLevel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seastart/srtc-plugin-deepfilternet",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "SRTC Web SDK DeepFilterNet 降噪处理器插件",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",