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.

index.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  1. // @flow
  2. // Script expects to find rnnoise webassembly binary in the same public path root, otherwise it won't load
  3. // During the build phase this needs to be taken care of manually
  4. import rnnoiseWasmInit from 'rnnoise-wasm';
  5. import RnnoiseProcessor from './RnnoiseProcessor';
  6. export { RNNOISE_SAMPLE_LENGTH } from './RnnoiseProcessor';
  7. export type { RnnoiseProcessor };
  8. let rnnoiseWasmInterface;
  9. let initializePromise;
  10. /**
  11. * Creates a new instance of RnnoiseProcessor.
  12. *
  13. * @returns {Promise<RnnoiseProcessor>}
  14. */
  15. export function createRnnoiseProcessor() {
  16. if (!initializePromise) {
  17. initializePromise = new Promise((resolve, reject) => {
  18. rnnoiseWasmInterface = rnnoiseWasmInit({
  19. onRuntimeInitialized() {
  20. resolve();
  21. },
  22. onAbort(reason) {
  23. reject(reason);
  24. }
  25. });
  26. });
  27. }
  28. return initializePromise.then(
  29. () => new RnnoiseProcessor(rnnoiseWasmInterface)
  30. );
  31. }