mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-03 14:17:12 +00:00
Add espeak_TextToPhonemesWithTerminator
This commit is contained in:
@@ -541,6 +541,12 @@ ESPEAK_API const char *espeak_TextToPhonemes(const void **textptr, int textmode,
|
||||
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
ESPEAK_API const char *espeak_TextToPhonemesWithTerminator(const void **textptr, int textmode, int phonememode, int *terminator);
|
||||
/* Version of espeak_TextToPhonemes that also returns the clause terminator (e.g., CLAUSE_INTONATION_FULL_STOP) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
+26
-10
@@ -850,6 +850,31 @@ ESPEAK_API void espeak_SetPhonemeTrace(int phonememode, FILE *stream)
|
||||
f_trans = stderr;
|
||||
}
|
||||
|
||||
// Same as espeak_TextToPhonemes except we also get the clause terminator used (full stop, comma, etc.).
|
||||
// Depends on the added TranslateClauseWithTerminator in
|
||||
ESPEAK_API const char* espeak_TextToPhonemesWithTerminator(const void** textptr, int textmode, int phonememode, int* terminator)
|
||||
{
|
||||
/* phoneme_mode
|
||||
bit 1: 0=eSpeak's ascii phoneme names, 1= International Phonetic
|
||||
Alphabet (as UTF-8 characters). bit 7: use (bits 8-23) as a tie within
|
||||
multi-letter phonemes names bits 8-23: separator character, between
|
||||
phoneme names
|
||||
*/
|
||||
|
||||
if (p_decoder == NULL)
|
||||
p_decoder = create_text_decoder();
|
||||
|
||||
if (text_decoder_decode_string_multibyte(
|
||||
p_decoder, *textptr, translator->encoding, textmode)
|
||||
!= ENS_OK)
|
||||
return NULL;
|
||||
|
||||
TranslateClauseWithTerminator(translator, NULL, NULL, terminator);
|
||||
*textptr = text_decoder_get_buffer(p_decoder);
|
||||
|
||||
return GetTranslatedPhonemeString(phonememode);
|
||||
}
|
||||
|
||||
ESPEAK_API const char *espeak_TextToPhonemes(const void **textptr, int textmode, int phonememode)
|
||||
{
|
||||
/* phoneme_mode
|
||||
@@ -858,16 +883,7 @@ ESPEAK_API const char *espeak_TextToPhonemes(const void **textptr, int textmode,
|
||||
bits 8-23: separator character, between phoneme names
|
||||
*/
|
||||
|
||||
if (p_decoder == NULL)
|
||||
p_decoder = create_text_decoder();
|
||||
|
||||
if (text_decoder_decode_string_multibyte(p_decoder, *textptr, translator->encoding, textmode) != ENS_OK)
|
||||
return NULL;
|
||||
|
||||
TranslateClause(translator, NULL, NULL);
|
||||
*textptr = text_decoder_get_buffer(p_decoder);
|
||||
|
||||
return GetTranslatedPhonemeString(phonememode);
|
||||
return espeak_TextToPhonemesWithTerminator(textptr, textmode, phonememode, NULL);
|
||||
}
|
||||
|
||||
ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Cancel(void)
|
||||
|
||||
@@ -919,7 +919,9 @@ static int UpperCaseInWord(Translator *tr, char *word, int c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TranslateClause(Translator *tr, int *tone_out, char **voice_change)
|
||||
// Same as TranslateClause except we also get the clause terminator used (full stop, comma, etc.).
|
||||
// Used by espeak_TextToPhonemesWithTerminator.
|
||||
void TranslateClauseWithTerminator(Translator *tr, int *tone_out, char **voice_change, int *terminator_out)
|
||||
{
|
||||
int ix;
|
||||
int c;
|
||||
@@ -983,6 +985,10 @@ void TranslateClause(Translator *tr, int *tone_out, char **voice_change)
|
||||
MAKE_MEM_UNDEFINED(&source, sizeof(source));
|
||||
terminator = ReadClause(tr, source, charix, &charix_top, N_TR_SOURCE, &tone, voice_change_name);
|
||||
|
||||
if (terminator_out != NULL) {
|
||||
*terminator_out = terminator;
|
||||
}
|
||||
|
||||
if (tone_out != NULL) {
|
||||
if (tone == 0)
|
||||
*tone_out = (terminator & CLAUSE_INTONATION_TYPE) >> 12; // tone type not overridden in ReadClause, use default
|
||||
@@ -1668,6 +1674,11 @@ void TranslateClause(Translator *tr, int *tone_out, char **voice_change)
|
||||
}
|
||||
}
|
||||
|
||||
void TranslateClause(Translator *tr, int *tone_out, char **voice_change)
|
||||
{
|
||||
TranslateClauseWithTerminator(tr, tone_out, voice_change, NULL);
|
||||
}
|
||||
|
||||
static int CalcWordLength(int source_index, int charix_top, short int *charix, WORD_TAB *words, int word_count) {
|
||||
int j;
|
||||
int k;
|
||||
|
||||
Reference in New Issue
Block a user