def test_audio(self): event = audio(asset_path=self.asset_path, tensor=tensor_np(shape=(42, ))) assert event.path == self.asset_path assert os.path.exists(self.asset_path) is True
def log_audio( self, data, name=None, sample_rate=44100, step=None, timestamp=None, content_type=None, ): """Logs a audio. ```python >>> log_audio("path/to/my_audio1"), >>> log_audio(name="my_audio2", data=np.arange(np.prod((42,)), dtype=float).reshape((42,))) ``` Args: data: str or audio data name: str, optional, if data is a filepath the name will be the name of the file sample_rate: int, optional, sample rate in Hz step: int, optional timestamp: datetime, optional content_type: str, optional, default "wav" """ self._log_has_events() is_file = isinstance(data, str) and os.path.exists(data) ext = content_type or "wav" if is_file: name = name or os.path.basename(data) ext = get_path_extension(filepath=data) or ext else: name = name or "audio" asset_path = get_asset_path( run_path=self._artifacts_path, kind=V1ArtifactKind.AUDIO, name=name, step=step, ext=ext, ) asset_rel_path = os.path.relpath(asset_path, self._artifacts_path) if is_file: event_value = events_processors.audio_path( from_path=data, asset_path=asset_path, content_type=content_type, asset_rel_path=asset_rel_path, ) else: event_value = events_processors.audio( asset_path=asset_path, tensor=data, sample_rate=sample_rate, asset_rel_path=asset_rel_path, ) if event_value == UNKNOWN: return logged_event = LoggedEventSpec( name=name, kind=V1ArtifactKind.AUDIO, event=V1Event.make(timestamp=timestamp, step=step, audio=event_value), ) self._event_logger.add_event(logged_event)