Skip to content

Commit 4097cbb

Browse files
committed
Extended readme.
1 parent 1eb7986 commit 4097cbb

File tree

2 files changed

+187
-23
lines changed

2 files changed

+187
-23
lines changed

Bindings/Python/Example.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import time
2+
3+
import sral
4+
5+
def sleep_ms(milliseconds):
6+
time.sleep(milliseconds / 1000.0) # Convert milliseconds to seconds
7+
8+
def main():
9+
text = ""
10+
# Initialize the SRAL library
11+
instance = sral.Sral(32)
12+
13+
instance.register_keyboard_hooks()
14+
15+
# Speak some text
16+
if instance.get_engine_features(0) & 128:
17+
text = input("Enter the text you want to be spoken:\n")
18+
instance.speak(text, False)
19+
20+
# Output text to a Braille display
21+
if instance.get_engine_features(0) & 256:
22+
text = input("Enter the text you want to be shown on braille display:\n")
23+
instance.braille(text)
24+
25+
# Delay example
26+
instance.output("Delay example: Enter any text", False)
27+
instance.delay(5000)
28+
instance.output("Press enter to continue", False)
29+
input() # Wait for user to press enter
30+
31+
instance.stop_speech() # Stops the delay thread
32+
33+
# Speech rate
34+
if instance.get_engine_features(0) & 512:
35+
rate = instance.get_rate()
36+
max_rate = rate + 10
37+
for rate in range(rate, max_rate):
38+
instance.set_rate(rate)
39+
instance.speak(text, False)
40+
sleep_ms(500)
41+
42+
# Uninitialize the SRAL library
43+
instance = None
44+
if __name__ == "__main__":
45+
main() # invoke_main()
46+

README.md

Lines changed: 141 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SRAL is a cross-platform library for output text using speech engines.
66
## Platforms
77
SRAL is supported on Windows, MacOS and Linux platforms.
88

9-
9+
## Header
1010

1111
## Enumerations
1212

@@ -142,37 +142,155 @@ The library also provides extended functions to perform operations with specific
142142
### `SRAL_UnregisterKeyboardHooks(void)`
143143
- **Description**: Uninstall speech interruption and pause keyboard hooks.
144144

145+
## Compilation
146+
SRAL can build using CMake into two libraries, static and dynamic.
147+
Run these commands
148+
```
149+
cmake . -B build
150+
cmake --build build --config Release
151+
```
152+
153+
You will also have an executable test to test the SRAL.
154+
155+
156+
# Warning
157+
To build on Linux you need to install libspeechd-dev and libx11-dev
158+
159+
160+
## Usage
161+
162+
To use the SRAL API in a C/C++ project, you need a statically linked or dynamically imported SRAL library, as well as a SRAL.h file with function declarations.
163+
If you use SRAL as a static library for Windows, you need to define SRAL_STATIC in the SRAL.h before the include
164+
```
165+
#define SRAL_STATIC
166+
#include <SRAL.h>
167+
```
168+
169+
## Bindings
170+
SRAL also has Bindings, which is updated with new wrappers for programming languages.
145171

