transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

[Feature request] Real time whisper transcription

Open vjeux opened this issue 1 year ago • 10 comments

Real time whisper transcription

Right now the demo works for a recording but does it in one shot. I'd love to be able to do it as I speak. Sadly the interface seems to be accepting only a Float32Array (or arrays of) and not a way to keep feeding it float32 arrays as we receive them from the audio source.

Would be great to be able to do it in a streaming fashion.

  • Demo: https://huggingface.co/spaces/Xenova/whisper-web
  • Code: https://github.com/xenova/whisper-web/blob/main/src/worker.js#L152
  • API Doc: https://huggingface.co/docs/transformers.js/main/en/api/pipelines#module_pipelines.AutomaticSpeechRecognitionPipeline

Reason for request

I want to build a tool to help recording off voice and want to get a real time transcription to overlay on-top of the existing one to help get a sense of progress.

Thanks <3

vjeux avatar Nov 19 '23 22:11 vjeux

Real-time transcription will hopefully be possible once webgpu support is added, and we'll definitely revisit (and update the demo) once it is. If someone in the community would like to try modify the whisper-web source code (or provide a basic streaming) implementation, which could be adapted once webgpu is supported, that would be great! 😇

xenova avatar Nov 23 '23 20:11 xenova

Curious why is it waiting for WebGPU, at least on my macbook pro pre-m1, the decoding is faster than the time of the recording. What would be needed is to be able to feed audio frames in an async way instead of all at once.

vjeux avatar Nov 23 '23 20:11 vjeux

The major bottleneck at the moment is the encoder, which can take a few seconds to process ~30 seconds. Ideally, if we were to process shorter audio sequences, it would take much shorter, however, this is a hard constraint of the architecture. The initial transformations into log-mel spectrogram space produce 30 second chunks that are fed into the encoder. See here for more discussion on this.

xenova avatar Nov 23 '23 21:11 xenova

Sorry for the super late reply. That makes sense. Thanks for the link to the discussions. Let me bring more visibility to this issue see if someone is interested in contributing.

vjeux avatar Nov 28 '23 21:11 vjeux

it's not real time but it might give someone some inspiration for chunked processing. I created this custom video element that automatically generates captions from the source (mp4 only atm) repo: https://github.com/luwes/ai-media-element demo: https://luwes.github.io/ai-media-element/

luwes avatar Dec 07 '23 18:12 luwes

does onnx deprecate the webgl backend?

arpu avatar Dec 26 '23 23:12 arpu

Hi luwes, xenova, Did you finally manage to implement realtime transcription with Whisper ? Do you think it is still too early to think about it regarding the required processing time for the encoder when running the inference ?

avie41 avatar Feb 19 '24 13:02 avie41

Hi @xenova , a must-have feature looking forward any updates ?

everythinginjs avatar May 17 '24 04:05 everythinginjs