Skip to content

Instantly share code, notes, and snippets.

@tikhonova
Last active April 16, 2023 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tikhonova/2bfdede483b2aed68c9968754102bbe9 to your computer and use it in GitHub Desktop.
Save tikhonova/2bfdede483b2aed68c9968754102bbe9 to your computer and use it in GitHub Desktop.
def convert_audio_to_wav(filename: str, filepath: str, dest_path: str) -> None:
filepath = os.path.join(filepath, filename)
dest_filepath = os.path.join(dest_path, f"{filename[:-4]}.wav")
given_audio = AudioSegment.from_file(filepath, format="mp3") # replace with mp4 or avi
given_audio.export(dest_filepath, format="wav")
# create a list of input arguments for the function
inputs = [(filename, filepath, dest_path) for filename in os.listdir(filepath) if filename not in os.listdir(dest_path)]
# create a Process pool with 16 worker processes
if __name__ == '__main__':
freeze_support()
p = multiprocessing.Pool(16)
p.starmap(convert_audio_to_wav, inputs)
# via https://github.com/tikhonova/what_would_alan_watts_say/blob/master/speech_synthesis/0_audio_convert_to_wav.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment