Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix audio output device selection #17532

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions source/nvwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)
from enum import Enum, auto
from ctypes import (
POINTER,
Structure,
c_uint,
byref,
Expand Down Expand Up @@ -76,17 +75,7 @@ class WAVEFORMATEX(Structure):
]


LPWAVEFORMATEX = POINTER(WAVEFORMATEX)


WAVE_FORMAT_PCM = 1
WAVE_MAPPER = -1

CALLBACK_NULL = 0
# CALLBACK_FUNCTION = 0x30000
CALLBACK_EVENT = 0x50000
# waveOutProc = CFUNCTYPE(HANDLE, UINT, DWORD, DWORD, DWORD)
# WOM_DONE = 0x3bd
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved


def _isDebugForNvWave():
Expand Down Expand Up @@ -258,7 +247,7 @@ class WasapiWavePlayer(garbageHandler.TrackedObject):
#: Whether there is a pending stream idle check.
_isIdleCheckPending: bool = False
#: Use the default device, this is the configSpec default value.
DEFAULT_DEVICE_KEY = "default"
DEFAULT_DEVICE_KEY = typing.cast(str, config.conf.getConfigValidation(("speech", "outputDevice")).default)
#: The silence output device, None if not initialized.
_silenceDevice: typing.Optional[str] = None

Expand All @@ -267,21 +256,16 @@ def __init__(
channels: int,
samplesPerSec: int,
bitsPerSample: int,
outputDevice: typing.Union[str, int] = WAVE_MAPPER,
closeWhenIdle: bool = False,
outputDevice: str = DEFAULT_DEVICE_KEY,
wantDucking: bool = True,
buffered: bool = False,
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved
purpose: AudioPurpose = AudioPurpose.SPEECH,
):
"""Constructor.
@param channels: The number of channels of audio; e.g. 2 for stereo, 1 for mono.
@param samplesPerSec: Samples per second (hz).
@param bitsPerSample: The number of bits per sample.
@param outputDevice: The name of the audio output device to use,
WAVE_MAPPER for default.
@param closeWhenIdle: Deprecated; ignored.
@param outputDevice: The name of the audio output device to use, defaults to WasapiWavePlayer.DEFAULT_DEVICE_KEY
@param wantDucking: if true then background audio will be ducked on Windows 8 and higher
@param buffered: Whether to buffer small chunks of audio to prevent audio glitches.
@param purpose: The purpose of this audio.
@note: If C{outputDevice} is a name and no such device exists, the default device will be used.
@raise WindowsError: If there was an error opening the audio output device.
Expand All @@ -303,7 +287,7 @@ def __init__(
if audioDucking.isAudioDuckingSupported():
self._audioDucker = audioDucking.AudioDucker()
self._purpose = purpose
if self._isDefaultDevice(outputDevice):
if outputDevice == self.DEFAULT_DEVICE_KEY:
outputDevice = ""
self._player = NVDAHelper.localLib.wasPlay_create(
outputDevice,
Expand Down Expand Up @@ -557,13 +541,6 @@ def _idleCheck(cls):
# Schedule another check here in case feed isn't called for a while.
cls._scheduleIdleCheck()

@classmethod
def _isDefaultDevice(cls, name):
if name in (WAVE_MAPPER, cls.DEFAULT_DEVICE_KEY):
return True
# Check if this is the WinMM sound mapper device, which means default.
return name == next(_getOutputDevices())[1]


WavePlayer = WasapiWavePlayer
fileWavePlayer: Optional[WavePlayer] = None
Expand Down
1 change: 0 additions & 1 deletion source/synthDrivers/_espeak.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ def initialize(indexCallback=None):
samplesPerSec=sampleRate,
bitsPerSample=16,
outputDevice=config.conf["speech"]["outputDevice"],
buffered=True,
)
onIndexReached = indexCallback
espeakDLL.espeak_SetSynthCallback(callback)
Expand Down