utils.py 383 B

123456789101112131415161718
  1. import numpy as np
  2. def next_power_of_2(x):
  3. return 1 if x == 0 else 2 ** (x - 1).bit_length()
  4. def int2float(sound):
  5. """
  6. Taken from https://github.com/snakers4/silero-vad
  7. """
  8. abs_max = np.abs(sound).max()
  9. sound = sound.astype("float32")
  10. if abs_max > 0:
  11. sound *= 1 / 32768
  12. sound = sound.squeeze() # depends on the use case
  13. return sound