Skip to content

Feature: Audio Device Selection#2826

Merged
Tkael merged 1 commit into
EDCD:developfrom
Tiberius-Sicae:feature/audio-device-selection
Jun 6, 2026
Merged

Feature: Audio Device Selection#2826
Tkael merged 1 commit into
EDCD:developfrom
Tiberius-Sicae:feature/audio-device-selection

Conversation

@Tiberius-Sicae
Copy link
Copy Markdown
Contributor

Pull Request: Audio Device Selection for Text-to-Speech & Audio Output

Summary

This PR adds the ability for users to select a specific audio playback device for all speech and audio generated by EDDI, rather than always outputting to the default Windows audio device.

The selected device configuration persists across sessions. If the configured device becomes unavailable (e.g., unplugged), the app automatically and gracefully falls back to the system's "Default Device" and saves that update.

Additionally, this PR features a zero-overhead window message listener to automatically refresh available audio devices and update selection when hardware is plugged in or unplugged in real-time.


Detailed Changes

1. Configuration Storage & Logic

  • ConfigService/Configurations/SpeechServiceConfiguration.cs:
    • Added AudioDevice property (serialised as audioDevice in speech.json) to persist the chosen device ID.
    • Reset AudioDevice to null on Clear().

2. Audio Device Enumeration & Playback Routing

  • SpeechService/AudioDevice.cs:
    • Added AudioDevice representation class.
    • Created AudioDeviceService with a static method GetAudioDevices() to query active audio endpoints using NAudio.
  • SpeechService/SoundManager.cs:
    • Updated GetSoundOut(IWaveProvider provider) to check speechServiceConfiguration.AudioDevice.
    • If a specific device ID is configured, resolves it to an MMDevice and instantiates WasapiOut(device, ...).
    • Implemented robust exception handling to fall back to the default new WasapiOut() if the device is not found or fails to initialise.

3. User Interface, Localisation & Real-time Tracking

  • EddiUI/Properties/Resources.resx & Resources.Designer.cs:
    • Added localised label tab_tts_audio_device_label ("Audio device:").
  • EddiUI/TextToSpeechTab.xaml:
    • Added a row to the grid layout and inserted the "Audio device" dropdown combobox above the "Voice" dropdown.
  • EddiUI/TextToSpeechTab.xaml.cs:
    • Populates the audio device combobox with available devices plus a "Default Device" placeholder.
    • Checks if the configured device is available in the options. If missing/unplugged, sets selection to "Default Device" and clears the configured ID permanently.
    • Registered a WM_DEVICECHANGE (0x0219) native message hook on Loaded (removed on Unloaded) to catch system hardware changes. This allows the dropdown list and selection to refresh dynamically in real-time without background polling overhead.

4. Build System Fix

  • BuildInstaller/BuildInstaller.csproj:
    • Wrapped the $(SolutionDir) path in double-quotes inside the PostBuildEvent batch command invocation. This fixes a build failure that occurred when the project was located in a path containing spaces.

@Tkael Tkael self-assigned this Jun 6, 2026
@Tkael Tkael force-pushed the feature/audio-device-selection branch from 8ff2acd to 8a1fb2b Compare June 6, 2026 21:03
@Tkael
Copy link
Copy Markdown
Member

Tkael commented Jun 6, 2026

This works equally well for both speech and audio clips. I'll convert the hardcoded "Default Device" string into a localizable resource and then merge. o7

@Tkael Tkael merged commit 8a1fb2b into EDCD:develop Jun 6, 2026
@Tkael Tkael added the 8. annoyance The behaviour is as specified, but has been found to be annoying in practice by real-world users. label Jun 6, 2026
@Tkael Tkael linked an issue Jun 6, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8. annoyance The behaviour is as specified, but has been found to be annoying in practice by real-world users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to select Audio Device

2 participants