OpenCut icon indicating copy to clipboard operation
OpenCut copied to clipboard

[BUG] The result of "Generate transcript" is inaccurate

Open HeaveNsHzj opened this issue 9 months ago • 4 comments

Platform

mac

Browser

Chrome 144

Current Behavior

the result of "Generate transcript" is inaccurate,due to audio data samplerate mismatch. whisper require samplerate=16000, not 44100。

Image

in my case, audio duration is 22s,but transcript result duration is 60.6s, 22 * 44100 / 16000 = 60.6

Expected Behavior

No response

Recurrence Probability

Always

Steps To Reproduce

  1. update an audio/video
  2. click "Generate transcript"
  3. wait for result
  4. result duration mismatch

Anything else?

No response

HeaveNsHzj avatar Feb 07 '26 04:02 HeaveNsHzj

I believe I’ve been hitting the same underlying issue, but with a different symptom. When generating captions for some videos, Whisper frequently returns output that suggests it is misreading the audio, for example "[snoring]", even when the source clip has clear speech.

I put together a branch with a proposed fix here: https://github.com/kcfancher/OpenCut/commit/c8ea0114e968a1eabd98076d3d181a9011e9d1ab. The issue appears to be that the transcription worker is receiving raw browser-decoded Float32Array audio without preserving or normalizing the original sample rate. Since the Whisper pipeline in this path is being fed raw samples directly, it is not automatically resampling them for us. The fix passes the decoded sample rate through to the worker and resamples the audio to the model's expected rate before inference.

I haven't opened a PR yet, as prior approval is requested. Does this fix fit in line with what you're currently looking for?

kcfancher avatar Mar 07 '26 18:03 kcfancher

I believe I’ve been hitting the same underlying issue, but with a different symptom. When generating captions for some videos, Whisper frequently returns output that suggests it is misreading the audio, for example "[snoring]", even when the source clip has clear speech.

I put together a branch with a proposed fix here: kcfancher@c8ea011. The issue appears to be that the transcription worker is receiving raw browser-decoded Float32Array audio without preserving or normalizing the original sample rate. Since the Whisper pipeline in this path is being fed raw samples directly, it is not automatically resampling them for us. The fix passes the decoded sample rate through to the worker and resamples the audio to the model's expected rate before inference.

I haven't opened a PR yet, as prior approval is requested. Does this fix fit in line with what you're currently looking for?

I think it is more simple use const buffer = new AudioContext({ sampleRate: 16000 }).decodeAudioData(); // buffer should be resample to 16000 in decodeAudioToFloat32 function

HeaveNsHzj avatar Mar 10 '26 13:03 HeaveNsHzj

Yes, that is definitely a much simpler change.

I chose to isolate the sample-rate handling in the transcription worker so that the code change stayed isolated to the transcription specific code rather than a generic helper.

I see two practical routes

1. Resample in the transcription worker (My current patch)

Keeps the resampling entirely in the transcription flow and leaves decodeAudioToFloat32() as a generic helper for future use.

2. Decode to 16000 in decodeAudioToFloat32() (HeaveNsHzj’s suggestion)

This is the simplest code change (just a single line). The downside is that it changes a generic helper into an implicitly transcription focused one.

At the moment that doesn’t cause any issues, especially if it’s intended only for transcriptions, but if it’s meant to be reusable for other workflows in the future I’d prefer

2a. renaming it to something transcription specific like decodeAudioForTranscription(), or 2b. adding an optional sampleRate parameter so the transcriber can specify 16000 explicitly.

Of those options, my preference is 2b.

@mazeincoding what are your thoughts? Let me know which direction you'd like me to head and I can create a new commit and submit a PR.

kcfancher avatar Mar 11 '26 19:03 kcfancher

@mazeincoding what are your thoughts? Let me know which direction you'd like me to head and I can create a new commit and submit a PR.

yeah, 2b works well, go for it

mazeincoding avatar Mar 12 '26 23:03 mazeincoding