You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @flow
  2. import { getJitsiMeetGlobalNS, loadScript } from '../base/util';
  3. let loadRnnoisePromise;
  4. /**
  5. * Returns promise that resolves with a RnnoiseProcessor instance.
  6. *
  7. * @returns {Promise<RnnoiseProcessor>} - Resolves with the blur effect instance.
  8. */
  9. export function createRnnoiseProcessorPromise() {
  10. // Subsequent calls should not attempt to load the script multiple times.
  11. if (!loadRnnoisePromise) {
  12. loadRnnoisePromise = loadScript('libs/rnnoise-processor.min.js');
  13. }
  14. return loadRnnoisePromise.then(() => {
  15. const ns = getJitsiMeetGlobalNS();
  16. if (ns?.effects?.rnnoise?.createRnnoiseProcessor) {
  17. return ns.effects.rnnoise.createRnnoiseProcessor();
  18. }
  19. throw new Error('Rnnoise module binding createRnnoiseProcessor not found!');
  20. });
  21. }
  22. /**
  23. * Get the accepted sample length for the rnnoise library. We might want to expose it with flow libdefs.
  24. *
  25. * @returns {number}
  26. */
  27. export function getSampleLength() {
  28. const ns = getJitsiMeetGlobalNS();
  29. const rnnoiseSample = ns?.effects?.rnnoise?.RNNOISE_SAMPLE_LENGTH;
  30. if (!rnnoiseSample) {
  31. throw new Error('Please call createRnnoiseProcessorPromise first or wait for promise to resolve!');
  32. }
  33. return rnnoiseSample;
  34. }