Skip to content

Commit

Permalink
Extended readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1maker committed Sep 7, 2024
1 parent 1eb7986 commit 4097cbb
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 23 deletions.
46 changes: 46 additions & 0 deletions Bindings/Python/Example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import time

import sral

def sleep_ms(milliseconds):
time.sleep(milliseconds / 1000.0) # Convert milliseconds to seconds

def main():
text = ""
# Initialize the SRAL library
instance = sral.Sral(32)

instance.register_keyboard_hooks()

# Speak some text
if instance.get_engine_features(0) & 128:
text = input("Enter the text you want to be spoken:\n")
instance.speak(text, False)

# Output text to a Braille display
if instance.get_engine_features(0) & 256:
text = input("Enter the text you want to be shown on braille display:\n")
instance.braille(text)

# Delay example
instance.output("Delay example: Enter any text", False)
instance.delay(5000)
instance.output("Press enter to continue", False)
input() # Wait for user to press enter

instance.stop_speech() # Stops the delay thread

# Speech rate
if instance.get_engine_features(0) & 512:
rate = instance.get_rate()
max_rate = rate + 10
for rate in range(rate, max_rate):
instance.set_rate(rate)
instance.speak(text, False)
sleep_ms(500)

# Uninitialize the SRAL library
instance = None
if __name__ == "__main__":
main() # invoke_main()

164 changes: 141 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SRAL is a cross-platform library for output text using speech engines.
## Platforms
SRAL is supported on Windows, MacOS and Linux platforms.


## Header

## Enumerations

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

## Compilation
SRAL can build using CMake into two libraries, static and dynamic.
Run these commands
```
cmake . -B build
cmake --build build --config Release
```

You will also have an executable test to test the SRAL.


# Warning
To build on Linux you need to install libspeechd-dev and libx11-dev


## Usage

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.
If you use SRAL as a static library for Windows, you need to define SRAL_STATIC in the SRAL.h before the include
```
#define SRAL_STATIC
#include <SRAL.h>
```

## Bindings
SRAL also has Bindings, which is updated with new wrappers for programming languages.

## Example
C
## C
```
#include <stdbool.h>
#include <stdio.h>
#define SRAL_STATIC
#include <SRAL.h>
#include <stdint.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
void sleep_ms(int milliseconds) {
#ifdef _WIN32
Sleep(milliseconds); // Windows-specific function
#else
usleep(milliseconds * 1000); // usleep takes microseconds
#endif
}
int main(void) {
// Initialize the SRAL library
if (!SRAL_Initialize(0)) {
printf("Failed to initialize SRAL library.\n");
return 1;
}
// Speak some text
if (!SRAL_Speak("Hello, world!", false)) {
printf("Failed to speak text.\n");
}
// Output text to a Braille display
if (!SRAL_Braille("This is Braille output.")) {
printf("Failed to output to Braille display.\n");
}
// Uninitialize the SRAL library
SRAL_Uninitialize();
return 0;
char text[10000];
// Initialize the SRAL library
if (!SRAL_Initialize(ENGINE_UIA)) { // So Microsoft UIAutomation provider can't speak in the terminal or none current process windows
printf("Failed to initialize SRAL library.\n");
return 1;
}
SRAL_RegisterKeyboardHooks();
// Speak some text
if (SRAL_GetEngineFeatures(0) & SUPPORTS_SPEECH) {
printf("Enter the text you want to be spoken:\n");
scanf("%s", text);
SRAL_Speak(text, false);
}
// Output text to a Braille display
if (SRAL_GetEngineFeatures(0) & SUPPORTS_BRAILLE) {
printf("Enter the text you want to be shown on braille display:\n");
scanf("%s", text);
SRAL_Braille(text);
}
// Delay example
SRAL_Output("Delay example: Enter any text", false);
SRAL_Delay(5000);
SRAL_Output("Press enter to continue", false);
scanf("%s", text);
SRAL_StopSpeech(); // Stops the delay thread
// Speech rate
if (SRAL_GetEngineFeatures(0) & SUPPORTS_SPEECH_RATE) {
uint64_t rate = SRAL_GetRate();
const uint64_t max_rate = rate + 10;
for (rate; rate < max_rate; rate++) {
SRAL_SetRate(rate);
SRAL_Speak(text, false);
sleep_ms(500);
}
}
// Uninitialize the SRAL library
SRAL_Uninitialize();
return 0;
}
```

## Python
```
import time
import sral
def sleep_ms(milliseconds):
time.sleep(milliseconds / 1000.0) # Convert milliseconds to seconds
def main():
text = ""
# Initialize the SRAL library
instance = sral.Sral(32)
instance.register_keyboard_hooks()
# Speak some text
if instance.get_engine_features(0) & 128:
text = input("Enter the text you want to be spoken:\n")
instance.speak(text, False)
# Output text to a Braille display
if instance.get_engine_features(0) & 256:
text = input("Enter the text you want to be shown on braille display:\n")
instance.braille(text)
# Delay example
instance.output("Delay example: Enter any text", False)
instance.delay(5000)
instance.output("Press enter to continue", False)
input() # Wait for user to press enter
instance.stop_speech() # Stops the delay thread
# Speech rate
if instance.get_engine_features(0) & 512:
rate = instance.get_rate()
max_rate = rate + 10
for rate in range(rate, max_rate):
instance.set_rate(rate)
instance.speak(text, False)
sleep_ms(500)
# Uninitialize the SRAL library
instance = None
if __name__ == "__main__":
main() # invoke_main()
```


## Additional info
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.
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.

0 comments on commit 4097cbb

Please sign in to comment.