Python wrapper for Xiph.org rnnoise ( https://gitlab.xiph.org/xiph/rnnoise )
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.

rnnoise_demo.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (c) 2018 Gregor Richards
  2. * Copyright (c) 2017 Mozilla
  3. * Copyright (c) 2023 Yann Weber */
  4. /*
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. - Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. - Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  17. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  20. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  21. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <rnnoise.h>
  28. #define FRAME_SIZE 480
  29. int main(int argc, char **argv) {
  30. int i;
  31. int first = 1;
  32. float x[FRAME_SIZE];
  33. FILE *f1, *fout;
  34. DenoiseState *st;
  35. st = rnnoise_create(NULL);
  36. if (argc!=3) {
  37. fprintf(stderr, "usage: %s <noisy speech> <output denoised>\n", argv[0]);
  38. return 1;
  39. }
  40. f1 = fopen(argv[1], "rb");
  41. fout = fopen(argv[2], "wb");
  42. while (1) {
  43. short tmp[FRAME_SIZE];
  44. size_t readed = fread(tmp, sizeof(short), FRAME_SIZE, f1);
  45. bzero(x, sizeof(x));
  46. for (i=0;i<readed;i++) x[i] = tmp[i];
  47. rnnoise_process_frame(st, x, x);
  48. for (i=0;i<readed;i++) tmp[i] = x[i];
  49. fwrite(tmp, sizeof(short), readed, fout);
  50. if (feof(f1)) break;
  51. first = 0;
  52. }
  53. rnnoise_destroy(st);
  54. fclose(f1);
  55. fclose(fout);
  56. return 0;
  57. }