Skip to content

Commit

Permalink
Accept timestamp token one above the expected maximum, and ensure the…
Browse files Browse the repository at this point in the history
… conversion to seconds clips to the valid range.
  • Loading branch information
rotemdan committed Dec 24, 2024
1 parent 8d09b86 commit 5430677
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/recognition/WhisperSTT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ export class Whisper {

const timestampTokensCount = 1501

for (let i = 0; i < timestampTokensCount; i++) {
for (let i = 0; i <= timestampTokensCount; i++) {
const tokenIndex = this.tokenConfig.timestampTokensStart + i
const tokenTime = this.timestampTokenToSeconds(tokenIndex)

Expand Down Expand Up @@ -1727,11 +1727,15 @@ export class Whisper {
throw new Error(`Invalid timestamp token: ${timestampToken}`)
}

return (timestampToken - this.tokenConfig.timestampTokensStart) * 0.02
let seconds = (timestampToken - this.tokenConfig.timestampTokensStart) * 0.02
seconds = clip(seconds, 0.0, 30.0)

return seconds
}

isValidToken(token: number) {
return token < this.tokenConfig.timestampTokensEnd
//return token < this.tokenConfig.timestampTokensEnd
return token <= this.tokenConfig.timestampTokensEnd
}

assertIsValidToken(token: number) {
Expand Down

0 comments on commit 5430677

Please sign in to comment.