session.audio.playAudio(). Stream sound effects, music, or pre-recorded messages to the user’s device.
Basic Usage
How It Works
- Provide a URL to an audio file
- MentraOS downloads and streams the file
- Audio plays through glasses speakers or phone
- 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:Best Practices
Use CDN for Audio Files
Use CDN for Audio Files
Host audio on a CDN for fast, reliable access:
Keep Files Small
Keep Files Small
Smaller files = faster loading = better UX:
Handle Failures Gracefully
Handle Failures Gracefully
Always check the result:
Provide Visual Feedback
Provide Visual Feedback
Combine audio with visual cues:
Audio Routing
Audio automatically routes to the best available output:- Glasses with speakers → Plays on glasses
- Glasses without speakers → Plays on phone
- 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
Pre-load Common Sounds
Pre-load Common Sounds
Cache frequently used audio:
Optimize File Size
Optimize File Size
Use appropriate bitrate and format:
- Sound effects: 128kbps MP3
- Voice: 64-96kbps MP3
- Music: 192-256kbps MP3
Use Short Durations
Use Short Durations
Keep audio brief for better UX:
Return Value
Troubleshooting
Audio Not Playing
Audio Not Playing
Check URL accessibility:
Playback Errors
Playback Errors
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
Volume Too Low
Volume Too Low
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

