echogarden 1.3.1 → 1.3.2

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.
@@ -1,15 +1,25 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- export declare function int8ToBuffer(ints: Int8Array): Buffer;
2
+ export declare function int8ToBuffer(int8s: Int8Array): Buffer;
3
+ export declare function int8ToBuffer_Slow(int8s: Int8Array): Buffer;
3
4
  export declare function bufferToInt8(buffer: Buffer): Int8Array;
4
- export declare function int16ToBufferLE(ints: Int16Array): Buffer;
5
+ export declare function bufferToInt8_Slow(buffer: Buffer): Int8Array;
6
+ export declare function int16ToBufferLE(int16s: Int16Array): Buffer;
7
+ export declare function int16ToBufferLE_Slow(int16s: Int16Array): Buffer;
5
8
  export declare function bufferLEToInt16(buffer: Buffer): Int16Array;
6
- export declare function int24ToBufferLE(ints: Int32Array): Buffer;
9
+ export declare function bufferLEToInt16_Slow(buffer: Buffer): Int16Array;
10
+ export declare function int24ToBufferLE(int24s: Int32Array): Buffer;
7
11
  export declare function bufferLEToInt24(buffer: Buffer): Int32Array;
8
- export declare function int32ToBufferLE(ints: Int32Array): Buffer;
12
+ export declare function int32ToBufferLE(int32s: Int32Array): Buffer;
13
+ export declare function int32ToBufferLE_Slow(int32s: Int32Array): Buffer;
9
14
  export declare function bufferLEToInt32(buffer: Buffer): Int32Array;
10
- export declare function float32ToBufferLE(floats: Float32Array): Buffer;
15
+ export declare function bufferLEToInt32_Slow(buffer: Buffer): Int32Array;
16
+ export declare function float32ToBufferLE(float32s: Float32Array): Buffer;
17
+ export declare function float32ToBufferLE_Slow(float32s: Float32Array): Buffer;
11
18
  export declare function bufferLEToFloat32(buffer: Buffer): Float32Array;
12
- export declare function float64ToBufferLE(floats: Float64Array): Buffer;
19
+ export declare function bufferLEToFloat32_Slow(buffer: Buffer): Float32Array;
20
+ export declare function float64ToBufferLE(float64s: Float64Array): Buffer;
21
+ export declare function float64ToBufferLE_Slow(float64s: Float64Array): Buffer;
13
22
  export declare function bufferLEToFloat64(buffer: Buffer): Float64Array;
14
- export declare function float64Tofloat32(doubles: Float64Array): Float32Array;
15
- export declare function float32Tofloat64(floats: Float32Array): Float64Array;
23
+ export declare function bufferLEToFloat64_Slow(buffer: Buffer): Float64Array;
24
+ export declare function float64Tofloat32(float64s: Float64Array): Float32Array;
25
+ export declare function float32Tofloat64(float32s: Float32Array): Float64Array;
@@ -1,13 +1,24 @@
1
1
  // Typed arrays to Buffer (little endian) conversions
2
+ //
3
+ // The faster conversion methods (other than the methods for int8) would only work correctly
4
+ // on little-endian architectures, since they assume the byte order of the underlying architecture.
5
+ //
6
+ // Since Echogarden only supports little-endian architectures, this shouldn't matter.
2
7
  // int8 <-> bufferLE
