Skip to main content
The Audio component allows users to upload, record, or play audio files.

Basic usage

import gradio as gr

def reverse_audio(audio):
    sr, data = audio
    return (sr, data[::-1])

gr.Interface(
    fn=reverse_audio,
    inputs=gr.Audio(),
    outputs=gr.Audio()
).launch()

Constructor

value
str | Path | tuple[int, np.ndarray] | Callable | None
default:"None"
Default audio as filepath, URL, or (sample_rate, numpy array) tuple
sources
list[Literal['upload', 'microphone']] | None
default:"None"
Input sources:
  • "upload" - File upload
  • "microphone" - Microphone recording
Defaults to both if not streaming
type
Literal['numpy', 'filepath']
default:"'numpy'"
Format passed to function:
  • "numpy" - Tuple of (sample_rate, data)
  • "filepath" - String path to temporary file
format
Literal['wav', 'mp3'] | None
default:"None"
Audio file format. If None, no conversion is done
streaming
bool
default:"False"
If True, automatically streams from microphone in live interfaces
autoplay
bool
default:"False"
Whether to automatically play audio when displayed as output
loop
bool
default:"False"
Whether audio loops when it reaches the end
editable
bool
default:"True"
Whether users can edit the audio waveform

Events

  • change - Triggered when audio changes
  • upload - Triggered when audio is uploaded
  • clear - Triggered when audio is cleared
  • play - Triggered when playback starts
  • pause - Triggered when playback pauses
  • stop - Triggered when playback stops
  • stream - Triggered during streaming
  • start_recording - Triggered when recording starts
  • pause_recording - Triggered when recording pauses
  • stop_recording - Triggered when recording stops

Examples

Microphone only

import gradio as gr

gr.Audio(
    sources=["microphone"],
    label="Record your voice"
)

MP3 format

import gradio as gr

gr.Audio(
    format="mp3",
    label="Audio in MP3 format"
)