Skip to content

Log audio¶

Comet's audio logging enables you to store audio recordings and audio-based outputs from your experiments.

Example of Audio tab
Example of audio source displayed in the Audio tab of the Comet UI

You can access and play the logged audio samples from the Comet UI to easily analyze its patterns and characteristics, from any starting point of your choice.

The following method can be used to log audio samples:

In addition all the audio samples logged to an Experiment can be view in the Single Experiment page tabs:

Discover more in our Working with Audio Data for Machine Learning in Python blog post.

For example, you could...

Analyze logged audio sources during the training of a voice-controlled assistant to uncover common speech patterns behind model errors.

Log an audio sample¶

You can log audio from file path or from numpy array. You can find a list of supported audio codecs here.

The example below logs one randomly generated audio sample as a numpy array.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import comet_ml
import numpy as np

# Initialize the Comet Experiment
comet_ml.login()
exp = comet_ml.start()

# Create an example audio
fs = 100
rate = 44100
t = np.linspace(0., 1., rate)
amplitude = np.iinfo(np.int16).max
audio_sample = amplitude * np.sin(2. * np.pi * fs * t)

# Log the audio to Comet
exp.log_audio(
    audio_data=audio_sample,
    sample_rate=rate,
    file_name="Example Audio",
    step=0,
)

The sample_rate argument is provided to support the automatic creation of a .wav file from the provided numpy array with the scipy.io.wavfile.write() method.

Additionally, you could use the overwrite argument to overwrite any existing asset with the same name or add a metadata argument to log extra information (such as tags) in a JSON format.

Nov. 18, 2024