[BRLTTY] Improving the speech support of brltty

Eric Scheibler email at eric-scheibler.de
Tue Apr 24 13:05:38 EDT 2012


Hello,

I want to improve the speech output of brltty. Cause I also often use
the speech to navigate, I miss some features which I strongly need to
work efficiently. Some of them are:
1. read out a text line word by word
2. implement a typing word echo
3. speak the characters when I move around the cursor with Capslock +
rightarrow / leftarrow
4. change pitch of voice on capital letters

I'am interested in helping with the implementation of the features. For
the first two points I've written a short sample code, which I append on
this mail. But now I need help. I've problems to find the correct place
to insert my code. I need:
1. A place, where I can add a new keyboard / braille shortcut for the
jump by word function.
2. Then I need the text line and the position of the cursor as input
parameters.
3. Finally transfer the found word to the speech synthesizer, like you
do for example when you move the cursor one line up.

Can someone help me to find the respective locations in the code?

Thank you in advance
regards
Eric

------------------------------

move_word_by_word.c

#include <stdio.h>
#include <string.h>

#define MAXLEN 50

/*
* the function gets a text line, the current cursor position and a list
of delimiters
* it searches for the next delimiter in the text line and begins at the
current cursor position
* if no delimiter can be found the end of the string is used as delimiter
* then it cuts out the found string and saves it in the variable
"current_word"
*/
int get_current_word(char *current_word, char *line, int current_pos,
const char *delimiters) {
	int i,j;
	// clear the current_word string
	for(i=0; i<MAXLEN; i++)
		current_word[i] = '\0';
	// search text_line for the given delimiters
	for(i=current_pos; i<strlen(line)-1; i++) {
		for(j=0; j<strlen(delimiters); j++) {
			if(line[i] == delimiters[j]) {
				if((i-current_pos) < MAXLEN)
					strncpy(current_word, line+current_pos, i-current_pos);
				else
					strncpy(current_word, line+current_pos, MAXLEN);
				current_word[MAXLEN-1] = '\0';
				return 0;
			}
		}
	}
	if((strlen(line)-current_pos) < MAXLEN)
		strncpy(current_word, line+current_pos, strlen(line)-current_pos);
	else
		strncpy(current_word, line+current_pos, MAXLEN);
	current_word[MAXLEN-1] = '\0';
	return 0;
}

/*
* the function returns the position of the next word in the text line
* if no delimiter can be found, it returns the current pos
*/
int cursor_to_next_word(char *line, int current_pos, char *delimiters) {
	int i,j;
	for(i=current_pos; i<strlen(line)-1; i++) {
		for(j=0; j<strlen(delimiters); j++) {
			if(line[i] == delimiters[j])
				return(i+1);
		}
	}
	return current_pos;
}

/*
* the function returns the position of the previous word in the text line
* if no delimiter can be found, it returns 0
*/
int cursor_to_prev_word(char *line, int current_pos, char *delimiters) {
	int i,j,count=0;
	for(i=current_pos; i>=0; i--) {
		for(j=0; j<strlen(delimiters); j++) {
			if(line[i] == delimiters[j])
				if(count == 1)
					return(i+1);
				else
					count++;
		}
	}
	return 0;
}

int main() {
	// define a number of characters, which define the end of a word
	char delimiters[] = " ,/";
	// an example string
	char text_line[] = "the exact distribution.terms for each program are
described in the individual files in /usr/share/doc/*/copyright.";
	// variable of the current word
	char current_word[MAXLEN];
	
	/* first example
	* navigate word by word in an area without a visible cursor
	* for example read out the console output
	*/
	// 1. start on the left edge
	int current_cursor_pos = 0;
	// 2. user presses the "one word left" shortcut, for example Capslock +
CTRL + LeftArrow
	// 3. search for the beginning of the next word
	current_cursor_pos = cursor_to_next_word(text_line, current_cursor_pos,
delimiters);
	printf("cursor moved to the beginning of the next word on pos %d\n",
current_cursor_pos);
	// 4. get the next word and give it to the speech synthisizer
	get_current_word(current_word, text_line, current_cursor_pos, delimiters);
	printf("brltty speaks \"%s\"\n", current_word);

	/* second example
	* navigate word by word in a text area with an existing cursor
	* for example the command prompt or the vim
	*/
	// 1. user jumps to the next word, for example vim: presses w
	// 2. cursor stands on the beginning of the next word, at the moment
brltty reads out the first character
	current_cursor_pos = 38;
	// 3. get the next word and give it to the speech synthisizer
	get_current_word(current_word, text_line, current_cursor_pos, delimiters);
	printf("brltty speaks \"%s\"\n", current_word);

	/* third example
	* word echo
	* reads out the typed word after pressing one of the spezified delimiters
	*/
	// 1. user typed the following into the command prompt:
	strcpy(text_line, "ls /etc/");
	// when the delimiter "/" is entered, brltty should speak the last
typed word "etc"
	current_cursor_pos = strlen(text_line)-1;
	current_cursor_pos = cursor_to_prev_word(text_line, current_cursor_pos,
delimiters);
	printf("cursor moved to the beginning of the prev word on pos %d\n",
current_cursor_pos);
	get_current_word(current_word, text_line, current_cursor_pos, delimiters);
	printf("brltty speaks \"%s\"\n", current_word);

	return(0);
}


More information about the BRLTTY mailing list