Tracks

A Track wraps an audio file or an array of raw PCM data.

class radiotool.composer.Track(fn, name='No name')

Represents a wrapped .wav file.

__init__(fn, name='No name')

Create a Track object

Parameters:
  • fn (str.) – Path to wav file
  • name (str.) – Name of track
all_as_mono()

Get the entire track as 1 combined channel

Returns:Track frames as 1 combined track
Return type:1d numpy array
current_frame None

Get and set the current frame of the track

duration None

Get the duration of total frames in the track

duration_in_seconds None

Get the duration of the track in seconds

loudest_time(start=0, duration=0)

Find the loudest time in the window given by start and duration Returns frame number in context of entire track, not just the window.

Parameters:
  • start (integer) – Start frame
  • duration (integer) – Number of frames to consider from start
Returns:

Frame number of loudest frame

Return type:

integer

range_as_mono(start_sample, end_sample)

Get a range of frames as 1 combined channel

Parameters:
  • start_sample (integer) – First frame in range
  • end_sample (integer) – Last frame in range (exclusive)
Returns:

Track frames in range as 1 combined channel

Return type:

1d numpy array of length end_sample - start_sample

read_frames(n, channels=None)

Read n frames from the track, starting with the current frame

Parameters:
  • n (integer) – Number of frames to read
  • channels (integer) – Number of channels to return (default is number of channels in track)
Returns:

Next n frames from the track, starting with current_frame

Return type:

numpy array

remaining_frames()

Get the number of frames remaining in the track

reset()

Sets current frame to 0

samplerate None

Get the sample rate of the track

zero_crossing_after(n)

Find nearest zero crossing in waveform after frame n

zero_crossing_before(n)

Find nearest zero crossing in waveform before frame n

class radiotool.composer.Speech(fn, name='Speech name')

A radiotool.composer.Track subclass that wraps a speech .wav file

class radiotool.composer.Song(fn, name='Song name')

A radiotool.composer.Track subclass that wraps a music .wav file. Allows access to a musical analysis of the song.

analysis None

Get musical anaylsis of the song using the librosa library

class radiotool.composer.RawTrack(frames, name='Raw frames name', samplerate=44100)

A radiotool.composer.Track subclass that wraps raw PCM data (as a numpy array).

__init__(frames, name='Raw frames name', samplerate=44100)

Create a track with raw PCM data in array frames

Parameters:
  • frames (numpy array) – Raw PCM data array
  • samplerate (integer) – Sample rate of frames
  • name (string) – Name of track

Previous topic

Composition

Next topic

Segments

This Page

Fork me on GitHub