@zwa73/utils 1.0.190 → 1.0.191
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/UtilClass.d.ts +5 -1
- package/dist/UtilClass.js +9 -0
- package/dist/UtilFfmpegTools.js +12 -8
- package/package.json +1 -1
- package/src/UtilClass.ts +10 -1
- package/src/UtilFfmpegTools.ts +12 -8
package/dist/UtilClass.d.ts
CHANGED
|
@@ -26,7 +26,11 @@ export declare class Stream<T> implements Iterable<T> {
|
|
|
26
26
|
private _list;
|
|
27
27
|
/**加工函数列表*/
|
|
28
28
|
private _operation;
|
|
29
|
-
constructor(
|
|
29
|
+
private constructor();
|
|
30
|
+
/**从arraylike创建流 */
|
|
31
|
+
static from<T>(...args: Parameters<typeof Array.from<T>>): Stream<T>;
|
|
32
|
+
/**设置并发数 */
|
|
33
|
+
concurrent(count: number): Stream<T>;
|
|
30
34
|
/**平分数组
|
|
31
35
|
* @param count - 份数
|
|
32
36
|
* @param mode - 模式 average:轮询平均分 chunk:切块均分
|
package/dist/UtilClass.js
CHANGED
|
@@ -49,6 +49,15 @@ class Stream {
|
|
|
49
49
|
this._list = new Array(...base);
|
|
50
50
|
this._concurrent = concurrent;
|
|
51
51
|
}
|
|
52
|
+
/**从arraylike创建流 */
|
|
53
|
+
static from(...args) {
|
|
54
|
+
return new Stream(Array.from(...args));
|
|
55
|
+
}
|
|
56
|
+
/**设置并发数 */
|
|
57
|
+
concurrent(count) {
|
|
58
|
+
this._concurrent = count;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
52
61
|
/**平分数组
|
|
53
62
|
* @param count - 份数
|
|
54
63
|
* @param mode - 模式 average:轮询平均分 chunk:切块均分
|
package/dist/UtilFfmpegTools.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
|
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.
|
|
236
|
-
await
|
|
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
|
|
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
package/src/UtilClass.ts
CHANGED
|
@@ -46,12 +46,21 @@ 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>>){
|
|
57
|
+
return new Stream<T>(Array.from(...args));
|
|
58
|
+
}
|
|
59
|
+
/**设置并发数 */
|
|
60
|
+
concurrent(count: number): Stream<T> {
|
|
61
|
+
this._concurrent = count;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
55
64
|
/**平分数组
|
|
56
65
|
* @param count - 份数
|
|
57
66
|
* @param mode - 模式 average:轮询平均分 chunk:切块均分
|
package/src/UtilFfmpegTools.ts
CHANGED
|
@@ -155,16 +155,16 @@ class SFfmpegTool {
|
|
|
155
155
|
inputWavPath: string,
|
|
156
156
|
outputWavPath: string,
|
|
157
157
|
threshold: number = -50,
|
|
158
|
-
silence: number = 0.
|
|
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
|
|
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
|
|
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.
|
|
254
|
+
silence: number = 0.1,
|
|
253
255
|
cpCount: number = 16
|
|
254
256
|
) {
|
|
255
|
-
await
|
|
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
|
|
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);
|