Skip to content

Commit

Permalink
Show example video as video instead of audio (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw authored Jul 26, 2024
1 parent 84b909f commit 236d087
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions audbcards/core/datacard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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' <p><audio controls src="{player_src}"></audio></p>'
f' <p><{media_tag} controls src="{player_src}"></{media_tag}></p>'
)

return player_str
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 236d087

Please sign in to comment.