medkit.core.audio.document#

Classes#

AudioDocument

Document holding audio annotations.

Module Contents#

class medkit.core.audio.document.AudioDocument(audio: medkit.core.audio.audio_buffer.AudioBuffer, anns: Sequence[medkit.core.audio.annotation.Segment] | None = None, attrs: Sequence[medkit.core.Attribute] | None = None, metadata: dict[str, Any] | None = None, uid: str | None = None)#

Bases: medkit.core.dict_conv.SubclassMapping

Document holding audio annotations.

Attributes:
uid: str

Unique identifier of the document.

audio: AudioBuffer

Audio buffer containing the entire signal of the document.

anns: :class:`~.audio.AudioAnnotationContainer`

Annotations of the document. Stored in an AudioAnnotationContainer but can be passed as a list at init.

attrs: :class:`~.core.AttributeContainer`

Attributes of the document. Stored in an AttributeContainer but can be passed as a list at init

metadata: dict of str to Any

Document metadata.

raw_segment: :class:`~.audio.Segment`

Auto-generated segment containing the full unprocessed document audio.

RAW_LABEL: ClassVar[str] = 'RAW_AUDIO'#

Label to be used for raw segment

uid: str#
anns: medkit.core.audio.annotation_container.AudioAnnotationContainer#
attrs: medkit.core.AttributeContainer#
metadata: dict[str, Any]#
raw_segment: medkit.core.audio.annotation.Segment#
classmethod _generate_raw_segment(audio: medkit.core.audio.audio_buffer.AudioBuffer, doc_id: str) medkit.core.audio.annotation.Segment#
property audio: medkit.core.audio.audio_buffer.AudioBuffer#
classmethod __init_subclass__()#
to_dict(with_anns: bool = True) dict[str, Any]#
classmethod from_dict(data: dict[str, Any]) typing_extensions.Self#
classmethod from_file(path: os.PathLike) typing_extensions.Self#

Create document from an audio file.

Parameters:
path: path-like

Path to the audio file. Supports all file formats handled by libsndfile (http://www.mega-nerd.com/libsndfile/#Features)

Returns:
AudioDocument

Audio document with signal of path as audio. The file path is included in the document metadata.

classmethod from_dir(path: os.PathLike, pattern: str = '*.wav') list[typing_extensions.Self]#

Create documents from audio files in a directory.

Parameters:
path: path-like

Path of the directory containing audio files

pattern: str, default=”*.wav”

Glob pattern to match audio files in path. Supports all file formats handled by libsndfile (http://www.mega-nerd.com/libsndfile/#Features)

Returns:
List[AudioDocument]

Audio documents with signal of each file as audio