@zwa73/utils 1.0.190 → 1.0.192

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.
@@ -26,7 +26,13 @@ export declare class Stream<T> implements Iterable<T> {
26
26
  private _list;
27
27
  /**加工函数列表*/
28
28
  private _operation;
29
- constructor(base?: Array<T> | number, concurrent?: number);
29
+ private constructor();
30
+ /**从arraylike创建流 */
31
+ static from<T>(args: Parameters<typeof Array.from<T>>[0], concurrent?: number): Stream<T>;
32
+ /**从数组创建流 */
33
+ static of<T>(...args: T[]): Stream<T>;
34
+ /**设置并发数 */
35
+ concurrent(count: number): Stream<T>;
30
36
  /**平分数组
31
37
  * @param count - 份数
32
38
  * @param mode - 模式 average:轮询平均分 chunk:切块均分
package/dist/UtilClass.js CHANGED
@@ -49,6 +49,19 @@ class Stream {
49
49
  this._list = new Array(...base);
50
50
  this._concurrent = concurrent;
51
51
  }
52
+ /**从arraylike创建流 */
53
+ static from(args, concurrent = 1) {
54
+ return new Stream(Array.from(args), concurrent);
55
+ }
56
+ /**从数组创建流 */
57
+ static of(...args) {
58
+ return new Stream(args);
59
+ }
60
+ /**设置并发数 */
61
+ concurrent(count) {
62
+ this._concurrent = count;
63
+ return this;
64
+ }
52
65
  /**平分数组
53
66
  * @param count - 份数
54
67
  * @param mode - 模式 average:轮询平均分 chunk:切块均分
@@ -150,12 +150,12 @@ class SFfmpegTool {
150
150
  * @param threshold - 静音阈值/dB
151
151
  * @param silence - 保留静音时长
152
152
  */
153
- static async trimSilence(inputWavPath, outputWavPath, threshold = -50, silence = 0.2) {
153
+ static async trimSilence(inputWavPath, outputWavPath, threshold = -50, silence = 0.1) {
154
154
  return new Promise((resolve, reject) => {
155
155
  const ins = (0, fluent_ffmpeg_1.default)(inputWavPath)
156
- .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
156
+ .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}:detection=peak`)
157
157
  .audioFilters("areverse")
158
- .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`)
158
+ .audioFilters(`silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}:detection=peak`)
159
159
  .audioFilters("areverse")
160
160
  .save(outputWavPath)
161
161
  .on("end", () => {
@@ -207,7 +207,8 @@ class SFfmpegTool {
207
207
  * @param cpCount - 并发数
208
208
  */
209
209
  static async wav2oggMP(ioMap, quality = 10, cpCount = 16) {
210
- await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
210
+ await UtilClass_1.Stream.from(Object.entries(ioMap))
211
+ .concurrent(cpCount)
211
212
  .map(async ([inPath, outPath]) => {
212
213
  UtilLogger_1.SLogger.info(`SFfmpegTool.wav2oggMP 正在处理:${outPath}`);
213
214
  await SFfmpegTool.wav2ogg(inPath, outPath, quality);
@@ -220,7 +221,8 @@ class SFfmpegTool {
220
221
  * @param cpCount - 并发数
221
222
  */
222
223
  static async flac2oggMP(ioMap, quality = 10, cpCount = 16) {
223
- await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
224
+ await UtilClass_1.Stream.from(Object.entries(ioMap))
225
+ .concurrent(cpCount)
224
226
  .map(async ([inPath, outPath]) => {
225
227
  UtilLogger_1.SLogger.info(`SFfmpegTool.flac2oggMP 正在处理:${outPath}`);
226
228
  await SFfmpegTool.flac2ogg(inPath, outPath, quality);
@@ -232,8 +234,9 @@ class SFfmpegTool {
232
234
  * @param threshold - 静音阈值/dB
233
235
  * @param silence - 保留静音时长
234
236
  */
235
- static async trimSilenceMP(ioMap, threshold = -50, silence = 0.2, cpCount = 16) {
236
- await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
237
+ static async trimSilenceMP(ioMap, threshold = -50, silence = 0.1, cpCount = 16) {
238
+ await UtilClass_1.Stream.from(Object.entries(ioMap))
239
+ .concurrent(cpCount)
237
240
  .map(async ([inPath, outPath]) => {
238
241
  UtilLogger_1.SLogger.info(`SFfmpegTool.trimSilenceMP 正在处理:${outPath}`);
239
242
  await SFfmpegTool.trimSilence(inPath, outPath, threshold, silence);
@@ -246,7 +249,8 @@ class SFfmpegTool {
246
249
  * @param cpCount - 并发数
247
250
  */
248
251
  static async resampleMP(ioMap, rate = 22050, cpCount = 16) {
249
- await new UtilClass_1.Stream(Object.entries(ioMap), cpCount)
252
+ await UtilClass_1.Stream.from(Object.entries(ioMap))
253
+ .concurrent(cpCount)
250
254
  .map(async ([inPath, outPath]) => {
251
255
  UtilLogger_1.SLogger.info(`SFfmpegTool.resampleMP 正在处理:${outPath}`);
252
256
  await SFfmpegTool.resample(inPath, outPath, rate);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/utils",
3
- "version": "1.0.190",
3
+ "version": "1.0.192",
4
4
  "description": "my utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/UtilClass.ts CHANGED
@@ -46,12 +46,25 @@ export class Stream<T> implements Iterable<T>{
46
46
  private _list: T[];
47
47
  /**加工函数列表*/
48
48
  private _operation: Array<StreamOperation<T, T>> = [];
49
- constructor(base?: Array<T>|number, concurrent: number = 1) {
49
+ private constructor(base?: Array<T>|number, concurrent: number = 1) {
50
50
  if(base==undefined) this._list = new Array();
51
51
  else if(typeof base === 'number') this._list = new Array(base);
52
52
  else this._list = new Array(...base);
53
53
  this._concurrent = concurrent;
54
54
  }
55
+ /**从arraylike创建流 */
56
+ static from<T>(args:Parameters<typeof Array.from<T>>[0],concurrent:number=1){
57
+ return new Stream<T>(Array.from(args),concurrent);
58
+ }
59
+ /**从数组创建流 */
60
+ static of<T>(...args:T[]){
61
+ return new Stream<T>(args);
62
+ }
63
+ /**设置并发数 */
64
+ concurrent(count: number): Stream<T> {
65
+ this._concurrent = count;
66
+ return this;
67
+ }
55
68
  /**平分数组
56
69
  * @param count - 份数
57
70
  * @param mode - 模式 average:轮询平均分 chunk:切块均分
@@ -155,16 +155,16 @@ class SFfmpegTool {
155
155
  inputWavPath: string,
156
156
  outputWavPath: string,
157
157
  threshold: number = -50,
158
- silence: number = 0.2
158
+ silence: number = 0.1
159
159
  ): Promise<boolean> {
160
160
  return new Promise((resolve, reject) => {
161
161
  const ins = fluentFfmpeg(inputWavPath)
162
162
  .audioFilters(
163
- `silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`
163
+ `silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}:detection=peak`
164
164
  )
165
165
  .audioFilters("areverse")
166
166
  .audioFilters(
167
- `silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}`
167
+ `silenceremove=start_periods=1:start_threshold=${threshold}dB:start_silence=${silence}:detection=peak`
168
168
  )
169
169
  .audioFilters("areverse")
170
170
  .save(outputWavPath)
@@ -217,7 +217,8 @@ class SFfmpegTool {
217
217
  * @param cpCount - 并发数
218
218
  */
219
219
  static async wav2oggMP(ioMap: IOMap, quality = 10, cpCount = 16) {
220
- await new Stream(Object.entries(ioMap),cpCount)
220
+ await Stream.from(Object.entries(ioMap))
221
+ .concurrent(cpCount)
221
222
  .map(async ([inPath, outPath]) => {
222
223
  SLogger.info(`SFfmpegTool.wav2oggMP 正在处理:${outPath}`);
223
224
  await SFfmpegTool.wav2ogg(inPath, outPath, quality);
@@ -234,7 +235,8 @@ class SFfmpegTool {
234
235
  quality: number = 10,
235
236
  cpCount: number = 16
236
237
  ) {
237
- await new Stream(Object.entries(ioMap),cpCount)
238
+ await Stream.from(Object.entries(ioMap))
239
+ .concurrent(cpCount)
238
240
  .map(async ([inPath, outPath]) => {
239
241
  SLogger.info(`SFfmpegTool.flac2oggMP 正在处理:${outPath}`);
240
242
  await SFfmpegTool.flac2ogg(inPath, outPath, quality);
@@ -249,10 +251,11 @@ class SFfmpegTool {
249
251
  static async trimSilenceMP(
250
252
  ioMap: IOMap,
251
253
  threshold: number = -50,
252
- silence: number = 0.2,
254
+ silence: number = 0.1,
253
255
  cpCount: number = 16
254
256
  ) {
255
- await new Stream(Object.entries(ioMap),cpCount)
257
+ await Stream.from(Object.entries(ioMap))
258
+ .concurrent(cpCount)
256
259
  .map(async ([inPath, outPath]) => {
257
260
  SLogger.info(`SFfmpegTool.trimSilenceMP 正在处理:${outPath}`);
258
261
  await SFfmpegTool.trimSilence(inPath, outPath, threshold, silence);
@@ -266,7 +269,8 @@ class SFfmpegTool {
266
269
  * @param cpCount - 并发数
267
270
  */
268
271
  static async resampleMP(ioMap: IOMap, rate: number = 22050, cpCount: number = 16) {
269
- await new Stream(Object.entries(ioMap),cpCount)
272
+ await Stream.from(Object.entries(ioMap))
273
+ .concurrent(cpCount)
270
274
  .map(async ([inPath, outPath]) => {
271
275
  SLogger.info(`SFfmpegTool.resampleMP 正在处理:${outPath}`);
272
276
  await SFfmpegTool.resample(inPath, outPath, rate);