xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
10.86k stars 657 forks source link

[Feature request] Real time whisper transcription #405

Open vjeux opened 9 months ago

vjeux commented 9 months ago

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.

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

xenova commented 9 months ago

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! 😇

vjeux commented 9 months ago

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.

xenova commented 9 months ago

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.

vjeux commented 9 months ago

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.

luwes commented 9 months ago

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/

arpu commented 8 months ago

does onnx deprecate the webgl backend?

avie41 commented 6 months ago

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 ?

everythinginjs commented 3 months ago

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

xenova commented 1 day ago

This is now possible with Transformers.js v3: https://x.com/xenovacom/status/1799110540700078422 🥳 Online demo: https://huggingface.co/spaces/Xenova/realtime-whisper-webgpu

https://github.com/user-attachments/assets/33adbc4d-7cee-4feb-97f3-6bd1d68fefa6

I'll close this issue once Transformers.js v3 is officially out and #545 is merged 🚀

vjeux commented 19 hours ago

image