diff --git a/audbcards/core/datacard.py b/audbcards/core/datacard.py index 52e2001..8fa6685 100644 --- a/audbcards/core/datacard.py +++ b/audbcards/core/datacard.py @@ -33,7 +33,7 @@ class Datacard(object): path: path to folder that store datacard files example: if ``True``, - include an audio example in the data card + include an audio or video example in the data card showing the waveform of the audio and an interactive player sphinx_build_dir: build dir of sphinx. @@ -173,7 +173,7 @@ def file_duration_distribution(self) -> str: return distribution_str def player(self) -> str: - r"""Create an audio player showing the waveform. + r"""Create an audio/video player showing the waveform. If :attr:`audbcards.Datacard.sphinx_build_dir` or :attr:`audbcards.Datacard.sphinx_src_dir` @@ -308,12 +308,15 @@ def plot_waveform_to_cache(cache_example_media: str) -> str: cache_example_media, os.path.join(media_dst_dir, self.dataset.example_media), ) - + if audiofile.has_video(cache_example_media): + media_tag = "video" + else: + media_tag = "audio" player_src = f"./{self.dataset.name}/{self.dataset.example_media}" player_str += ( ".. raw:: html\n" "\n" - f'
' + f'<{media_tag} controls src="{player_src}">{media_tag}>
' ) return player_str diff --git a/pyproject.toml b/pyproject.toml index 688dafe..839ef80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,6 +35,7 @@ requires-python = '>=3.9' dependencies = [ 'audb >=1.7.0', 'audeer >=2.2.0', + 'audiofile >=1.5.0', 'audplot >=1.4.6', 'jinja2', 'pandas >=2.1.0',