-
-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Hi, thanks for this, it's great.
I ran into an issue with the application failing to work correctly on first launch and crashing on second.
I believe the issue is related to cpal trying to use the legacy "oss" sound system, or something to that effect.
Below is a linux only fix (forcing ALSA) if useful, and an LLM description of the issue.
--
Bug Description
CPAL incorrectly selects OSS audio backend instead of ALSA on Linux, causing audio initialization failure
When running Handy on Linux (EndeavourOS/Arch), the application fails to initialize audio properly because CPAL's default_host()
function selects the OSS (Open Sound System) backend instead of the more modern ALSA backend. This results in the error:
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
The issue occurs because:
- CPAL auto-detects available audio hosts on system startup
- OSS compatibility layers may be present on the system (even if not actively used)
- CPAL's host selection algorithm chooses OSS over ALSA in some configurations
- OSS tries to access
/dev/dsp
which either doesn't exist or isn't properly configured - This causes all audio recording/playback functionality to fail
Steps to Reproduce
- Install Handy on a Linux system with both ALSA and OSS compatibility present
- Launch the application
- Attempt to use any audio recording functionality
- Observe the error messages in console output
Expected Behavior
CPAL should prioritize ALSA as the default audio backend on modern Linux systems, or provide better fallback mechanisms when the selected backend fails to initialize.
Actual Behavior
CPAL selects OSS backend, attempts to open /dev/dsp
, fails with "Cannot open device" error, and audio functionality becomes unavailable.
System Information
App Version: 0.5.0
Operating System: EndeavourOS (Arch Linux) with kernel 6.5.6-arch2-1-g14
CPU: AMD Ryzen 7 5800HS with Radeon Graphics
GPU:
- NVIDIA GeForce RTX 3060 Mobile / Max-Q
- AMD Radeon Vega Series (integrated)
Audio System:
- ALSA version: System default
- CPAL version: 0.16.0
- OSS compatibility: Present but not actively used
Workaround (Linux only)
The issue can be resolved by explicitly forcing CPAL to use the ALSA backend instead of relying on auto-detection:
// Replace:
let host = cpal::default_host();
// With:
let host = cpal::host_from_id(cpal::HostId::Alsa)
.map_err(|e| anyhow::anyhow!("Failed to create ALSA host: {}", e))?;
This change needs to be applied in multiple files:
src-tauri/src/audio_toolkit/audio/recorder.rs:65
src-tauri/src/audio_toolkit/audio/device.rs:11,33
src-tauri/src/audio_feedback.rs:70
Suggested Fix (Linux only)
- For Handy: Implement explicit ALSA backend selection on Linux instead of relying on CPAL's auto-detection
- For CPAL: Improve host selection algorithm to prefer ALSA over OSS on modern Linux systems
- For Handy: Add better error handling and fallback mechanisms when audio initialization fails
Additional Context
This issue affects Linux users who have OSS compatibility layers installed (common on Arch-based distributions) but primarily use ALSA. The problem is particularly confusing because:
- ALSA is working fine system-wide
- Other audio applications work correctly
- The error message points to OSS (
/dev/dsp
) rather than indicating a backend selection issue - The actual cause (CPAL backend selection) is not immediately obvious from the error
Error Logs
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
This error indicates that CPAL selected the OSS backend and is trying to access the legacy OSS device file /dev/dsp
.