Elements
Audio
The Audio
class allows you to display an audio player for a specific audio file in the chatbot user interface.
You must provide either an url or a path or content bytes.
Attributes
name
str
The name of the audio file to be displayed in the UI. This is shown to users.
display
ElementDisplay
Determines where the element should be displayed in the UI. Choices are “side” (default), “inline”, or “page”.
url
str
The remote URL of the audio.
path
str
The local file path of the audio.
content
bytes
The file content of the audio in bytes format.
Usage with message scope
Code Example
import chainlit as cl
@cl.on_chat_start
async def main():
elements = [
cl.Audio(name="example.mp3", path="./example.mp3", display="inline"),
]
await cl.Message(
content="Here is an audio file",
elements=elements,
).send()
Usage without scope
Code Example
import chainlit as cl
@cl.on_chat_start
async def main():
await cl.Audio(name="example.mp3", path="./example.mp3", display="side").send()
await cl.Message(
content="Here is the example.mp3 audio file",
).send()
Was this page helpful?