@qvac/decoder-audio 0.2.9 → 0.3.0

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,103 +0,0 @@
1
- const GSTDecoder = require('@qvac/decoder-audio')
2
- const fs = require('bare-fs')
3
-
4
- async function testDecodeMp3() {
5
- const decoder = new GSTDecoder({
6
- config: {
7
- audioFormat: 'f32le',
8
- sampleRate: 16000
9
- }
10
- })
11
-
12
- try {
13
- await decoder.load()
14
-
15
- const audioPath = getAssetPath('sample.mp3')
16
- const audioStream = fs.createReadStream(audioPath)
17
- const response = await decoder.run(audioStream)
18
-
19
- let totalBytes = 0
20
- let updateCount = 0
21
-
22
- await response
23
- .onUpdate(output => {
24
- if (output && output.outputArray) {
25
- const bytes = new Uint8Array(output.outputArray)
26
- totalBytes += bytes.length
27
- updateCount++
28
- }
29
- })
30
- .await()
31
-
32
- if (totalBytes === 0) {
33
- throw new Error('No audio data decoded')
34
- }
35
-
36
- if (updateCount === 0) {
37
- throw new Error('No decoder updates received')
38
- }
39
-
40
- console.log(`MP3 decode complete: ${totalBytes} bytes, ${updateCount} updates`)
41
-
42
- return {
43
- success: true,
44
- totalBytes,
45
- updateCount
46
- }
47
- } catch (error) {
48
- console.error('Error during testDecodeMp3:', error)
49
- throw error
50
- }
51
- }
52
-
53
- async function testDecodeWav() {
54
- const decoder = new GSTDecoder({
55
- config: {
56
- audioFormat: 'f32le',
57
- sampleRate: 16000
58
- }
59
- })
60
-
61
- try {
62
- await decoder.load()
63
-
64
- const audioPath = getAssetPath('sample.wav')
65
- const audioStream = fs.createReadStream(audioPath)
66
- const response = await decoder.run(audioStream)
67
-
68
- let totalBytes = 0
69
- let updateCount = 0
70
-
71
- await response
72
- .onUpdate(output => {
73
- if (output && output.outputArray) {
74
- const bytes = new Uint8Array(output.outputArray)
75
- totalBytes += bytes.length
76
- updateCount++
77
- }
78
- })
79
- .await()
80
-
81
- if (totalBytes === 0) {
82
- throw new Error('No audio data decoded')
83
- }
84
-
85
- if (updateCount === 0) {
86
- throw new Error('No decoder updates received')
87
- }
88
-
89
- console.log(`WAV decode complete: ${totalBytes} bytes, ${updateCount} updates`)
90
-
91
- return {
92
- success: true,
93
- totalBytes,
94
- updateCount
95
- }
96
- } catch (error) {
97
- console.error('Error during testDecodeWav:', error)
98
- throw error
99
- }
100
- }
101
-
102
- module.exports = { testDecodeMp3, testDecodeWav }
103
-