@@ 29,6 29,7 @@ void c_freePage(struct page*);
char *c_renderDoc(struct session*, struct page*, _Bool);
char **c_extractLinks(struct page*);
char **c_docLinksAndRendering(struct session*, struct page*, _Bool); // FIXME segfaults.
+int c_ssmlHasMark(char*, char*);
/* espeak-ng integration. Based on the espeak-ng command source code. */
SNDFILE *fd_wav = NULL;
@@ 123,10 124,13 @@ int speak_initialize() {
samplerate = espeak_ng_GetSampleRate();
return 0;
}
-void speak(char *ssml, char *mark) {
+void speak(char *ssml, char *mark, char* fallback) {
int flags = espeakCHARS_AUTO | espeakPHONEMES | espeakENDPAUSE | espeakCHARS_UTF8 | espeakSSML;
- if (mark != NULL) espeak_Synth_Mark(ssml, strlen(ssml)+1, mark, 0, flags, NULL, NULL);
- espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL); // FIXME only do so if mark doesn't play.
+ if (mark != NULL && c_ssmlHasMark(mark, ssml))
+ espeak_Synth_Mark(ssml, strlen(ssml)+1, mark, 0, flags, NULL, NULL);
+ else if (fallback != NULL)
+ espeak_Synth_Mark(ssml, strlen(ssml)+1, fallback, 0, flags, NULL, NULL);
+ else espeak_Synth(ssml, strlen(ssml)+1, 0, POS_CHARACTER, 0, flags, NULL, NULL);
}
int read_keyboard = 0;
int speak_finalize(char *ssml) {
@@ 134,6 138,7 @@ int speak_finalize(char *ssml) {
char c = getc(stdin);
if (c == '\033') {
char mark[200];
+ char fallback[200];
espeak_Cancel();
c = getc(stdin);
if (c == 0 || c == -1 || c == '\033' || c == 'q') goto close; // skip [
@@ 144,37 149,39 @@ int speak_finalize(char *ssml) {
tablerow--;
if (tablerow > 0) {
sprintf(mark, "-rhaps-tablecell%i:%ix%i", tableno, tablerow, tablecol);
- speak(ssml, mark);
+ speak(ssml, mark, NULL);
break;
} else in_table = 0;
}
section_no--;
sprintf(mark, "-rhaps-section%i", section_no);
- speak(ssml, section_no > 0 ? mark : NULL);
+ speak(ssml, section_no > 0 ? mark : NULL, NULL);
break;
case 'B':
// 🠗
if (in_table) {
tablerow++;
sprintf(mark, "-rhaps-tablecell%i:%ix%i", tableno, tablerow, tablecol);
- speak(ssml, mark);
+ sprintf(fallback, "-rhaps-section%i", section_no+1);
+ speak(ssml, mark, fallback);
break; // FIXME What if that mark doesn't exist?
}
section_no++;
sprintf(mark, "-rhaps-section%i", section_no);
- speak(ssml, section_no > 0 ? mark : NULL);
+ speak(ssml, section_no > 0 ? mark : NULL, NULL);
break;
case 'C':
// ➔
if (in_table) {
tablecol++;
sprintf(mark, "-rhaps-tablecell%i:%ix%i", tableno, tablerow, tablecol);
- speak(ssml, mark);
+ sprintf(fallback, "-rhaps-paragraph%i", paragraph_no+1);
+ speak(ssml, mark, fallback);
break; // FIXME What if that mark doesn't exist?
}
paragraph_no++;
sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
- speak(ssml, paragraph_no > 0 ? mark : NULL);
+ speak(ssml, paragraph_no > 0 ? mark : NULL, NULL);
break;
case 'D':
// 🠔
@@ 182,13 189,13 @@ int speak_finalize(char *ssml) {
tablecol--;
if (tablecol > 0) {
sprintf(mark, "-rhaps-tablecell%i:%ix%i", tableno, tablerow, tablecol);
- speak(ssml, mark);
+ speak(ssml, mark, NULL);
break;
} else in_table = 0;
}
paragraph_no--;
sprintf(mark, "-rhaps-paragraph%i", paragraph_no);
- speak(ssml, paragraph_no > 0 ? mark : NULL);
+ speak(ssml, paragraph_no > 0 ? mark : NULL, NULL);
break;
}
}
@@ 303,7 310,7 @@ int main(int argc, char **argv) {
if (use_espeak) speak_err = speak_initialize();
char *ssml;
for (int i = optind; i < argc; i++) {
- if (use_espeak && speak_err == 0) speak(argv[i], NULL);
+ if (use_espeak && speak_err == 0) speak(argv[i], NULL, NULL);
#ifdef WITH_SPEECHD
else if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, argv[i]);
#endif
@@ 315,7 322,7 @@ int main(int argc, char **argv) {
if (fd_ssml != NULL) fprintf(fd_ssml, "%s\n", ssml);
if (fd_links != NULL) write_links(fd_links, links);
- if (use_espeak & speak_err == 0) speak(ssml, "main");
+ if (use_espeak & speak_err == 0) speak(ssml, "main", NULL);
#ifdef WITH_SPEECHD
if (spd_conn != NULL) spd_say(spd_conn, SPD_MESSAGE, ssml);
#endif