Audio#

class alfred3.element.display.Audio(path: Optional[Union[str, pathlib.Path]] = None, url: Optional[str] = None, controls: bool = True, autoplay: bool = False, loop: bool = False, align: str = 'center', **kwargs)[source]#

Bases: alfred3.element.display.Image

Allows playing audio files.

Parameters
  • path – Path to the audio file. Can be relative to the experiment directory, or absolute.

  • url – URL to the audio file.

  • controls – If True, alfred will display controls like a pause/ play button for participants to use (default: True).

  • autoplay – If True, the audio file will start to play automatically (default: False).

  • loop – If True, the audio file will start playing from the beginning again, once the end is reached (default: False).

  • **kwargs

    Inherited keyword arguments

    align

    Horizontal alignment of text in the element. Does not usually apply to labels. Think of it as an alignment that applies to the innermost layer of an element (while labels are generally located at outer layers). See LabelledElement for more on labelled elements. Can be left (default), center, right, or justify.

    font_size

    Font size for text in the element. You can use a keyword or an exact specification. The available keywords are tiny, small, normal, big, and huge. The exact specification shoul ideally include a unit, such as 1rem, or 12pt. If you supply an integer without a unit, a unit of pt will be assumed. Defaults to normal.

    height

    Vertical height of the elements display area. Supply a string with a unit, e.g. 80px. Usually, the default is fine. For adding vertical space to a page, you should prefer the VerticalSpace element, as it is sematically more clear.

    instance_log

    If True, the element will use an instance-specific logger, thereby allowing detailed fine- tuning of its logging behavior.

    layout

    Can be one of the following: 1) An instance of RowLayout, or 2) a tuple of integers, specifying the allocation of horizontal space between leftlab, main element widget and rightlab on small screens upwards. Option 1) offers fine-tuned flexibility, 2) uses a default RowLayout and changes the RowLayout.width_sm attribute. By default, the layout is set automatically depending on the specification of the left and right labels.

    name

    Name of the element. This should be a unique identifier. It will be used to identify the corresponding data in the final data set.

    position

    Horizontal position of the full element on the page. Values can be left, center (default), end, or any valid value for the justify-content flexbox utility. Takes effect only, when the element is not full-width.

    showif

    A dictionary, defining conditions that must be met for the element to be shown. The conditions take the form of key-value pairs, where each key is an element name and the value is the required input. See showif for details.

    toplab, bottomlab, leftlab, rightlab

    Labels above, below, left and right of the element.

    width

    Defines the horizontal width of the element from small screens upwards. It is always full-width on extra small screens. Possible values are narrow, medium, wide, and full. For more detailed control, you can define the element_width attribute.

Notes

You can specify either a path, or a url, but not both.

Examples

Minimal example:

import alfred3 as al
exp = al.Experiment()

@exp.member
class Demo(al.Page):
    name = "demo1"

    def on_exp_access(self):
        demo_audio = "https://file-examples-com.github.io/uploads/2017/11/file_example_MP3_1MG.mp3"

        self += al.Audio(url=demo_audio)

Methods

add_css

Adds CSS to the element.

add_js

Adds Javascript to the element.

added_to_experiment

The image is added to the dict of static files, if a path is provided.

added_to_page

Tells the element that it was added to a page.

prepare_web_widget

Hook for computations for preparing an element's web widget.

render_inner_html

Renders the element template element_template.

Attributes

base_template

Base template for the element, which will be used to hold the rendered element template.

bottomlab

Label below of the main element widget.

converted_width

List of bootstrap column widths at different screen sizes.

css_class_container

Returns the name the element container's CSS class.

css_class_element

Returns the name of the element's CSS class.

css_code

A list of tuples, which contain a priority and CSS code.

css_urls

A list of tuples, which contain a priority and an url pointing to CSS code.

display_standalone

If True (default), the element will be displayed as usual on its own.

element_template

The element's specific, inner template.

element_width

Returns a string of column width definitions.

exp

The experiment session to which this element belongs.

experiment

Alias for exp

font_size

Font size

js_code

A list of tuples, which contain a priority and Javascript.

js_urls

A list of tuples, which contain a priority and an url pointing to JavaScript.

labels

Returns the labels in a single, nicely formatted string.

layout

Controls the allocation of horizontal space between the left and right label, as well as the main element.

leftlab

Label to the left of the main element widget.

name

Unique identifier for the element.

page

The page to which this element belongs.

position

Position of the whole element on the page.

rightlab

Label to the right of the main element widget.

section

The direct parent section of this element's page.

short_tree

String, giving the exact position in the experiment.

should_be_shown

Boolean, indicating whether the element is meant to be shown.

showif

Conditions that have to be met for the element to be shown.

template_data

Dictionary of data to be passed on to jinja templates.

toplab

Label above of the main element widget.

tree

String, giving the exact position in the experiment.

web_widget

The element's rendered html code for display on a page.

width

Element width