146172
## Example
147-
C
173+
## C
148174
```
175+
#include <stdbool.h>
149176
#include <stdio.h>
177+
#define SRAL_STATIC
150178
#include <SRAL.h>
179+
#include <stdint.h>
180+
#ifdef _WIN32
181+
#include <windows.h>
182+
#else
183+
#include <unistd.h>
184+
#endif
185+
186+
void sleep_ms(int milliseconds) {
187+
#ifdef _WIN32
188+
Sleep(milliseconds); // Windows-specific function
189+
#else
190+
usleep(milliseconds * 1000); // usleep takes microseconds
191+
#endif
192+
}
151193
152194
int main(void) {
153-
// Initialize the SRAL library
154-
if (!SRAL_Initialize(0)) {
155-
printf("Failed to initialize SRAL library.\n");
156-
return 1;
157-
}
158-
159-
// Speak some text
160-
if (!SRAL_Speak("Hello, world!", false)) {
161-
printf("Failed to speak text.\n");
162-
}
163-
164-
// Output text to a Braille display
165-
if (!SRAL_Braille("This is Braille output.")) {
166-
printf("Failed to output to Braille display.\n");
167-
}
168-
169-
// Uninitialize the SRAL library
170-
SRAL_Uninitialize();
171-
172-
return 0;
195+
char text[10000];
196+
// Initialize the SRAL library
197+
if (!SRAL_Initialize(ENGINE_UIA)) { // So Microsoft UIAutomation provider can't speak in the terminal or none current process windows
198+
printf("Failed to initialize SRAL library.\n");
199+
return 1;
200+
}
201+
SRAL_RegisterKeyboardHooks();
202+
// Speak some text
203+
if (SRAL_GetEngineFeatures(0) & SUPPORTS_SPEECH) {
204+
printf("Enter the text you want to be spoken:\n");
205+
scanf("%s", text);
206+
SRAL_Speak(text, false);
207+
}
208+
209+
// Output text to a Braille display
210+
if (SRAL_GetEngineFeatures(0) & SUPPORTS_BRAILLE) {
211+
printf("Enter the text you want to be shown on braille display:\n");
212+
scanf("%s", text);
213+
SRAL_Braille(text);
214+
215+
}
216+
217+
// Delay example
218+
SRAL_Output("Delay example: Enter any text", false);
219+
SRAL_Delay(5000);
220+
SRAL_Output("Press enter to continue", false);
221+
scanf("%s", text);
222+
223+
SRAL_StopSpeech(); // Stops the delay thread
224+
// Speech rate
225+
if (SRAL_GetEngineFeatures(0) & SUPPORTS_SPEECH_RATE) {
226+
227+
uint64_t rate = SRAL_GetRate();
228+
const uint64_t max_rate = rate + 10;
229+
for (rate; rate < max_rate; rate++) {
230+
SRAL_SetRate(rate);
231+
SRAL_Speak(text, false);
232+
sleep_ms(500);
233+
}
234+
}
235+
// Uninitialize the SRAL library
236+
SRAL_Uninitialize();
237+
238+
return 0;
173239
}
174240
175241
```
176242

243+
## Python
244+
```
245+
import time
246+
247+
import sral
248+
249+
def sleep_ms(milliseconds):
250+
time.sleep(milliseconds / 1000.0) # Convert milliseconds to seconds
251+
252+
def main():
253+
text = ""
254+
# Initialize the SRAL library
255+
instance = sral.Sral(32)
256+
257+
instance.register_keyboard_hooks()
258+
259+
# Speak some text
260+
if instance.get_engine_features(0) & 128:
261+
text = input("Enter the text you want to be spoken:\n")
262+
instance.speak(text, False)
263+
264+
# Output text to a Braille display
265+
if instance.get_engine_features(0) & 256:
266+
text = input("Enter the text you want to be shown on braille display:\n")
267+
instance.braille(text)
268+
269+
# Delay example
270+
instance.output("Delay example: Enter any text", False)
271+
instance.delay(5000)
272+
instance.output("Press enter to continue", False)
273+
input() # Wait for user to press enter
274+
275+
instance.stop_speech() # Stops the delay thread
276+
277+
# Speech rate
278+
if instance.get_engine_features(0) & 512:
279+
rate = instance.get_rate()
280+
max_rate = rate + 10
281+
for rate in range(rate, max_rate):
282+
instance.set_rate(rate)
283+
instance.speak(text, False)
284+
sleep_ms(500)
285+
286+
# Uninitialize the SRAL library
287+
instance = None
288+
if __name__ == "__main__":
289+
main() # invoke_main()
290+
291+
```
292+
293+
177294
## Additional info
178-
For [NVDA](https://github.com/nvaccess/nvda) screen reader, you need to download the [Controller Client](https://www.nvaccess.org/files/nvda/releases/stable/) for this.
295+
For [NVDA](https://github.com/nvaccess/nvda) screen reader, you need to download the [Controller Client](https://www.nvaccess.org/files/nvda/releases/stable/). We don't support old client V 1.
296+

0 commit comments

Comments
 (0)