Skip to content

Instantly share code, notes, and snippets.

@SamuelAlgheriniAI
Last active July 2, 2021 08:17
Show Gist options
  • Save SamuelAlgheriniAI/1f2918fd1b64cd3d4749f61cd1987649 to your computer and use it in GitHub Desktop.
Save SamuelAlgheriniAI/1f2918fd1b64cd3d4749f61cd1987649 to your computer and use it in GitHub Desktop.
The function loads and resamples the file to 16KhZ. Then store it to the resampled folder.
#Resampling function
def resample(file, sr):
print("\nResampling of " + file + " in progress")
path = path_converted_audio + file
audio, sr = librosa.load(path, sr=sr) #File load and resampling
length = librosa.get_duration(audio, sr) #File lenght
print("File " + file + " is",datetime.timedelta(seconds=round(length,0)),"sec. long")
sf.write(os.path.join(resampled_folder,file), audio, sr) #(resampled_folder + file, audio, sr)
resampled_path = os.path.join(resampled_folder,file) #resampled_folder + file
print(file + " was resampled to " + str(sr) + "kHz")
return resampled_path, length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment