crowsetta.formats.seq.audseq.AudSeq#

class crowsetta.formats.seq.audseq.AudSeq(start_times: ndarray, end_times: ndarray, labels: ndarray, annot_path: Path, notated_path=None)[source]#

Bases: object

Class meant to represent Audacity Labeltrack annotations exported to txt files in the standard format[1]_.

The txt file will have 3 tab-separated columns that represent the start time, end time, and labels of annotated regions.

name#

Shorthand name for annotation format: 'aud-seq'.

Type:

str

ext#

Extension of files in annotation format, '.txt'.

Type:

str

start_times#

Vector of integer sample numbers corresponding to beginning of segments, i.e. onsets.

Type:

numpy.ndarray

end_times#

Vector of integer sample numbers corresponding to ends of segments, i.e. offsets.

Type:

numpy.ndarray

labels#

Vector of string labels for segments; each element is either a single word, or a single phonetic transcription code.

Type:

numpy.ndarray

annot_path#

Path to file from which annotations were loaded.

Type:

str, pathlib.Path

notated_path#

Path to file that annot_path annotates. E.g., an audio file, or an array file that contains a spectrogram generated from audio. Optional, default is None.

Type:

str, pathlib.Path

References

__init__(start_times: ndarray, end_times: ndarray, labels: ndarray, annot_path: Path, notated_path=None) None#

Method generated by attrs for class AudSeq.

Methods

__init__(start_times, end_times, labels, ...)

Method generated by attrs for class AudSeq.

from_file(annot_path[, notated_path])

Load annotations from a file.

to_annot([round_times, decimals])

Convert this annotation to a crowsetta.Annotation.

to_file(annot_path)

Save this 'aud-seq' annotation to a txt file in the standard/default Audacity LabelTrack format.

to_seq([round_times, decimals])

Convert this annotation to a crowsetta.Sequence.

Attributes

start_times

end_times

labels

annot_path

notated_path

ext

name

classmethod from_file(annot_path: str | bytes | PathLike | Path, notated_path: str | bytes | PathLike | Path | None = None) Self[source]#

Load annotations from a file.

Parameters:
  • annot_path (str, pathlib.Path) – Path to an annotation file, with ‘.txt’ extension.

  • notated_path (str, pathlib.Path) – Path to file that annot_path annotates. E.g., an audio file, or an array file that contains a spectrogram generated from audio. Optional, default is None.

Examples

>>> example = crowsetta.data.get('aud-seq')
>>> audseq = crowsetta.formats.seq.AudSeq.from_file(example.annot_path)
to_annot(round_times: bool = True, decimals: int = 3) Annotation[source]#

Convert this annotation to a crowsetta.Annotation.

Parameters:
  • round_times (bool) – If True, round onsets_s and offsets_s. Default is True.

  • decimals (int) – Number of decimals places to round floating point numbers to. Only meaningful if round_times is True. Default is 3, so that times are rounded to milliseconds.

Returns:

annot

Return type:

crowsetta.Annotation

Examples

>>> example = crowsetta.data.get('aud-seq')
>>> audseq = crowsetta.formats.seq.AudSeq.from_file(example.annot_path)
>>> annot = audseq.to_annot()

Notes

The round_times and decimals arguments are provided to reduce differences across platforms due to floating point error, e.g. when loading annotation files and then sending them to a csv file, the result should be the same on Windows and Linux.

to_file(annot_path: str | bytes | PathLike | Path) None[source]#

Save this ‘aud-seq’ annotation to a txt file in the standard/default Audacity LabelTrack format.

Parameters:

annot_path (str, pathlib.Path) – Path with filename of txt file that should be saved.

to_seq(round_times: bool = True, decimals: int = 3) Sequence[source]#

Convert this annotation to a crowsetta.Sequence.

Parameters:
  • round_times (bool) – If True, round onsets_s and offsets_s. Default is True.

  • decimals (int) – Number of decimals places to round floating point numbers to. Only meaningful if round_times is True. Default is 3, so that times are rounded to milliseconds.

Returns:

seq

Return type:

crowsetta.Sequence

Examples

>>> example = crowsetta.data.get('aud-seq')
>>> audseq = crowsetta.formats.seq.AudSeq.from_file(example.annot_path)
>>> seq = audseq.to_seq()

Notes

The round_times and decimals arguments are provided to reduce differences across platforms due to floating point error, e.g. when loading annotation files and then sending them to a csv file, the result should be the same on Windows and Linux.