sox_utils.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from typing import Dict, List
  2. import torch
  3. from torchaudio._internal import module_utils as _mod_utils
  4. @_mod_utils.requires_sox()
  5. def set_seed(seed: int):
  6. """Set libsox's PRNG
  7. Args:
  8. seed (int): seed value. valid range is int32.
  9. See Also:
  10. http://sox.sourceforge.net/sox.html
  11. """
  12. torch.ops.torchaudio.sox_utils_set_seed(seed)
  13. @_mod_utils.requires_sox()
  14. def set_verbosity(verbosity: int):
  15. """Set libsox's verbosity
  16. Args:
  17. verbosity (int): Set verbosity level of libsox.
  18. * ``1`` failure messages
  19. * ``2`` warnings
  20. * ``3`` details of processing
  21. * ``4``-``6`` increasing levels of debug messages
  22. See Also:
  23. http://sox.sourceforge.net/sox.html
  24. """
  25. torch.ops.torchaudio.sox_utils_set_verbosity(verbosity)
  26. @_mod_utils.requires_sox()
  27. def set_buffer_size(buffer_size: int):
  28. """Set buffer size for sox effect chain
  29. Args:
  30. buffer_size (int): Set the size in bytes of the buffers used for processing audio.
  31. See Also:
  32. http://sox.sourceforge.net/sox.html
  33. """
  34. torch.ops.torchaudio.sox_utils_set_buffer_size(buffer_size)
  35. @_mod_utils.requires_sox()
  36. def set_use_threads(use_threads: bool):
  37. """Set multithread option for sox effect chain
  38. Args:
  39. use_threads (bool): When ``True``, enables ``libsox``'s parallel effects channels processing.
  40. To use mutlithread, the underlying ``libsox`` has to be compiled with OpenMP support.
  41. See Also:
  42. http://sox.sourceforge.net/sox.html
  43. """
  44. torch.ops.torchaudio.sox_utils_set_use_threads(use_threads)
  45. @_mod_utils.requires_sox()
  46. def list_effects() -> Dict[str, str]:
  47. """List the available sox effect names
  48. Returns:
  49. Dict[str, str]: Mapping from ``effect name`` to ``usage``
  50. """
  51. return dict(torch.ops.torchaudio.sox_utils_list_effects())
  52. @_mod_utils.requires_sox()
  53. def list_read_formats() -> List[str]:
  54. """List the supported audio formats for read
  55. Returns:
  56. List[str]: List of supported audio formats
  57. """
  58. return torch.ops.torchaudio.sox_utils_list_read_formats()
  59. @_mod_utils.requires_sox()
  60. def list_write_formats() -> List[str]:
  61. """List the supported audio formats for write
  62. Returns:
  63. List[str]: List of supported audio formats
  64. """
  65. return torch.ops.torchaudio.sox_utils_list_write_formats()
  66. @_mod_utils.requires_sox()
  67. def get_buffer_size() -> int:
  68. """Get buffer size for sox effect chain
  69. Returns:
  70. int: size in bytes of buffers used for processing audio.
  71. """
  72. return torch.ops.torchaudio.sox_utils_get_buffer_size()