Optional ducking of other audio
Reported by jteh on 2014-01-31 01:54 Windows 8 allows us to request that other audio be ducked. This means we can duck the volume of other audio while NVDA is speaking. This should be optional, as it isn't always desirable. Also, I wonder whether it might be useful to have a command to duck audio even if this option is disabled for times when unexpected loud audio clobbers speech.
See the audioDuckingPrototype branch.
Comment 1 by k_kolev1985 on 2014-03-16 18:38 Hi Jamie,
I want to ask a question about the volume ducking feature. Will it duck the volume constantly when NVDA is running, or it will duck it only when NVDA is speaking? I'm asking, because Narrator ducks it constantly, witch is not an ideal solution.
Comment 2 by mdcurran on 2014-03-25 00:35 Our prototype ducks only when NVDA is speaking. However, as the fade time that Windows uses when starting to duck is a bit slower than we'd like, we have to slightly delay the start of speech otherwise NVDA will start speaking while the background audio is still at full volume.
Comment 3 by zahari_bgr on 2014-03-25 01:39 Hi, It will be a very nice feature. Is it possible to detect whether there is actual background audio currently playing? Cause a constant delay in speech will not be nice. It will be useful if toggling of this option could be bound to an input gesture. Also, what about Windows 7?
Comment 4 by mdcurran on 2014-03-25 03:16 We only plan to support Windows 8 at this point in time as the Operating System has the support already built in. We have no way of detecting whether there is background audio or not, therefore we probably will have a guesture to toggle it on and off.
Comment 5 by mdcurran on 2014-12-02 02:56 A prototype of this stupport can be found in branch t3830
Comment 6 by mdcurran on 2014-12-03 07:27 A try build, now supporting no ducking, ducking for NVDA speech and sounds, and ducking always, (NVDA+shift+d and combobox in synth dialog) can be found at: http://community.nvda-project.org/try/t3830/nvda_snapshot_try-t3830-10573,7f8c9e1.exe
Comment 7 by leonarddr on 2015-04-24 20:40 Is there any idea of when this work could find its way to next? I tried the functionality from source on windows 8.1, but am getting the message 'ducking not supported'
Comment 8 by mdcurran on 2015-04-26 18:56 This functionality can only work for installed copies due to Windows security. I think there were still some race conditions where audio would accidentially remain ducked. I'll take another look soon.
Comment 9 by camlorn on 2015-05-18 19:33 This is almost certainly blocked by #5096 as, if we move NVWave to C/C++, we'll need to redo some of this there.
Comment 10 by jteh on 2015-10-28 00:36 We need to make sure this cooperates with prevention of our audio being ducked by other audio (#5443).
Incubated in ca7e036c4e66390977b257e2551914854f4e5076.
It seems that ducking and configuration profiles don't like each other.
To reproduce, enable ducking in a configuration profile with a trigger and disable it in the default configuration. When switching to the application with the ducking enable profile, ducking isn't enabled as expected.
@michaelDCurran: You need to switch ducking modes when config profiles are switched. Introduce a handleConfigProfileSwitch function in nvwave and call it from config.ConfigManager._handleProfileSwitch (config/init.py around line 510).
I want to report a bug with the current (available in the "next" snapshots) implementation of the audio ducking feature. It seams not to work with SAPI5. I've tried with 2 bulgarian voices and with Microsoft Zira voice, but it did not work. The option is set to "Duck when outputting speech and sounds". If the option is set to "Always duck", the feature works as expected. Is this a limitation with SAPI5 or a bug in the current implementation of the audio ducking feature? It works with other TTS engines like "Speech Player" and "RHVoice" (the older one - I don't like the newer one very much) witch are as add-ons for NVDA.
Test environment:
- Operating system: Windows 10 Pro (build 10586.11), 64-bit, in Bulgarian with all locale settings set to "Bulgarian".
- NVDA version: next-12831,b1f00f4.
- Processor: Intel Core i5-2320 at 3.00GHz.
- RAM Memory: 4.00 GB.
- Sound Card: Realtek ALC662 at Intel Cougar Point PCH - High Definition Audio Controller.
This isn't currently possible because SAPI 5 handles its own audio output; it doesn't use NVDA code to do this. It should be possible for us to fix this with some rewriting of the SAPI 5 driver, but we don't plan to do this for the initial implementation of ducking.
Incubated in 071a65396b68bafade119e81e48b4d779d1a564a.
Incubated in fe9c9397949da33b2f7665ac172d6ca4fe92fd3b.
Incubated in 9fa91c2f07da195bc08992fd94d5b8bf6695be9a.
I think it'd be really good if we can not delay the audio if there isn't audio playing (or better still, if audio is quiet). So, I've been looking into this a bit.
It seems there are two APIs you can use to get the peak levels for an audio device:
- The Windows Core Audio APIs in Vista and later. These are COM based. Basically, you start with IMMDeviceEnumerator, get an IMMDevice and call IMMDevice::Activate and request IAudioMeterInformation.
- Unfortunately, as nice as being COM based sounds, calling CoCreateInstance for IMMDeviceEnumerator results in class not registered for some reason. mmdevapi.dll doesn't seem to have a typelib, so I tried generating one from mmdeviceapi.idl. When I tried to use that with comtypes, it threw a weird assertion error.
- This StackOverflow thread shows it's possible to use this API with comtypes, but the interfaces would all have to be written out.
- The old Audio Mixer API from winmm. This article provides details about how this could be used to get peak levels.
- Unfortunately, there would be a hell of a lot of structs to write out if we wanted to do this in Python.
Of course, I guess we could write the code in C++ and avoid the Python porting bit. After all, all we want is one damned value.
However, the above should perhaps be done separately, as it looks like it's pretty complicated to implement and it is nice-to-have rather than essential. Thoughts, @MichaelDCurran?