-
-
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.
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
#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