Created
December 22, 2022 17:15
-
-
Save ovuruska/6290eb077085932cd5109adc8f00c759 to your computer and use it in GitHub Desktop.
Convert from any audio file to .wav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from pydub import AudioSegment | |
def convert_to_wav(audio_path,target_sr=32000): | |
P = Path(audio_path) | |
extension = P.suffix | |
extension = extension[1:] | |
if extension == "wav": | |
return audio_path | |
sound = AudioSegment.from_file(audio_path, format=extension) | |
sound = sound.set_frame_rate(target_sr) | |
new_path = P.with_suffix(".wav") | |
sound.export(new_path, format="wav") | |
return new_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment