@qvac/decoder-audio 0.1.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.
- package/LICENSE +202 -0
- package/README.md +257 -0
- package/binding.js +3 -0
- package/gstreamer.js +131 -0
- package/index.d.ts +57 -0
- package/index.js +103 -0
- package/package.json +53 -0
- package/prebuilds/android-arm/qvac__decoder-audio.bare +0 -0
- package/prebuilds/android-arm64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/android-ia32/qvac__decoder-audio.bare +0 -0
- package/prebuilds/android-x64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/darwin-arm64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/darwin-arm64/qvac__decoder-audio.bare.exports +7163 -0
- package/prebuilds/darwin-x64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/darwin-x64/qvac__decoder-audio.bare.exports +7130 -0
- package/prebuilds/ios-arm64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/ios-arm64/qvac__decoder-audio.bare.exports +7163 -0
- package/prebuilds/ios-arm64-simulator/qvac__decoder-audio.bare +0 -0
- package/prebuilds/ios-arm64-simulator/qvac__decoder-audio.bare.exports +7163 -0
- package/prebuilds/ios-x64-simulator/qvac__decoder-audio.bare +0 -0
- package/prebuilds/ios-x64-simulator/qvac__decoder-audio.bare.exports +7141 -0
- package/prebuilds/linux-x64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/win32-x64/qvac__decoder-audio.bare +0 -0
- package/prebuilds/win32-x64/qvac__decoder-audio.bare.exports +0 -0
- package/utils/createStreamAccumulator.js +64 -0
- package/utils/error.js +61 -0
package/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const QvacResponse = require('@qvac/response')
|
|
4
|
+
const BaseInference = require('@qvac/infer-base/WeightsProvider/BaseInference')
|
|
5
|
+
const { GSTDecoderInterface } = require('./gstreamer')
|
|
6
|
+
const createStreamAccumulator = require('./utils/createStreamAccumulator')
|
|
7
|
+
|
|
8
|
+
const END_OF_INPUT = 'end of job'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* GSTDecoder client implementation for the Whisper transcription model
|
|
12
|
+
*/
|
|
13
|
+
class GSTDecoder extends BaseInference {
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of GSTDecoder.
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {Object} config - environment-specific inference setup configuration
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
constructor ({ config, ...args }) {
|
|
21
|
+
super(args)
|
|
22
|
+
this.config = config
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async load () {
|
|
26
|
+
const config = {
|
|
27
|
+
audioFormat: this.config.audioFormat || 'encoded',
|
|
28
|
+
sampleRate: this.config.sampleRate || 16000
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
this.logger.info('Loading GSTDecoder with config:', config)
|
|
32
|
+
this.addon = this.createAddon(config)
|
|
33
|
+
|
|
34
|
+
await this.addon.activate()
|
|
35
|
+
this.logger.info('GSTDecoder activated successfully')
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async _runInternal (audioStream) {
|
|
39
|
+
this.logger.info('Starting new audio stream processing')
|
|
40
|
+
const response = new QvacResponse({
|
|
41
|
+
cancelHandler: () => this.addon.cancel(jobId),
|
|
42
|
+
pauseHandler: () => this.addon.pause(),
|
|
43
|
+
continueHandler: () => this.addon.continue()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
const jobId = await this.addon.append({
|
|
47
|
+
type: 'audio',
|
|
48
|
+
input: new Uint8Array().buffer,
|
|
49
|
+
priority: 1
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
this.logger.info('Created new job with ID:', jobId)
|
|
53
|
+
this._saveJobToResponseMapping(jobId, response)
|
|
54
|
+
|
|
55
|
+
this._handleAudioStream(audioStream).catch(err => {
|
|
56
|
+
this.logger.error('Error processing audio stream:', err)
|
|
57
|
+
response.failed(err)
|
|
58
|
+
})
|
|
59
|
+
return response
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async _handleAudioStream (audioStream) {
|
|
63
|
+
this.logger.info('Starting audio stream handling')
|
|
64
|
+
const streamAccumulator = createStreamAccumulator({
|
|
65
|
+
onChunk: async chunk => {
|
|
66
|
+
this.logger.debug('Processing audio chunk of size:', chunk.byteLength)
|
|
67
|
+
await this.addon.append({
|
|
68
|
+
type: 'audio',
|
|
69
|
+
input: chunk.buffer,
|
|
70
|
+
priority: 1
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
onFinish: async () => {
|
|
74
|
+
this.logger.info('Audio stream finished, sending end of input')
|
|
75
|
+
await this.addon.append({ type: END_OF_INPUT })
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
for await (const chunk of audioStream) {
|
|
80
|
+
await streamAccumulator.processData(chunk)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await streamAccumulator.finish()
|
|
84
|
+
this.logger.info('Audio stream handling completed')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async getStatus () {
|
|
88
|
+
const status = await this.addon.status()
|
|
89
|
+
this.logger.debug('Current status:', status)
|
|
90
|
+
return status
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
createAddon (config) {
|
|
94
|
+
this.logger.info('Creating new GSTDecoderInterface instance')
|
|
95
|
+
return new GSTDecoderInterface(
|
|
96
|
+
config,
|
|
97
|
+
this._outputCallback.bind(this),
|
|
98
|
+
this.logger.info.bind(this.logger)
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = GSTDecoder
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qvac/decoder-audio",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Tether",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"addon": true,
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test:dts": "tsc index.d.ts --noEmit --esModuleInterop --skipLibCheck",
|
|
12
|
+
"test:unit": "npm run test:unit:generate && bare test/unit/all.js",
|
|
13
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
14
|
+
"coverage:unit": "brittle-bare --coverage --cov-dir=coverage/unit test/unit/*.test.js && npx istanbul report html --include=coverage/unit/coverage-final.json",
|
|
15
|
+
"coverage": "brittle-bare --coverage --cov-dir=coverage/unit test/unit/*.test.js && npx istanbul report html --include=coverage/unit/coverage-final.json",
|
|
16
|
+
"lint": "standard --ignore 'addon/**'",
|
|
17
|
+
"lint:fix": "standard --fix --ignore 'addon/**'",
|
|
18
|
+
"test:unit:generate": "brittle -r test/unit/all.js test/unit/*.test.js",
|
|
19
|
+
"test:integration:generate": "brittle -r test/integration/all.js test/integration/*.test.js",
|
|
20
|
+
"test:integration": "npm run test:integration:generate && bare test/integration/all.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"binding.js",
|
|
24
|
+
"index.js",
|
|
25
|
+
"gstreamer.js",
|
|
26
|
+
"prebuilds",
|
|
27
|
+
"utils",
|
|
28
|
+
"index.d.ts"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
"./package": "./package.json",
|
|
32
|
+
".": "./index.js"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22.14.1",
|
|
36
|
+
"bare-process": "^4.2.1",
|
|
37
|
+
"brittle": "^3.13.1",
|
|
38
|
+
"cmake-bare": "^1.5.2",
|
|
39
|
+
"cmake-vcpkg": "^1.1.0",
|
|
40
|
+
"istanbul": "^0.4.5",
|
|
41
|
+
"standard": "^17.1.2",
|
|
42
|
+
"typescript": "^5.3.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@qvac/infer-base": "^0.1.0",
|
|
46
|
+
"@qvac/error": "^0.1.0",
|
|
47
|
+
"@qvac/response": "^0.1.0",
|
|
48
|
+
"bare-assert": "^1.0.2",
|
|
49
|
+
"bare-fs": "^4.0.2"
|
|
50
|
+
},
|
|
51
|
+
"bugs": "https://github.com/tetherto/qvac-lib-decoder-audio/issues",
|
|
52
|
+
"types": "index.d.ts"
|
|
53
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|