3
- export function int8ToBuffer(ints) {
4
- const buffer = Buffer.alloc(ints.length);
5
- for (let i = 0; i < ints.length; i++) {
6
- buffer[i] = ints[i] + 128;
8
+ export function int8ToBuffer(int8s) {
9
+ return Buffer.copyBytesFrom(int8s);
10
+ }
11
+ export function int8ToBuffer_Slow(int8s) {
12
+ const buffer = Buffer.alloc(int8s.length);
13
+ for (let i = 0; i < int8s.length; i++) {
14
+ buffer[i] = int8s[i] + 128;
7
15
  }
8
16
  return buffer;
9
17
  }
10
18
  export function bufferToInt8(buffer) {
19
+ return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
20
+ }
21
+ export function bufferToInt8_Slow(buffer) {
11
22
  const result = new Int8Array(buffer.length);
12
23
  for (let i = 0; i < result.length; i++) {
13
24
  result[i] = buffer[i] - 128;
@@ -15,14 +26,20 @@ export function bufferToInt8(buffer) {
15
26
  return result;
16
27
  }
17
28
  // int16 <-> bufferLE
18
- export function int16ToBufferLE(ints) {
19
- const buffer = Buffer.alloc(ints.length * 2);
20
- for (let i = 0; i < ints.length; i++) {
21
- buffer.writeInt16LE(ints[i], i * 2);
29
+ export function int16ToBufferLE(int16s) {
30
+ return Buffer.copyBytesFrom(int16s);
31
+ }
32
+ export function int16ToBufferLE_Slow(int16s) {
33
+ const buffer = Buffer.alloc(int16s.length * 2);
34
+ for (let i = 0; i < int16s.length; i++) {
35
+ buffer.writeInt16LE(int16s[i], i * 2);
22
36
  }
23
37
  return buffer;
24
38
  }
25
39
  export function bufferLEToInt16(buffer) {
40
+ return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
41
+ }
42
+ export function bufferLEToInt16_Slow(buffer) {
26
43
  const result = new Int16Array(buffer.length / 2);
27
44
  for (let i = 0; i < result.length; i++) {
28
45
  result[i] = buffer.readInt16LE(i * 2);
@@ -30,10 +47,10 @@ export function bufferLEToInt16(buffer) {
30
47
  return result;
31
48
  }
32
49
  // int24 <-> bufferLE (uses int32 for storage)
33
- export function int24ToBufferLE(ints) {
34
- const buffer = Buffer.alloc(ints.length * 3);
35
- for (let i = 0; i < ints.length; i++) {
36
- const val = ints[i];
50
+ export function int24ToBufferLE(int24s) {
51
+ const buffer = Buffer.alloc(int24s.length * 3);
52
+ for (let i = 0; i < int24s.length; i++) {
53
+ const val = int24s[i];
37
54
  const encodedVal = val < 0 ? val + 0x1000000 : val;
38
55
  buffer[(i * 3) + 0] = (encodedVal >> 0) & 0xff;
39
56
  buffer[(i * 3) + 1] = (encodedVal >> 8) & 0xff;
@@ -53,14 +70,20 @@ export function bufferLEToInt24(buffer) {
53
70
  return result;
54
71
  }
55
72
  // int32 <-> bufferLE
56
- export function int32ToBufferLE(ints) {
57
- const buffer = Buffer.alloc(ints.length * 4);
58
- for (let i = 0; i < ints.length; i++) {
59
- buffer.writeInt32LE(ints[i], i * 4);
73
+ export function int32ToBufferLE(int32s) {
74
+ return Buffer.copyBytesFrom(int32s);
75
+ }
76
+ export function int32ToBufferLE_Slow(int32s) {
77
+ const buffer = Buffer.alloc(int32s.length * 4);
78
+ for (let i = 0; i < int32s.length; i++) {
79
+ buffer.writeInt32LE(int32s[i], i * 4);
60
80
  }
61
81
  return buffer;
62
82
  }
63
83
  export function bufferLEToInt32(buffer) {
84
+ return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
85
+ }
86
+ export function bufferLEToInt32_Slow(buffer) {
64
87
  const result = new Int32Array(buffer.length / 4);
65
88
  for (let i = 0; i < result.length; i++) {
66
89
  result[i] = buffer.readInt32LE(i * 4);
@@ -68,14 +91,20 @@ export function bufferLEToInt32(buffer) {
68
91
  return result;
69
92
  }
70
93
  // float32 <-> bufferLE
71
- export function float32ToBufferLE(floats) {
72
- const buffer = Buffer.alloc(floats.length * 4);
73
- for (let i = 0; i < floats.length; i++) {
74
- buffer.writeFloatLE(floats[i], i * 4);
94
+ export function float32ToBufferLE(float32s) {
95
+ return Buffer.copyBytesFrom(float32s);
96
+ }
97
+ export function float32ToBufferLE_Slow(float32s) {
98
+ const buffer = Buffer.alloc(float32s.length * 4);
99
+ for (let i = 0; i < float32s.length; i++) {
100
+ buffer.writeFloatLE(float32s[i], i * 4);
75
101
  }
76
102
  return buffer;
77
103
  }
78
104
  export function bufferLEToFloat32(buffer) {
105
+ return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
106
+ }
107
+ export function bufferLEToFloat32_Slow(buffer) {
79
108
  const result = new Float32Array(buffer.length / 4);
80
109
  for (let i = 0; i < result.length; i++) {
81
110
  result[i] = buffer.readFloatLE(i * 4);
@@ -83,14 +112,20 @@ export function bufferLEToFloat32(buffer) {
83
112
  return result;
84
113
  }
85
114
  // float64 <-> bufferLE
86
- export function float64ToBufferLE(floats) {
87
- const buffer = Buffer.alloc(floats.length * 8);
88
- for (let i = 0; i < floats.length; i++) {
89
- buffer.writeDoubleLE(floats[i], i * 8);
115
+ export function float64ToBufferLE(float64s) {
116
+ return Buffer.copyBytesFrom(float64s);
117
+ }
118
+ export function float64ToBufferLE_Slow(float64s) {
119
+ const buffer = Buffer.alloc(float64s.length * 8);
120
+ for (let i = 0; i < float64s.length; i++) {
121
+ buffer.writeDoubleLE(float64s[i], i * 8);
90
122
  }
91
123
  return buffer;
92
124
  }
93
125
  export function bufferLEToFloat64(buffer) {
126
+ return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
127
+ }
128
+ export function bufferLEToFloat64_Slow(buffer) {
94
129
  const result = new Float64Array(buffer.length / 8);
95
130
  for (let i = 0; i < result.length; i++) {
96
131
  result[i] = buffer.readDoubleLE(i * 8);
@@ -98,18 +133,10 @@ export function bufferLEToFloat64(buffer) {
98
133
  return result;
99
134
  }
100
135
  // float64 <-> float32
101
- export function float64Tofloat32(doubles) {
102
- const floats = new Float32Array(doubles.length);
103
- for (let i = 0; i < doubles.length; i++) {
104
- floats[i] = doubles[i];
105
- }
106
- return floats;
136
+ export function float64Tofloat32(float64s) {
137
+ return Float32Array.from(float64s);
107
138
  }
108
- export function float32Tofloat64(floats) {
109
- const doubles = new Float64Array(floats.length);
110
- for (let i = 0; i < floats.length; i++) {
111
- doubles[i] = floats[i];
112
- }
113
- return doubles;
139
+ export function float32Tofloat64(float32s) {
140
+ return Float64Array.from(float32s);
114
141
  }
115
142
  //# sourceMappingURL=BinaryArrayConversion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BinaryArrayConversion.js","sourceRoot":"","sources":["../../src/utilities/BinaryArrayConversion.ts"],"names":[],"mappings":"AAAA,qDAAqD;AAErD,oBAAoB;AACpB,MAAM,UAAU,YAAY,CAAC,IAAe;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;IAC1B,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,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,CAAC;AAED,sBAAsB;AACtB,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echogarden",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "An easy-to-use speech toolset. Includes tools for synthesis, recognition, alignment, speech translation, language detection, source separation and more.",
5
5
  "author": "Rotem Dan",
6
6
  "license": "GPL-3.0",
@@ -1,17 +1,30 @@
1
1
  // Typed arrays to Buffer (little endian) conversions
2
+ //
3
+ // The faster conversion methods (other than the methods for int8) would only work correctly
4
+ // on little-endian architectures, since they assume the byte order of the underlying architecture.
5
+ //
6
+ // Since Echogarden only supports little-endian architectures, this shouldn't matter.
2
7
 
3
8
  // int8 <-> bufferLE
4
- export function int8ToBuffer(ints: Int8Array) {
5
- const buffer = Buffer.alloc(ints.length)
9
+ export function int8ToBuffer(int8s: Int8Array) {
10
+ return Buffer.copyBytesFrom(int8s)
11
+ }
12
+
13
+ export function int8ToBuffer_Slow(int8s: Int8Array) {
14
+ const buffer = Buffer.alloc(int8s.length)
6
15
 
7
- for (let i = 0; i < ints.length; i++) {
8
- buffer[i] = ints[i] + 128
16
+ for (let i = 0; i < int8s.length; i++) {
17
+ buffer[i] = int8s[i] + 128
9
18
  }
10
19
 
11
20
  return buffer
12
21
  }
13
22
 
14
23
  export function bufferToInt8(buffer: Buffer) {
24
+ return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
25
+ }
26
+
27
+ export function bufferToInt8_Slow(buffer: Buffer) {
15
28
  const result = new Int8Array(buffer.length)
16
29
 
17
30
  for (let i = 0; i < result.length; i++) {
@@ -22,17 +35,25 @@ export function bufferToInt8(buffer: Buffer) {
22
35
  }
23
36
 
24
37
  // int16 <-> bufferLE
25
- export function int16ToBufferLE(ints: Int16Array) {
26
- const buffer = Buffer.alloc(ints.length * 2)
38
+ export function int16ToBufferLE(int16s: Int16Array) {
39
+ return Buffer.copyBytesFrom(int16s)
40
+ }
41
+
42
+ export function int16ToBufferLE_Slow(int16s: Int16Array) {
43
+ const buffer = Buffer.alloc(int16s.length * 2)
27
44
 
28
- for (let i = 0; i < ints.length; i++) {
29
- buffer.writeInt16LE(ints[i], i * 2)
45
+ for (let i = 0; i < int16s.length; i++) {
46
+ buffer.writeInt16LE(int16s[i], i * 2)
30
47
  }
31
48
 
32
49
  return buffer
33
50
  }
34
51
 
35
52
  export function bufferLEToInt16(buffer: Buffer) {
53
+ return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2)
54
+ }
55
+
56
+ export function bufferLEToInt16_Slow(buffer: Buffer) {
36
57
  const result = new Int16Array(buffer.length / 2)
37
58
 
38
59
  for (let i = 0; i < result.length; i++) {
@@ -43,11 +64,11 @@ export function bufferLEToInt16(buffer: Buffer) {
43
64
  }
44
65
 
45
66
  // int24 <-> bufferLE (uses int32 for storage)
46
- export function int24ToBufferLE(ints: Int32Array) {
47
- const buffer = Buffer.alloc(ints.length * 3)
67
+ export function int24ToBufferLE(int24s: Int32Array) {
68
+ const buffer = Buffer.alloc(int24s.length * 3)
48
69
 
49
- for (let i = 0; i < ints.length; i++) {
50
- const val = ints[i]
70
+ for (let i = 0; i < int24s.length; i++) {
71
+ const val = int24s[i]
51
72
  const encodedVal = val < 0 ? val + 0x1000000 : val
52
73
 
53
74
  buffer[(i * 3) + 0] = (encodedVal >> 0) & 0xff
@@ -74,17 +95,25 @@ export function bufferLEToInt24(buffer: Buffer) {
74
95
  }
75
96
 
76
97
  // int32 <-> bufferLE
77
- export function int32ToBufferLE(ints: Int32Array) {
78
- const buffer = Buffer.alloc(ints.length * 4)
98
+ export function int32ToBufferLE(int32s: Int32Array) {
99
+ return Buffer.copyBytesFrom(int32s)
100
+ }
79
101
 
80
- for (let i = 0; i < ints.length; i++) {
81
- buffer.writeInt32LE(ints[i], i * 4)
102
+ export function int32ToBufferLE_Slow(int32s: Int32Array) {
103
+ const buffer = Buffer.alloc(int32s.length * 4)
104
+
105
+ for (let i = 0; i < int32s.length; i++) {
106
+ buffer.writeInt32LE(int32s[i], i * 4)
82
107
  }
83
108
 
84
109
  return buffer
85
110
  }
86
111
 
87
112
  export function bufferLEToInt32(buffer: Buffer) {
113
+ return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
114
+ }
115
+
116
+ export function bufferLEToInt32_Slow(buffer: Buffer) {
88
117
  const result = new Int32Array(buffer.length / 4)
89
118
 
90
119
  for (let i = 0; i < result.length; i++) {
@@ -95,17 +124,25 @@ export function bufferLEToInt32(buffer: Buffer) {
95
124
  }
96
125
 
97
126
  // float32 <-> bufferLE
98
- export function float32ToBufferLE(floats: Float32Array) {
99
- const buffer = Buffer.alloc(floats.length * 4)
127
+ export function float32ToBufferLE(float32s: Float32Array) {
128
+ return Buffer.copyBytesFrom(float32s)
129
+ }
130
+
131
+ export function float32ToBufferLE_Slow(float32s: Float32Array) {
132
+ const buffer = Buffer.alloc(float32s.length * 4)
100
133
 
101
- for (let i = 0; i < floats.length; i++) {
102
- buffer.writeFloatLE(floats[i], i * 4)
134
+ for (let i = 0; i < float32s.length; i++) {
135
+ buffer.writeFloatLE(float32s[i], i * 4)
103
136
  }
104
137
 
105
138
  return buffer
106
139
  }
107
140
 
108
141
  export function bufferLEToFloat32(buffer: Buffer) {
142
+ return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
143
+ }
144
+
145
+ export function bufferLEToFloat32_Slow(buffer: Buffer) {
109
146
  const result = new Float32Array(buffer.length / 4)
110
147
 
111
148
  for (let i = 0; i < result.length; i++) {
@@ -116,17 +153,25 @@ export function bufferLEToFloat32(buffer: Buffer) {
116
153
  }
117
154
 
118
155
  // float64 <-> bufferLE
119
- export function float64ToBufferLE(floats: Float64Array) {
120
- const buffer = Buffer.alloc(floats.length * 8)
156
+ export function float64ToBufferLE(float64s: Float64Array) {
157
+ return Buffer.copyBytesFrom(float64s)
158
+ }
159
+
160
+ export function float64ToBufferLE_Slow(float64s: Float64Array) {
161
+ const buffer = Buffer.alloc(float64s.length * 8)
121
162
 
122
- for (let i = 0; i < floats.length; i++) {
123
- buffer.writeDoubleLE(floats[i], i * 8)
163
+ for (let i = 0; i < float64s.length; i++) {
164
+ buffer.writeDoubleLE(float64s[i], i * 8)
124
165
  }
125
166
 
126
167
  return buffer
127
168
  }
128
169
 
129
170
  export function bufferLEToFloat64(buffer: Buffer) {
171
+ return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8)
172
+ }
173
+
174
+ export function bufferLEToFloat64_Slow(buffer: Buffer) {
130
175
  const result = new Float64Array(buffer.length / 8)
131
176
 
132
177
  for (let i = 0; i < result.length; i++) {
@@ -137,23 +182,10 @@ export function bufferLEToFloat64(buffer: Buffer) {
137
182
  }
138
183
 
139
184
  // float64 <-> float32
140
- export function float64Tofloat32(doubles: Float64Array) {
141
- const floats = new Float32Array(doubles.length)
142
-
143
- for (let i = 0; i < doubles.length; i++) {
144
- floats[i] = doubles[i]
145
- }
146
-
147
- return floats
185
+ export function float64Tofloat32(float64s: Float64Array) {
186
+ return Float32Array.from(float64s)
148
187
  }
149
188
 
150
- export function float32Tofloat64(floats: Float32Array) {
151
- const doubles = new Float64Array(floats.length)
152
-
153
- for (let i = 0; i < floats.length; i++) {
154
- doubles[i] = floats[i]
155
- }
156
-
157
- return doubles
189
+ export function float32Tofloat64(float32s: Float32Array) {
190
+ return Float64Array.from(float32s)
158
191
  }
159
-