msqr1 / Vosklet

A speech recognizer that can run on the browser, inspired by vosk-browser
MIT License
33 stars 1 forks source link

Problem with memory #10

Closed xiz2020 closed 3 months ago

xiz2020 commented 3 months ago

Thanks for interesting project!

I have several questions:

  1. After some time it stop working with following errors:

Screenshot 2024-08-19 002047 Screenshot 2024-08-19 011904

  1. How to dynamically change models?
  2. How to free shared buffer from dev.tools?

Tested on localhost.

`<script>
async function start() {
        let ctx = new AudioContext({sampleRate : 16000})
        let micNode = ctx.createMediaStreamSource(await navigator.mediaDevices.getUserMedia({
          video: false,
          audio: {
            echoCancellation: true,
            noiseSuppression: true,
            channelCount: 1,
            sampleRate: 16000
          },
        }))

        let module = await loadVosklet()
        let model = await module.createModel("https://github.com/msqr1/Vosklet/raw/main/examples/en-model.tgz","model","ID")
        let recognizer = await module.createRecognizer(model, 16000)
        recognizer.addEventListener("result", ev => {
          console.log("Result 1: ", ev.detail)
        })
        recognizer.addEventListener("partialResult", ev => {
          console.log("Partial result 2: ", ev.detail)
        })

        let transferer = await module.createTransferer(ctx, 128 * 150)
        transferer.port.onmessage = ev => {
          recognizer.acceptWaveform(ev.data)
        }
        micNode.connect(transferer)
      }
</script>`

Thanks.

msqr1 commented 3 months ago
  1. The latest version, 1.1.0 should fix this by allowing memory growth
  2. The underlying library, Vosk, doesn't allow dynamic model change. The best you can do here is delete both the model and recognizer, load the new model, and load the new recognizer with the new model.
  3. I don't really know how. Could you tell me more on why you need to do this? @xiz2020