Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show example video as video instead of audio #104

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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