|
11 | 11 |
|
12 | 12 | #define CLAUSE_TYPE_CLAUSE 0x00040000 |
13 | 13 | #define CLAUSE_TYPE_SENTENCE 0x00080000 |
| 14 | +#define CLAUSE_TYPE_EOF 0x00010000 |
| 15 | + |
| 16 | +#define CLAUSE_INTONATION_TYPE 0x00007000 |
| 17 | +#define CLAUSE_PAUSE 0x00000FFF |
14 | 18 |
|
15 | 19 | #define CLAUSE_PERIOD (40 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_SENTENCE) |
16 | 20 | #define CLAUSE_COMMA (20 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE) |
|
20 | 24 | #define CLAUSE_COLON (30 | CLAUSE_INTONATION_FULL_STOP | CLAUSE_TYPE_CLAUSE) |
21 | 25 | #define CLAUSE_SEMICOLON (30 | CLAUSE_INTONATION_COMMA | CLAUSE_TYPE_CLAUSE) |
22 | 26 |
|
| 27 | +#define EXCLAMATION_PAUSE (CLAUSE_EXCLAMATION & CLAUSE_PAUSE) |
| 28 | +#define PERIOD_PAUSE (CLAUSE_PERIOD & CLAUSE_PAUSE) |
| 29 | +#define SEMICOLON_PAUSE (CLAUSE_SEMICOLON & CLAUSE_PAUSE) |
| 30 | +#define COMMA_PAUSE (CLAUSE_COMMA & CLAUSE_PAUSE) |
| 31 | + |
23 | 32 | static PyObject *py_initialize(PyObject *self, PyObject *args) { |
24 | 33 | const char *data_dir; |
25 | 34 | if (!PyArg_ParseTuple(args, "s", &data_dir)) { |
@@ -64,29 +73,36 @@ static PyObject *py_get_phonemes(PyObject *self, PyObject *args) { |
64 | 73 | (const void **)&text, espeakCHARS_AUTO, espeakPHONEMES_IPA, |
65 | 74 | &terminator); |
66 | 75 |
|
67 | | - // Categorize terminator |
68 | | - terminator &= 0x000FFFFF; |
69 | | - |
70 | | - if (terminator == CLAUSE_PERIOD) { |
71 | | - terminator_str = "."; |
72 | | - } else if (terminator == CLAUSE_QUESTION) { |
73 | | - terminator_str = "?"; |
74 | | - } else if (terminator == CLAUSE_EXCLAMATION) { |
75 | | - terminator_str = "!"; |
76 | | - } else if (terminator == CLAUSE_COMMA) { |
77 | | - terminator_str = ","; |
78 | | - } else if (terminator == CLAUSE_COLON) { |
79 | | - terminator_str = ":"; |
80 | | - } else if (terminator == CLAUSE_SEMICOLON) { |
81 | | - terminator_str = ";"; |
| 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 | + } |
82 | 97 | } |
83 | 98 |
|
84 | 99 | PyList_Append(phonemes_and_terminators, |
85 | 100 | Py_BuildValue("(ssO)", phonemes, terminator_str, |
86 | 101 | (terminator & CLAUSE_TYPE_SENTENCE) == |
87 | 102 | CLAUSE_TYPE_SENTENCE |
88 | 103 | ? Py_True |
89 | | - : Py_False)); |
| 104 | + : Py_False |
| 105 | + )); |
90 | 106 | } |
91 | 107 |
|
92 | 108 | return phonemes_and_terminators; |
|
0 commit comments