-
Notifications
You must be signed in to change notification settings - Fork 41
Misc. functionality
Jyotika Singh edited this page May 11, 2022
·
1 revision
You can convert you audio in .mp4, .mp3, .m4a and .aac to .wav. This will allow you to use audio feature generation and classification functionalities.
In order to convert your audios, the following code sample can be used.
from pyAudioProcessing.convert_audio import convert_files_to_wav
# dir_path is the path to the directory/folder on your machine containing audio files
dir_path = "data/mp4_files"
# simply change audio_format to "mp3", "m4a" or "acc" depending on the format
# of audio that you are trying to convert to wav
convert_files_to_wav(dir_path, audio_format="mp4")
# the converted wav files will be saved in the same dir_path location.
To remove low-activity regions from your audio clip, the following sample usage can be referred to.
from pyAudioProcessing import clean
clean.remove_silence(
<path to wav file>,
output_file=<path where you want to store cleaned wav file>
)
To see time-domain view of the audios, and the spectrogram of the audios, please refer to the following sample usage.
from pyAudioProcessing import plot
# spectrogram plot
plot.spectrogram(
<path to wav file>,
show=True, # set to False if you do not want the plot to show
save_to_disk=True, # set to False if you do not want the plot to save
output_file=<path where you want to store spectrogram as a png>
)
# time-series plot
plot.time(
<path to wav file>,
show=True, # set to False if you do not want the plot to show
save_to_disk=True, # set to False if you do not want the plot to save
output_file=<path where you want to store the plot as a png>
)