Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/qvac-lib-infer-parakeet/parakeet.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const state = Object.freeze({
STOPPED: 'stopped'
})

function nextSafeId (current) {
return current >= Number.MAX_SAFE_INTEGER ? 1 : current + 1
}

function createParakeetError (code, message, cause = undefined) {
// @qvac/error expects an options object, while the local fallback class
// accepts positional args. Support both call shapes.
Expand Down Expand Up @@ -211,9 +215,8 @@ class ParakeetInterface {
throw new Error('Cannot set new job: a job is already set or being processed')
}

// Only replace the active job after the native runner accepts it.
this._activeJobId = currentJobId
this._nextJobId += 1
this._nextJobId = nextSafeId(this._nextJobId)
this._bufferedAudio = []
this._setState(state.PROCESSING)
return currentJobId
Expand Down Expand Up @@ -377,7 +380,7 @@ class ParakeetInterface {
return false
}
this._activeJobId = currentJobId
this._nextJobId += 1
this._nextJobId = nextSafeId(this._nextJobId)
this._setState(state.PROCESSING)
return accepted
} catch (error) {
Expand Down
10 changes: 7 additions & 3 deletions packages/qvac-lib-infer-whispercpp/whisper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const state = Object.freeze({

const END_OF_INPUT = 'end of job'

function nextSafeId (current) {
return current >= Number.MAX_SAFE_INTEGER ? 1 : current + 1
}

/**
* An interface between Bare addon in C++ and JS runtime.
*/
Expand Down Expand Up @@ -265,7 +269,7 @@ class WhisperInterface {
}

this._activeJobId = currentJobId
this._nextJobId += 1
this._nextJobId = nextSafeId(this._nextJobId)
this._bufferedAudio = []
this._setState(state.PROCESSING)
return currentJobId
Expand Down Expand Up @@ -335,7 +339,7 @@ class WhisperInterface {
async runJob (data) {
try {
this._activeJobId = this._nextJobId
this._nextJobId += 1
this._nextJobId = nextSafeId(this._nextJobId)
this._setState(state.PROCESSING)
const accepted = this._binding.runJob(this._handle, {
...data,
Expand All @@ -360,7 +364,7 @@ class WhisperInterface {
startStreaming (config = {}) {
try {
this._activeJobId = this._nextJobId
this._nextJobId += 1
this._nextJobId = nextSafeId(this._nextJobId)
this._setState(state.PROCESSING)
this._binding.startStreaming(this._handle, config)
} catch (err) {
Expand Down
Loading