@@ -57,6 +57,29 @@ static PyObject *py_set_voice(PyObject *self, PyObject *args) {
5757 Py_RETURN_NONE ;
5858}
5959
60+ static char * categorize_terminator (int terminator ) {
61+ if ((terminator & CLAUSE_TYPE_EOF ) != CLAUSE_TYPE_EOF ) {
62+ int pause = terminator & CLAUSE_PAUSE ;
63+
64+ if (pause >= PERIOD_PAUSE ) {
65+ switch (terminator & CLAUSE_INTONATION_TYPE ) {
66+ case CLAUSE_INTONATION_EXCLAMATION : return "!" ;
67+ case CLAUSE_INTONATION_QUESTION : return "?" ;
68+ default : return "." ;
69+ }
70+ } else if (pause >= SEMICOLON_PAUSE ) {
71+ switch (terminator & CLAUSE_INTONATION_TYPE ) {
72+ case CLAUSE_INTONATION_FULL_STOP : return ":" ;
73+ default : return ";" ;
74+ }
75+ } else if (pause >= COMMA_PAUSE ) {
76+ return "," ;
77+ }
78+ }
79+
80+ return "" ;
81+ }
82+
6083static PyObject * py_get_phonemes (PyObject * self , PyObject * args ) {
6184 const char * text ;
6285 if (!PyArg_ParseTuple (args , "s" , & text )) {
@@ -67,42 +90,19 @@ static PyObject *py_get_phonemes(PyObject *self, PyObject *args) {
6790
6891 while (text != NULL ) {
6992 int terminator = 0 ;
70- char * terminator_str = "" ;
7193
7294 const char * phonemes = espeak_TextToPhonemesWithTerminator (
7395 (const void * * )& text , espeakCHARS_AUTO , espeakPHONEMES_IPA ,
7496 & terminator );
7597
76- if (!(terminator & CLAUSE_TYPE_EOF )) {
77- int pause = terminator & CLAUSE_PAUSE ;
78- int intonation = terminator & CLAUSE_INTONATION_TYPE ;
79-
80- if (pause >= PERIOD_PAUSE ) {
81- if (intonation == CLAUSE_INTONATION_EXCLAMATION ) {
82- terminator_str = "!" ;
83- } else if (intonation == CLAUSE_INTONATION_QUESTION ) {
84- terminator_str = "?" ;
85- } else {
86- terminator_str = "." ;
87- }
88- } else if (pause >= SEMICOLON_PAUSE ) {
89- if (intonation == CLAUSE_INTONATION_FULL_STOP ) {
90- terminator_str = ":" ;
91- } else {
92- terminator_str = ";" ;
93- }
94- } else if (pause >= COMMA_PAUSE ) {
95- terminator_str = "," ;
96- }
97- }
98+ char * terminator_str = categorize_terminator (terminator );
9899
99100 PyList_Append (phonemes_and_terminators ,
100101 Py_BuildValue ("(ssO)" , phonemes , terminator_str ,
101102 (terminator & CLAUSE_TYPE_SENTENCE ) ==
102103 CLAUSE_TYPE_SENTENCE
103104 ? Py_True
104- : Py_False
105- ));
105+ : Py_False ));
106106 }
107107
108108 return phonemes_and_terminators ;
0 commit comments