Eclectic Media Git rhapsode / c15af78
Add arrow key navigation inside pages. Adrian Cochrane 6 months ago
1 changed file(s) with 26 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
116116 samplerate = espeak_ng_GetSampleRate();
117117 return 0;
118118 }
119 void speak(char *ssml) {
119 void speak(char *ssml, char *mark) {
120120 int flags = espeakCHARS_AUTO | espeakPHONEMES | espeakENDPAUSE | espeakCHARS_UTF8 | espeakSSML;
121 espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL);
121 if (mark != NULL) espeak_Synth_Mark(ssml, strlen(ssml)+1, mark, 0, flags, NULL, NULL);
122 espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL); // FIXME only do so if mark doesn't play.
122123 }
123124 int read_keyboard = 0;
124 int speak_finalize() {
125 int speak_finalize(char *ssml) {
125126 while (read_keyboard) {
126127 char c = getc(stdin);
127128 if (c == '\033') {
129 char mark[200];
128130 espeak_Cancel();
129131 c = getc(stdin);
130132 if (c == 0 || c == -1 || c == '\033' || c == 'q') goto close; // skip [
131133 switch (getc(stdin)) {
132134 case 'A':
133 printf("🠕");
135 // 🠕
136 section_no--;
137 sprintf(mark, "-rhaps-section%i", section_no);
138 speak(ssml, section_no > 0 ? mark : NULL);
134139 break;
135140 case 'B':
136 printf("🠗");
141 // 🠗
142 section_no++;
143 sprintf(mark, "-rhaps-section%i", section_no);
144 speak(ssml, section_no > 0 ? mark : NULL);
137145 break;
138146 case 'C':
139 printf("➔");
147 // ➔
148 paragraph_no++;
149 sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
150 speak(ssml, paragraph_no > 0 ? mark : NULL);
140151 break;
141152 case 'D':
142 printf("🠔");
153 // 🠔
154 paragraph_no--;
155 sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
156 speak(ssml, paragraph_no > 0 ? mark : NULL);
143157 break;
144158 }
145159 }
233247 struct page *referer = c_initialReferer();
234248
235249 if (use_espeak) speak_err = speak_initialize();
250 char *ssml;
236251 for (int i = optind; i < argc; i++) {
237 if (use_espeak && speak_err == 0) speak(argv[i]);
252 if (use_espeak && speak_err == 0) speak(argv[i], NULL);
238253 else printf("%s\n", argv[i]);
239254
240255 struct page *page = c_fetchURL(session, mimes, referer, argv[i]);
241 char *ssml = c_renderDoc(session, page, use_espeak);
256 ssml = c_renderDoc(session, page, use_espeak);
242257 char **links = c_extractLinks(page);
243258
244259 if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
245260 if (fd_links != NULL) write_links(fd_links, links);
246 if (use_espeak & speak_err == 0) speak(ssml);
261 if (use_espeak & speak_err == 0) speak(ssml, "main");
247262
248263 c_freePage(page);
249264 }
250 if (use_espeak & speak_err == 0) speak_err = speak_finalize();
265 if (use_espeak & speak_err == 0) speak_err = speak_finalize(ssml);
251266
252267 c_freePage(referer);
253268 c_freeSession(session);