AudioFile#
- class osekit.core_api.audio_file.AudioFile(path: PathLike | str, begin: Timestamp | None = None, strptime_format: str | list[str] | None = None, timezone: str | pytz.timezone | None = None)#
Audio file associated with timestamps.
Initialize an
AudioFileobject with a path and a begin timestamp.- The begin timestamp can either be provided as a parameter
or parsed from the filename according to the provided
strptime_format.
Parameters#
- path: PathLike | str
Full path to the file.
- begin: pandas.Timestamp | None
Timestamp corresponding to the first data point in the file. If it is not provided,
strptime_formatis mandatory. If bothbeginandstrptime_formatare provided,beginwill overrule the timestamp embedded in the filename.- strptime_format: str | None
The strptime format used in the text. It should use valid strftime codes (https://strftime.org/). Example:
'%y%m%d_%H:%M:%S'.- timezone: str | pytz.timezone | None
The timezone in which the file should be localized. If
None, the file begin/end will be tz-naive. If different from a timezone parsed from the filename, the timestamps’ timezone will be converted from the parsed timezone to the specified timezone.
- frames_indexes(start: Timestamp, stop: Timestamp) tuple[int, int]#
Return the indexes of the frames between the
startandstoptimestamps.The
startindex is that of the first sample that ends after thestarttimestamp. Thestopindex is that of the last sample that starts before thestoptimestamp.Parameters#
- start: pandas.Timestamp
Timestamp corresponding to the first data point to read.
- stop: pandas.Timestamp
Timestamp after the last data point to read.
Returns#
- tuple[int,int]
First and last frames of the data.
- move(folder: Path) None#
Move the file to the target folder.
Parameters#
- folder: Path
destination folder where the file will be moved.
- read(start: Timestamp, stop: Timestamp) np.ndarray#
Return the audio data between start and stop from the file.
Parameters#
- start: pandas.Timestamp
Timestamp corresponding to the first data point to read.
- stop: pandas.Timestamp
Timestamp after the last data point to read.
Returns#
- numpy.ndarray:
The audio data between
startandstop. The first frame of the data is the first frame that ends afterstart. The last frame of the data is the last frame that starts beforestop.