|
5 | 5 | # Copyright (C) 2006-2024 NV Access Limited, Peter Vágner, Aleksey Sadovoy, Rui Batista, Joseph Lee, |
6 | 6 | # Leonard de Ruijter, Derek Riemer, Babbage B.V., Davy Kager, Ethan Holliger, Łukasz Golonka, Accessolutions, |
7 | 7 | # Julien Cochuyt, Jakub Lukowicz, Bill Dengler, Cyrille Bougot, Rob Meredith, Luke Davis, |
8 | | -# Burman's Computer and Education Ltd. |
| 8 | +# Burman's Computer and Education Ltd, Beka Gozalishvili. |
9 | 9 |
|
10 | 10 | import itertools |
11 | 11 | from typing import ( |
|
58 | 58 | import braille |
59 | 59 | import brailleInput |
60 | 60 | import inputCore |
| 61 | +import nvwave |
61 | 62 | import characterProcessing |
62 | 63 | from baseObject import ScriptableObject |
63 | 64 | import core |
@@ -4443,6 +4444,43 @@ def script_cycleParagraphStyle(self, gesture: "inputCore.InputGesture") -> None: |
4443 | 4444 | config.conf["documentNavigation"]["paragraphStyle"] = newFlag.name |
4444 | 4445 | ui.message(newFlag.displayString) |
4445 | 4446 |
|
| 4447 | + @staticmethod |
| 4448 | + def _cycleOutputAudioDevices(forward: bool = True): |
| 4449 | + """Cycle through available output devices. |
| 4450 | + @param forward: boolean flag if false cycles in backward direction. |
| 4451 | + """ |
| 4452 | + deviceNames = nvwave.getFriendlyOutputDeviceNames() |
| 4453 | + currentIndex = 0 |
| 4454 | + currentOutputDevice = config.conf["speech"]["outputDevice"] |
| 4455 | + if currentOutputDevice in deviceNames: |
| 4456 | + currentIndex = deviceNames.index(currentOutputDevice) |
| 4457 | + direction = 1 if forward else -1 |
| 4458 | + newIndex = (currentIndex + direction) % len(deviceNames) |
| 4459 | + device = deviceNames[newIndex] |
| 4460 | + if not nvwave.setOutputDevice(device): |
| 4461 | + return ui.message(_("Failed to set {device} as an output audio device").format(device=device)) |
| 4462 | + ui.message(device) |
| 4463 | + |
| 4464 | + @script( |
| 4465 | + description=_( |
| 4466 | + # Translators: Describes the switch to next output device command. |
| 4467 | + "switches to the next output device" |
| 4468 | + ), |
| 4469 | + category=SCRCAT_SPEECH, |
| 4470 | + ) |
| 4471 | + def script_switchToNextOutputDevice(self, gesture: inputCore.InputGesture) -> None: |
| 4472 | + self._cycleOutputAudioDevices() |
| 4473 | + |
| 4474 | + @script( |
| 4475 | + description=_( |
| 4476 | + # Translators: Describes the switch to previous output device command. |
| 4477 | + "switches to the previous output device" |
| 4478 | + ), |
| 4479 | + category=SCRCAT_SPEECH, |
| 4480 | + ) |
| 4481 | + def script_switchToPreviousOutputDevice(self, gesture: inputCore.InputGesture) -> None: |
| 4482 | + self._cycleOutputAudioDevices(-False) |
| 4483 | + |
4446 | 4484 |
|
4447 | 4485 | #: The single global commands instance. |
4448 | 4486 | #: @type: L{GlobalCommands} |
|
0 commit comments