speech-processor.js 744 B

12345678910111213141516171819202122
  1. /* Implementation of the AudioWorkletProcessor
  2. https://webaudio.github.io/web-audio-api/#audioworklet
  3. This file will be loaded only in recent browsers that supports Audio worklet it is
  4. currently in js because it needs to be in es6 */
  5. class SpeechProcessor extends AudioWorkletProcessor {
  6. constructor(options) {
  7. // The super constructor call is required.
  8. super(options);
  9. }
  10. process(inputs, outputs) {
  11. const input = inputs[0];
  12. const output = []; // Make sure output array can be assigned to
  13. for (let channel = 0; channel < input.length; channel += 1) {
  14. output[channel] = input[channel];
  15. }
  16. this.port.postMessage(output[0]);
  17. return true;
  18. }
  19. }
  20. registerProcessor('speech-processor', SpeechProcessor);