asrtoolkit/data_structures/audio_file.py
def degrade_audio(source_audio_file, target_audio_file=None):
  """
    Degrades audio to typical G711 level. Useful if models need to target this audio quality.
  """

  target_audio_file = source_audio_file if target_audio_file is None else target_audio_file

  # degrade to 8k
  tmp1 = ".".join(source_audio_file.split(".")[:-1]) + "_tmp1.wav"
  subprocess.call(["sox {} -r 8000 -e a-law {}".format(source_audio_file, tmp1)], shell=True)

  # convert to u-law
  tmp2 = ".".join(source_audio_file.split(".")[:-1]) + "_tmp2.wav"
  subprocess.call(["sox {} --rate 8000 -e u-law {}".format(tmp1, tmp2)], shell=True)

  # upgrade to 16k a-law signed
  subprocess.call(["sox {} --rate 16000 -e signed  -b 16 --channel 1 {}".format(tmp2, target_audio_file)], shell=True)
  os.remove(tmp1)
  os.remove(tmp2)

    Degrades audio to typical G711 level. Useful if models need to target this audio quality.
  
Degrades audio to typical G711 level. Useful if models need to target this audio quality.
Degrades audio to typical G711 level . Useful if models need to target this audio quality .
def degrade_audio(source_audio_file, target_audio_file=None):
  target_audio_file = source_audio_file if target_audio_file is None else target_audio_file
  tmp1 = ".".join(source_audio_file.split(".")[:-1]) + "_tmp1.wav"
  subprocess.call(["sox {} -r 8000 -e a-law {}".format(source_audio_file, tmp1)], shell=True)
  tmp2 = ".".join(source_audio_file.split(".")[:-1]) + "_tmp2.wav"
  subprocess.call(["sox {} --rate 8000 -e u-law {}".format(tmp1, tmp2)], shell=True)
  subprocess.call(["sox {} --rate 16000 -e signed  -b 16 --channel 1 {}".format(tmp2, target_audio_file)], shell=True)
  os.remove(tmp1)
  os.remove(tmp2)
def degrade_audio ( source_audio_file , target_audio_file = None ) : target_audio_file = source_audio_file if target_audio_file is None else target_audio_file tmp1 = "." . join ( source_audio_file . split ( "." ) [ : - 1 ] ) + "_tmp1.wav" subprocess . call ( [ "sox {} -r 8000 -e a-law {}" . format ( source_audio_file , tmp1 ) ] , shell = True ) tmp2 = "." . join ( source_audio_file . split ( "." ) [ : - 1 ] ) + "_tmp2.wav" subprocess . call ( [ "sox {} --rate 8000 -e u-law {}" . format ( tmp1 , tmp2 ) ] , shell = True ) subprocess . call ( [ "sox {} --rate 16000 -e signed  -b 16 --channel 1 {}" . format ( tmp2 , target_audio_file ) ] , shell = True ) os . remove ( tmp1 ) os . remove ( tmp2 )
Degrades audio to typical G711 level.
Degrades audio to typical G711 level .
"""
    Degrades audio to typical G711 level. Useful if models need to target this audio quality.
  """ # degrade to 8k # convert to u-law # upgrade to 16k a-law signed
source_audio_file
target_audio_file