Skip to main content

AudioMate Examples

AudioMate - How To Examples in Python

AudioMate is a Python library that provides various functionalities for working with audio files. It allows you to perform tasks like reading and writing audio files, applying audio effects, extracting features from audio, and much more. In this tutorial, we will cover 10 examples to help you understand how to use the AudioMate library effectively.

Example 1: Reading an Audio File

To read an audio file using AudioMate, you can use the audioread module. Here's an example:

import audioread

# Open the audio file
with audioread.audio_open('audio.wav') as f:
# Read and print the audio file metadata
print(f.channels, f.samplerate, f.duration)

# Iterate over the audio frames and print them
for frame in f:
print(frame)

Expected Output:

  • The number of channels, sample rate, and duration of the audio file will be printed.
  • The audio frames will be printed one by one.

Example 2: Writing an Audio File

You can use the soundfile module in AudioMate to write an audio file. Here's an example:

import soundfile as sf
import numpy as np

# Create a numpy array of audio data
data = np.random.uniform(-1, 1, 44100)

# Write the audio data to a file
sf.write('output.wav', data, 44100)

Expected Output:

  • An audio file named "output.wav" will be created with random audio data.

Example 3: Applying Audio Effects

AudioMate provides a variety of audio effects that you can apply to audio files. Here's an example of applying a low-pass filter:

import soundfile as sf
import audiomate
from audiomate import effects

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Apply a low-pass filter
filtered_data = effects.low_pass_filter(data, sample_rate, cutoff_freq=5000)

# Save the filtered audio to a new file
sf.write('filtered.wav', filtered_data, sample_rate)

Expected Output:

  • An audio file named "filtered.wav" will be created with the input audio file after applying a low-pass filter with a cutoff frequency of 5000 Hz.

Example 4: Extracting Audio Features

AudioMate allows you to extract various audio features from audio files. Here's an example of extracting mel-frequency cepstral coefficients (MFCCs):

import soundfile as sf
from audiomate import features

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Extract MFCCs
mfccs = features.mfcc(data, sample_rate)

# Print the MFCCs
print(mfccs)

Expected Output:

  • The extracted MFCCs will be printed as a numpy array.

Example 5: Concatenating Audio Files

AudioMate provides a convenient way to concatenate multiple audio files into a single file. Here's an example:

import soundfile as sf
from audiomate import utils

# Read the input audio files
data1, sample_rate1 = sf.read('audio1.wav')
data2, sample_rate2 = sf.read('audio2.wav')

# Concatenate the audio data
concatenated_data = utils.concat_audio([data1, data2], [sample_rate1, sample_rate2])

# Write the concatenated audio to a new file
sf.write('concatenated.wav', concatenated_data, sample_rate1)

Expected Output:

  • An audio file named "concatenated.wav" will be created by concatenating the audio data from "audio1.wav" and "audio2.wav".

Example 6: Resampling Audio

You can use AudioMate to resample audio files to a different sample rate. Here's an example:

import soundfile as sf
from audiomate import utils

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Resample the audio to a new sample rate
resampled_data = utils.resample_audio(data, sample_rate, new_sample_rate=16000)

# Write the resampled audio to a new file
sf.write('resampled.wav', resampled_data, 16000)

Expected Output:

  • An audio file named "resampled.wav" will be created with the input audio file resampled to a sample rate of 16000 Hz.

Example 7: Splitting Audio into Segments

AudioMate allows you to split audio files into segments of fixed duration. Here's an example:

import soundfile as sf
from audiomate import utils

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Split the audio into segments of 5 seconds
segments = utils.split_audio(data, sample_rate, segment_duration=5)

# Write each segment to a separate file
for i, segment in enumerate(segments):
sf.write(f'segment{i}.wav', segment, sample_rate)

Expected Output:

  • Multiple audio files named "segment0.wav", "segment1.wav", etc. will be created, each containing a 5-second segment of the input audio file.

Example 8: Applying Volume Normalization

You can use AudioMate to apply volume normalization to audio files. Here's an example:

import soundfile as sf
from audiomate import effects

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Normalize the audio volume
normalized_data = effects.normalize_volume(data)

# Write the normalized audio to a new file
sf.write('normalized.wav', normalized_data, sample_rate)

Expected Output:

  • An audio file named "normalized.wav" will be created with the input audio file after applying volume normalization.

Example 9: Generating Silence

AudioMate provides a simple way to generate silence audio segments. Here's an example:

import soundfile as sf
from audiomate import utils

# Generate 5 seconds of silence
silence_data = utils.generate_silence(5, sample_rate=44100)

# Write the silence audio to a file
sf.write('silence.wav', silence_data, 44100)

Expected Output:

  • An audio file named "silence.wav" will be created with 5 seconds of silence.

Example 10: Pitch Shifting

You can use AudioMate to apply pitch shifting to audio files. Here's an example:

import soundfile as sf
from audiomate import effects

# Read the input audio file
data, sample_rate = sf.read('input.wav')

# Shift the pitch by 2 semitones
shifted_data = effects.pitch_shift(data, sample_rate, semitones=2)

# Write the shifted audio to a new file
sf.write('shifted.wav', shifted_data, sample_rate)

Expected Output:

  • An audio file named "shifted.wav" will be created with the input audio file after applying a pitch shift of 2 semitones.

These examples should give you a good starting point for working with the AudioMate library in Python. Feel free to explore the library's documentation for more advanced features and functionalities.