-
-
Notifications
You must be signed in to change notification settings - Fork 650
/
example_python.py
51 lines (43 loc) · 1.71 KB
/
example_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2006-2023 NV Access Limited, Łukasz Golonka, Leonard de Ruijter
# This file is covered by the GNU Lesser General Public License, version 2.1.
# See the file license.txt for more details.
import ctypes
import time
# Load the NVDA client library
clientLib = ctypes.windll.LoadLibrary("./nvdaControllerClient.dll")
# Test if NVDA is running, and if its not show a message
res = clientLib.nvdaController_testIfRunning()
if res != 0:
errorMessage = str(ctypes.WinError(res))
ctypes.windll.user32.MessageBoxW(0, f"Error: {errorMessage}", "Error communicating with NVDA", 0)
# Speak and braille some messages
for count in range(4):
clientLib.nvdaController_speakText("This is a test client for NVDA")
clientLib.nvdaController_brailleMessage("Time: %g seconds" % (0.75 * count))
time.sleep(0.625)
clientLib.nvdaController_cancelSpeech()
# Test SSML output
@ctypes.WINFUNCTYPE(ctypes.c_ulong, ctypes.c_wchar_p)
def onMarkReached(name: str) -> int:
print(f"Reached SSML mark with name: {name}")
return 0
ssml = (
"<speak>"
"This is one sentence. "
'<mark name="test" />'
'<prosody pitch="200%">This sentence is pronounced with higher pitch.</prosody>'
'<mark name="test2" />'
"This is a third sentence. "
'<mark name="test3" />'
"This is a fourth sentence. We will stay silent for a second after this one."
'<break time="1000ms" />'
'<mark name="test4" />'
"This is a fifth sentence. "
'<mark name="test5" />'
"</speak>"
)
clientLib.nvdaController_setOnSsmlMarkReachedCallback(onMarkReached)
clientLib.nvdaController_speakSsml(ssml, -1, 0, False)
clientLib.nvdaController_setOnSsmlMarkReachedCallback(None)
clientLib.nvdaController_brailleMessage("Test completed!")