Skip to main content
Play audio files from URLs using session.audio.playAudio(). Stream sound effects, music, or pre-recorded messages to the user’s device.

Basic Usage

How It Works

  1. Provide a URL to an audio file
  2. MentraOS downloads and streams the file
  3. Audio plays through glasses speakers or phone
  4. Promise resolves when playback completes

Supported Formats

  • MP3 - Most common, recommended
  • WAV - Uncompressed, larger files
  • OGG - Open format, good compression
  • M4A - Apple format
MP3 format is recommended for best compatibility and file size.

Audio Options

Volume Control

Stop Other Audio

Options Reference

Common Patterns

Sound Effects

Notification Sounds

Background Music

Error Handling

Sequential Audio

Conditional Audio

Stopping Audio

Stop all currently playing audio:
Stop before playing new audio:

Best Practices

Host audio on a CDN for fast, reliable access:
Smaller files = faster loading = better UX:
Always check the result:
Combine audio with visual cues:

Audio Routing

Audio automatically routes to the best available output:
  1. Glasses with speakers → Plays on glasses
  2. Glasses without speakers → Plays on phone
  3. Phone Bluetooth → Respects phone audio routing
Users can connect glasses to their phone via Bluetooth like regular headphones to route all audio through glasses speakers.

Performance Tips

Cache frequently used audio:
Use appropriate bitrate and format:
  • Sound effects: 128kbps MP3
  • Voice: 64-96kbps MP3
  • Music: 192-256kbps MP3
Keep audio brief for better UX:

Return Value

Example:

Troubleshooting

Check URL accessibility:
Common issues:
  • CORS errors: Ensure CDN allows cross-origin requests
  • File format: Use MP3 for best compatibility
  • File size: Large files may timeout (60s limit)
  • URL access: Must be publicly accessible
Adjust volume:

Example: Sound Library

Next Steps

Text-to-Speech

Generate speech from text

Speech-to-Text

Capture user voice input

Audio Manager

Complete audio API reference

Device Control

All device control features