| #define N_XML_BUF 500 | #define N_XML_BUF 500 | ||||
| static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]); | static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]); | ||||
| static void TerminateBufWithSpaceAndZero(char *buf, int index); | |||||
| static void TerminateBufWithSpaceAndZero(char *buf, int index, int *ungetc); | |||||
| static const char *xmlbase = ""; // base URL from <speak> | static const char *xmlbase = ""; // base URL from <speak> | ||||
| punctname, punct_count, punctname); | punctname, punct_count, punctname); | ||||
| } else { | } else { | ||||
| // end the clause now and pick up the punctuation next time | // end the clause now and pick up the punctuation next time | ||||
| UngetC(c2); | |||||
| ungot_char2 = c1; | ungot_char2 = c1; | ||||
| TerminateBufWithSpaceAndZero(buf, 0); | |||||
| TerminateBufWithSpaceAndZero(buf, 0, &c2); | |||||
| } | } | ||||
| } | } | ||||
| // check for space in the output buffer for embedded commands produced by the SSML tag | // check for space in the output buffer for embedded commands produced by the SSML tag | ||||
| if (ix > (n_buf - 20)) { | if (ix > (n_buf - 20)) { | ||||
| // Perhaps not enough room, end the clause before the SSML tag | // Perhaps not enough room, end the clause before the SSML tag | ||||
| UngetC(c2); | |||||
| ungot_char2 = c1; | ungot_char2 = c1; | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, &c2); | |||||
| return CLAUSE_NONE; | return CLAUSE_NONE; | ||||
| } | } | ||||
| terminator = ProcessSsmlTag(xml_buf, buf, &ix, n_buf, xmlbase, &audio_text, current_voice_id, &base_voice, base_voice_variant_name, &ignore_text, &clear_skipping_text, &sayas_mode, &sayas_start, ssml_stack, &n_ssml_stack, &n_param_stack, (int *)speech_parameters); | terminator = ProcessSsmlTag(xml_buf, buf, &ix, n_buf, xmlbase, &audio_text, current_voice_id, &base_voice, base_voice_variant_name, &ignore_text, &clear_skipping_text, &sayas_mode, &sayas_start, ssml_stack, &n_ssml_stack, &n_param_stack, (int *)speech_parameters); | ||||
| if (terminator != 0) { | if (terminator != 0) { | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, NULL); | |||||
| if (terminator & CLAUSE_TYPE_VOICE_CHANGE) | if (terminator & CLAUSE_TYPE_VOICE_CHANGE) | ||||
| strcpy(voice_change, current_voice_id); | strcpy(voice_change, current_voice_id); | ||||
| ix += utf8_out(c1, &buf[ix]); | ix += utf8_out(c1, &buf[ix]); | ||||
| terminator = CLAUSE_PERIOD; // line doesn't end in punctuation, assume period | terminator = CLAUSE_PERIOD; // line doesn't end in punctuation, assume period | ||||
| } | } | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, NULL); | |||||
| return terminator; | return terminator; | ||||
| } | } | ||||
| } | } | ||||
| if (parag > 0) { | if (parag > 0) { | ||||
| // 2nd newline, assume paragraph | // 2nd newline, assume paragraph | ||||
| UngetC(c2); | |||||
| if (end_clause_after_tag) | if (end_clause_after_tag) | ||||
| RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation | RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, &c2); | |||||
| if (parag > 3) | if (parag > 3) | ||||
| parag = 3; | parag = 3; | ||||
| if (option_ssml) parag = 1; | if (option_ssml) parag = 1; | ||||
| if (linelength <= option_linelength) { | if (linelength <= option_linelength) { | ||||
| // treat lines shorter than a specified length as end-of-clause | // treat lines shorter than a specified length as end-of-clause | ||||
| UngetC(c2); | |||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, &c2); | |||||
| return CLAUSE_COLON; | return CLAUSE_COLON; | ||||
| } | } | ||||
| if (!iswspace(c1)) { | if (!iswspace(c1)) { | ||||
| if (!IsAlpha(c1) || !iswlower(c1)) { | if (!IsAlpha(c1) || !iswlower(c1)) { | ||||
| UngetC(c2); | |||||
| ungot_char2 = c1; | ungot_char2 = c1; | ||||
| TerminateBufWithSpaceAndZero(buf, end_clause_index); | |||||
| TerminateBufWithSpaceAndZero(buf, end_clause_index, &c2); | |||||
| return end_clause_after_tag; | return end_clause_after_tag; | ||||
| } | } | ||||
| end_clause_after_tag = 0; | end_clause_after_tag = 0; | ||||
| } | } | ||||
| if (is_end_clause) { | if (is_end_clause) { | ||||
| UngetC(c_next); | |||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, &c_next); | |||||
| if (iswdigit(cprev) && !IsAlpha(c_next)) // ???? | if (iswdigit(cprev) && !IsAlpha(c_next)) // ???? | ||||
| punct_data &= ~CLAUSE_DOT_AFTER_LAST_WORD; | punct_data &= ~CLAUSE_DOT_AFTER_LAST_WORD; | ||||
| // clause too long, getting near end of buffer, so break here | // clause too long, getting near end of buffer, so break here | ||||
| // try to break at a word boundary (unless we actually reach the end of buffer). | // try to break at a word boundary (unless we actually reach the end of buffer). | ||||
| // (n_buf-4) is to allow for 3 bytes of multibyte character plus terminator. | // (n_buf-4) is to allow for 3 bytes of multibyte character plus terminator. | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| UngetC(c2); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, &c2); | |||||
| return CLAUSE_NONE; | return CLAUSE_NONE; | ||||
| } | } | ||||
| } | } | ||||
| ix += utf8_out(CHAR_EMPHASIS, &buf[ix]); | ix += utf8_out(CHAR_EMPHASIS, &buf[ix]); | ||||
| if (end_clause_after_tag) | if (end_clause_after_tag) | ||||
| RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation | RemoveChar(&buf[end_clause_index]); // delete clause-end punctiation | ||||
| TerminateBufWithSpaceAndZero(buf, ix); | |||||
| TerminateBufWithSpaceAndZero(buf, ix, NULL); | |||||
| return CLAUSE_EOF; // end of file | return CLAUSE_EOF; // end of file | ||||
| } | } | ||||
| xmlbase = NULL; | xmlbase = NULL; | ||||
| } | } | ||||
| static void TerminateBufWithSpaceAndZero(char *buf, int index) { | |||||
| static void TerminateBufWithSpaceAndZero(char *buf, int index, int *ungetc) { | |||||
| buf[index] = ' '; | buf[index] = ' '; | ||||
| buf[index+1] = 0; | buf[index+1] = 0; | ||||
| if (ungetc != NULL) { | |||||
| UngetC(*ungetc); | |||||
| } | |||||
| } | } | ||||
| static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]) { | static void DecodeWithPhonemeMode(char *buf, char *phonemes, Translator *tr, Translator *tr2, unsigned int flags[]) { |