Skip to content

(audio): Add SampleRate parameter to AudioRecorder #2323

@rorychatt

Description

@rorychatt

Description

Add SampleRate parameter to AudioRecorder

Summary

The AudioRecorder widget currently has no way to control the audio sample rate. Streamlit's st.audio_input supports a sample_rate parameter that lets developers target a specific sample rate in Hz, which is useful for optimizing audio quality vs. file size depending on the use case.

Motivation

Different use cases require different audio fidelity:

  • Speech recognition / voice commands: 16,000 Hz is standard and keeps file sizes small
  • Voice messages / podcasts: 22,050–24,000 Hz offers a good balance
  • Music / high-fidelity recording: 44,100 or 48,000 Hz is expected

Without this parameter, developers have no control over recording quality and must accept whatever the browser defaults to, or post-process the audio server-side.

Proposal

Add a SampleRate property to AudioRecorder:

[Prop] public int? SampleRate { get; set; }

With a corresponding fluent extension method:

public static AudioRecorder SampleRate(this AudioRecorder widget, int? sampleRate)
{
    return widget with { SampleRate = sampleRate };
}

Accepted values

Following Streamlit's supported set: 8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000, or null (browser default).

When null, the browser picks its native sample rate (typically 48,000 Hz).

Usage

// Optimized for speech recognition
new AudioRecorder(upload, "Record voice", sampleRate: 16000)

// High-fidelity recording
new AudioRecorder(upload, "Record audio", sampleRate: 48000)

// Fluent API
new AudioRecorder(upload, "Record").SampleRate(16000)

References

  • Streamlit st.audio_input sample_rate parameter

Other

Also: Rename AudioRecorder to AudioInput.

Use Case

No response

Proposed Solution

No response

Alternatives Considered

No response

Impact

No response

Code Examples

Additional Context

No response

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions