Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2009 SVOX AG, Baslerstr. 30, 8048 Zuerich, Switzerland |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 16 | */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 17 | |
| 18 | #include "svox_ssml_parser.h" |
| 19 | #include <utils/Log.h> |
| 20 | #include <cutils/jstring.h> |
| 21 | #include <string.h> |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 22 | #include <utils/String16.h> |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 23 | |
| 24 | #define SSML_PITCH_XLOW "50" |
| 25 | #define SSML_PITCH_LOW "75" |
| 26 | #define SSML_PITCH_MEDIUM "100" |
| 27 | #define SSML_PITCH_HIGH "150" |
| 28 | #define SSML_PITCH_XHIGH "200" |
| 29 | #define SSML_RATE_XSLOW "30" |
| 30 | #define SSML_RATE_SLOW "60" |
| 31 | #define SSML_RATE_MEDIUM "100" |
| 32 | #define SSML_RATE_FAST "250" |
| 33 | #define SSML_RATE_XFAST "500" |
| 34 | #define SSML_VOLUME_SILENT "0" |
Charles Chen | 474a319 | 2009-07-17 18:02:16 -0700 | [diff] [blame] | 35 | #define SSML_VOLUME_XLOW "25" |
| 36 | #define SSML_VOLUME_LOW "70" |
Jean-Michel Trivi | 0e684c3 | 2009-07-21 18:17:27 -0700 | [diff] [blame] | 37 | #define SSML_VOLUME_MEDIUM "120" |
| 38 | #define SSML_VOLUME_LOUD "300" |
| 39 | #define SSML_VOLUME_XLOUD "450" |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 40 | #define SSML_BREAK_NONE "0ms" |
| 41 | #define SSML_BREAK_XWEAK "100ms" |
| 42 | #define SSML_BREAK_WEAK "300ms" |
| 43 | #define SSML_BREAK_MEDIUM "600ms" |
| 44 | #define SSML_BREAK_STRONG "1s" |
| 45 | #define SSML_BREAK_XSTRONG "3s" |
| 46 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 47 | extern int cnvIpaToXsampa(const char16_t* ipaString, size_t ipaStringSize, char** outXsampaString); |
| 48 | extern char * createPhonemeString( const char * xsampa, int length ); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 49 | |
| 50 | SvoxSsmlParser::SvoxSsmlParser() : m_isInBreak(0), m_appendix(NULL), m_docLanguage(NULL) |
| 51 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 52 | mParser = XML_ParserCreate("UTF-8"); |
| 53 | if (mParser) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 54 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 55 | XML_SetElementHandler(mParser, starttagHandler, endtagHandler); |
| 56 | XML_SetCharacterDataHandler(mParser, textHandler); |
| 57 | XML_SetUserData(mParser, (void*)this); |
| 58 | m_datasize = 512; |
| 59 | m_data = new char[m_datasize]; |
Narayan Kamath | c3a05c0 | 2018-02-06 11:02:21 +0000 | [diff] [blame] | 60 | if (!m_data) |
| 61 | { |
| 62 | ALOGE("Error: failed to allocate memory for string!\n"); |
| 63 | } else { |
| 64 | memset(m_data, 0, m_datasize); |
| 65 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | SvoxSsmlParser::~SvoxSsmlParser() |
| 70 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 71 | if (mParser) |
| 72 | XML_ParserFree(mParser); |
| 73 | if (m_data) |
| 74 | delete [] m_data; |
| 75 | if (m_appendix) |
| 76 | delete [] m_appendix; |
| 77 | if (m_docLanguage) |
| 78 | delete [] m_docLanguage; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int SvoxSsmlParser::initSuccessful() |
| 82 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 83 | return (mParser && m_data); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | int SvoxSsmlParser::parseDocument(const char* ssmldoc, int isFinal) |
| 87 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 88 | int doclen = (int)strlen(ssmldoc) + 1; |
| 89 | int status = XML_Parse(mParser, ssmldoc, doclen, isFinal); |
| 90 | if (status == XML_STATUS_ERROR) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 91 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 92 | /* Note: for some reason Expat almost always complains about invalid tokens, even when document is well formed */ |
Steve Block | 659851c | 2012-01-04 20:01:45 +0000 | [diff] [blame] | 93 | ALOGI("Parser error at line %d: %s\n", (int)XML_GetCurrentLineNumber(mParser), XML_ErrorString(XML_GetErrorCode(mParser))); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 94 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 95 | return status; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | char* SvoxSsmlParser::getParsedDocument() |
| 99 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 100 | return m_data; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | char* SvoxSsmlParser::getParsedDocumentLanguage() |
| 104 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 105 | return m_docLanguage; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void SvoxSsmlParser::starttagHandler(void* data, const XML_Char* element, const XML_Char** attributes) |
| 109 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 110 | ((SvoxSsmlParser*)data)->startElement(element, attributes); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void SvoxSsmlParser::startElement(const XML_Char* element, const XML_Char** attributes) |
| 114 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 115 | if (strcmp(element, "speak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 116 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 117 | if (strlen(m_data) > 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 118 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 119 | /* we have old data, get rid of it and reallocate memory */ |
| 120 | delete m_data; |
| 121 | m_data = NULL; |
| 122 | m_datasize = 512; |
| 123 | m_data = new char[m_datasize]; |
| 124 | if (!m_data) |
| 125 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 126 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 127 | return; |
Narayan Kamath | c3a05c0 | 2018-02-06 11:02:21 +0000 | [diff] [blame] | 128 | } else { |
| 129 | memset(m_data, 0, m_datasize); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 130 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 131 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 132 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 133 | /* the only attribute supported in the speak tag is xml:lang, all others are ignored */ |
| 134 | for (int i = 0; attributes[i]; i += 2) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 135 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 136 | if (strcmp(attributes[i], "xml:lang") == 0) |
| 137 | { |
| 138 | if (!m_docLanguage) |
| 139 | { |
| 140 | m_docLanguage = new char[strlen(attributes[i+1])+1]; |
| 141 | } |
| 142 | strcpy(m_docLanguage, attributes[i+1]); |
| 143 | break; |
| 144 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 147 | else if (strcmp(element, "p") == 0) /* currently no attributes are supported for <p> */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 148 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 149 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 150 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 151 | if (!growDataSize(100)) |
| 152 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 153 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 154 | return; |
| 155 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 156 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 157 | strcat(m_data, "<p>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 158 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 159 | else if (strcmp(element, "s") == 0) /* currently no attributes are supported for <s> */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 160 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 161 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 162 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 163 | if (!growDataSize(100)) |
| 164 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 165 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 166 | return; |
| 167 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 168 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 169 | strcat(m_data, "<s>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 170 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 171 | else if (strcmp(element, "phoneme") == 0) /* only ipa and xsampa alphabets are supported */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 172 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 173 | int alpha = 1; /* set to 1 if alphabet is ipa */ |
| 174 | int tagComplete = 0; /* set to 1 if phoneme tag has already been added */ |
| 175 | char16_t* ph = NULL; |
| 176 | char* xsampastr = NULL; |
| 177 | size_t phsize = 0; |
| 178 | size_t xsampasize = 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 179 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 180 | for (int i = 0; attributes[i]; i += 2) |
| 181 | { |
| 182 | if (strcmp(attributes[i], "alphabet") == 0) |
| 183 | { |
| 184 | if (strcmp(attributes[i+1], "xsampa") == 0) |
| 185 | { |
| 186 | alpha = 0; |
| 187 | } |
| 188 | } |
| 189 | if (strcmp(attributes[i], "ph") == 0) |
| 190 | { |
| 191 | ph = new char16_t[strlen8to16(attributes[i+1]) + 1]; |
| 192 | ph = strdup8to16(attributes[i+1], &phsize); |
| 193 | } |
| 194 | } |
| 195 | if (!ph) |
| 196 | { |
| 197 | /* error, no phonetic string */ |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 198 | ALOGE("Error: bad SSML syntax, ph attribute not supplied."); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 199 | return; |
| 200 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 201 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 202 | if (alpha) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 203 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 204 | /* need to convert phoneme string to xsampa */ |
| 205 | xsampasize = cnvIpaToXsampa(ph, phsize, &xsampastr); |
| 206 | delete [] ph; |
| 207 | if (!xsampastr) |
| 208 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 209 | ALOGE("Error: failed to allocate memory for IPA string conversion"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | } |
| 213 | else |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 214 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 215 | xsampastr = strndup16to8(ph, phsize); |
| 216 | xsampasize = strlen(xsampastr); |
| 217 | delete [] ph; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 218 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 219 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 220 | /* split XSAMPA string into multiple phonemes if needed */ |
| 221 | if (strstr(xsampastr, " ") || strstr(xsampastr, "#")) /* check again to see if we have multiple words */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 222 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 223 | char* phonstr = createPhonemeString(xsampastr, strlen(xsampastr) + 1); |
| 224 | free(xsampastr); |
| 225 | xsampastr = NULL; |
| 226 | xsampastr = (char*)malloc(strlen(phonstr) + 1); |
| 227 | strcpy(xsampastr, phonstr); |
| 228 | free(phonstr); |
| 229 | phonstr = NULL; |
| 230 | tagComplete = 1; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 231 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 232 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 233 | if (tagComplete) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 234 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 235 | if (strlen(m_data) + strlen(xsampastr) + 1 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 236 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 237 | if (!growDataSize(100)) |
| 238 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 239 | ALOGE("Error: failed to allocate memory for string!"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 240 | free(xsampastr); |
| 241 | return; |
| 242 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 245 | else |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 246 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 247 | if (strlen(m_data) + strlen(xsampastr) + 17 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 248 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 249 | if (!growDataSize(100)) |
| 250 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 251 | ALOGE("Error: failed to allocate memory for string!"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 252 | free(xsampastr); |
| 253 | return; |
| 254 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 255 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 256 | strcat(m_data, "<phoneme ph='"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 257 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 258 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 259 | strcat(m_data, xsampastr); |
| 260 | free(xsampastr); |
| 261 | |
| 262 | if (!tagComplete) |
| 263 | { |
| 264 | if (strlen(m_data) + 4 > (size_t)m_datasize) |
| 265 | { |
| 266 | if (!growDataSize(100)) |
| 267 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 268 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 269 | return; |
| 270 | } |
| 271 | } |
| 272 | strcat(m_data, "'/>"); |
| 273 | } |
| 274 | |
| 275 | m_isInBreak = 1; /* set flag to indicate any text between open and close tag is to be discarded */ |
| 276 | } |
| 277 | else if (strcmp(element, "break") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 278 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 279 | if (strlen(m_data) + 17 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 280 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 281 | if (!growDataSize(100)) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 282 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 283 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 284 | return; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 285 | } |
| 286 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 287 | strcat(m_data, "<break time='"); |
| 288 | char* time = NULL; |
| 289 | |
| 290 | for (int i = 0; attributes[i]; i += 2) |
| 291 | { |
| 292 | if (strcmp(attributes[i], "time") == 0) |
| 293 | { |
| 294 | time = new char[strlen(attributes[i+1]) + 1]; |
| 295 | if (!time) |
| 296 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 297 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 298 | return; |
| 299 | } |
| 300 | strcpy(time, attributes[i+1]); |
| 301 | } |
| 302 | else if (strcmp(attributes[i], "strength") == 0 && !time) |
| 303 | { |
| 304 | time = convertBreakStrengthToTime(attributes[i+1]); |
| 305 | } |
| 306 | } |
| 307 | if (!time) |
| 308 | { |
| 309 | time = new char[6]; |
| 310 | if (!time) |
| 311 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 312 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | strcpy(time, SSML_BREAK_WEAK); /* if no time or strength attributes are specified, default to weak break */ |
| 316 | } |
| 317 | if (strlen(m_data) + strlen(time) + 4 > (size_t)m_datasize) |
| 318 | { |
| 319 | if (!growDataSize(100)) |
| 320 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 321 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | } |
| 325 | strcat(m_data, time); |
| 326 | strcat(m_data, "'/>"); |
| 327 | m_isInBreak = 1; /* set flag to indicate any text between open and close tag is to be discarded */ |
| 328 | } |
| 329 | else if (strcmp(element, "prosody") == 0) /* only pitch, rate and volume attributes are supported */ |
| 330 | { |
| 331 | for (int i = 0; attributes[i]; i += 2) |
| 332 | { |
| 333 | if (strcmp(attributes[i], "pitch") == 0) |
| 334 | { |
| 335 | char* svoxpitch = convertToSvoxPitch(attributes[i+1]); |
| 336 | if (!svoxpitch) |
| 337 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 338 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | if (!svoxpitch) |
| 342 | { |
| 343 | svoxpitch = new char[4]; |
| 344 | if (!svoxpitch) |
| 345 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 346 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | strcpy(svoxpitch, "100"); |
| 350 | } |
| 351 | char* pitch = new char[17 + strlen(svoxpitch)]; |
| 352 | if (!pitch) |
| 353 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 354 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | sprintf(pitch, "<pitch level='%s'>", svoxpitch); |
| 358 | if (strlen(m_data) + strlen(pitch) + 1 > (size_t)m_datasize) |
| 359 | { |
| 360 | if (!growDataSize(100)) |
| 361 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 362 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 363 | return; |
| 364 | } |
| 365 | } |
| 366 | strcat(m_data, pitch); |
| 367 | if (!m_appendix) |
| 368 | { |
| 369 | m_appendix = new char[30]; |
| 370 | m_appendix[0] = '\0'; |
| 371 | } |
| 372 | strcat(m_appendix, "</pitch>"); |
| 373 | delete [] svoxpitch; |
| 374 | delete [] pitch; |
| 375 | } |
| 376 | else if (strcmp(attributes[i], "rate") == 0) |
| 377 | { |
| 378 | char* svoxrate = convertToSvoxRate(attributes[i+1]); |
| 379 | if (!svoxrate) |
| 380 | { |
| 381 | svoxrate = new char[4]; |
| 382 | if (!svoxrate) |
| 383 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 384 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 385 | return; |
| 386 | } |
| 387 | strcpy(svoxrate, "100"); |
| 388 | } |
| 389 | char* rate = new char[17 + strlen(svoxrate)]; |
| 390 | if (!rate) |
| 391 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 392 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | sprintf(rate, "<speed level='%s'>", svoxrate); |
| 396 | if (strlen(m_data) + strlen(rate) + 1 > (size_t)m_datasize) |
| 397 | { |
| 398 | if (!growDataSize(100)) |
| 399 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 400 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 401 | return; |
| 402 | } |
| 403 | } |
| 404 | strcat(m_data, rate); |
| 405 | if (!m_appendix) |
| 406 | { |
| 407 | m_appendix = new char[30]; |
| 408 | if (!m_appendix) |
| 409 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 410 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 411 | return; |
| 412 | } |
| 413 | m_appendix[0] = '\0'; |
| 414 | } |
| 415 | strcat(m_appendix, "</speed>"); |
| 416 | delete [] svoxrate; |
| 417 | delete [] rate; |
| 418 | } |
| 419 | else if (strcmp(attributes[i], "volume") == 0) |
| 420 | { |
| 421 | char* svoxvol = convertToSvoxVolume(attributes[i+1]); |
| 422 | if (!svoxvol) |
| 423 | { |
| 424 | svoxvol = new char[4]; |
| 425 | if (!svoxvol) |
| 426 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 427 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | strcpy(svoxvol, "100"); |
| 431 | } |
| 432 | char* volume = new char[18 + strlen(svoxvol)]; |
| 433 | if (!volume) |
| 434 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 435 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 436 | return; |
| 437 | } |
| 438 | sprintf(volume, "<volume level='%s'>", svoxvol); |
| 439 | if (strlen(m_data) + strlen(volume) + 1 > (size_t)m_datasize) |
| 440 | { |
| 441 | if (!growDataSize(100)) |
| 442 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 443 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | } |
| 447 | strcat(m_data, volume); |
| 448 | if (!m_appendix) |
| 449 | { |
| 450 | m_appendix = new char[30]; |
| 451 | m_appendix[0] = '\0'; |
| 452 | } |
| 453 | strcat(m_appendix, "</volume>"); |
| 454 | delete [] svoxvol; |
| 455 | delete [] volume; |
| 456 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 459 | else if (strcmp(element, "audio") == 0) /* only 16kHz 16bit wav files are supported as src */ |
| 460 | { |
| 461 | if (strlen(m_data) + 17 > (size_t)m_datasize) |
| 462 | { |
| 463 | if (!growDataSize(100)) |
| 464 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 465 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 466 | return; |
| 467 | } |
| 468 | } |
| 469 | strcat(m_data, "<usesig file='"); |
| 470 | |
| 471 | for (int i = 0; attributes[i]; i += 2) |
| 472 | { |
| 473 | if (strcmp(attributes[i], "src") == 0) |
| 474 | { |
| 475 | if (strlen(m_data) + strlen(attributes[i+1]) + 1 > (size_t)m_datasize) |
| 476 | { |
| 477 | if (!growDataSize(100)) |
| 478 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 479 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | } |
| 483 | strcat(m_data, attributes[i+1]); |
| 484 | } |
| 485 | } |
| 486 | strcat(m_data, "'>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | void SvoxSsmlParser::endtagHandler(void* data, const XML_Char* element) |
| 491 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 492 | ((SvoxSsmlParser*)data)->endElement(element); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | void SvoxSsmlParser::endElement(const XML_Char* element) |
| 496 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 497 | if (strcmp(element, "speak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 498 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 499 | /* do nothing */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 500 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 501 | else if (strcmp(element, "p") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 502 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 503 | if (strlen(m_data) + 5 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 504 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 505 | if (!growDataSize(100)) |
| 506 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 507 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 508 | return; |
| 509 | } |
| 510 | } |
| 511 | strcat(m_data, "</p>"); |
| 512 | } |
| 513 | else if (strcmp(element, "s") == 0) |
| 514 | { |
| 515 | if (strlen(m_data) + 5 > (size_t)m_datasize) |
| 516 | { |
| 517 | if (!growDataSize(100)) |
| 518 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 519 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 520 | return; |
| 521 | } |
| 522 | } |
| 523 | strcat(m_data, "</s>"); |
| 524 | } |
| 525 | else if (strcmp(element, "phoneme") == 0) |
| 526 | { |
| 527 | m_isInBreak = 0; /* indicate we are no longer in phoneme tag */ |
| 528 | } |
| 529 | else if (strcmp(element, "break") == 0) |
| 530 | { |
| 531 | m_isInBreak = 0; /* indicate we are no longer in break tag */ |
| 532 | } |
| 533 | else if (strcmp(element, "prosody") == 0) |
| 534 | { |
| 535 | if (m_appendix) |
| 536 | { |
| 537 | if (strlen(m_data) + strlen(m_appendix) + 1 > (size_t)m_datasize) |
| 538 | { |
| 539 | if (!growDataSize(100)) |
| 540 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 541 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 542 | return; |
| 543 | } |
| 544 | } |
| 545 | strcat(m_data, m_appendix); |
| 546 | delete [] m_appendix; |
| 547 | m_appendix = NULL; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 550 | else if (strcmp(element, "audio") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 551 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 552 | if (strlen(m_data) + 10 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 553 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 554 | if (!growDataSize(100)) |
| 555 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 556 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 559 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 560 | strcat(m_data, "</usesig>"); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
| 564 | void SvoxSsmlParser::textHandler(void* data, const XML_Char* text, int length) |
| 565 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 566 | ((SvoxSsmlParser*)data)->textElement(text, length); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | void SvoxSsmlParser::textElement(const XML_Char* text, int length) |
| 570 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 571 | if (m_isInBreak) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 572 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 573 | return; /* handles the case when someone has added text inside the break or phoneme tag - this text is thrown away */ |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 576 | char* content = new char[length + 1]; |
| 577 | if (!content) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 578 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 579 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 580 | return; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 581 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 582 | strncpy(content, text, length); |
| 583 | content[length] = '\0'; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 584 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 585 | if (strlen(m_data) + strlen(content) + 1 > (size_t)m_datasize) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 586 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 587 | if (!growDataSize(100)) |
| 588 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 589 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 590 | return; |
| 591 | } |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 592 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 593 | strcat(m_data, content); |
| 594 | delete [] content; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 598 | convertToSvoxPitch |
| 599 | Converts SSML pitch labels to SVOX pitch levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 600 | */ |
| 601 | char* SvoxSsmlParser::convertToSvoxPitch(const char* value) |
| 602 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 603 | char* converted = NULL; |
| 604 | if (strcmp(value, "x-low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 605 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 606 | converted = new char[4]; |
| 607 | if (!converted) |
| 608 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 609 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 610 | return NULL; |
| 611 | } |
| 612 | strcpy(converted, SSML_PITCH_XLOW); |
| 613 | } |
| 614 | else if (strcmp(value, "low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 615 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 616 | converted = new char[4]; |
| 617 | if (!converted) |
| 618 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 619 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 620 | return NULL; |
| 621 | } |
| 622 | strcpy(converted, SSML_PITCH_LOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 623 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 624 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 625 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 626 | converted = new char[4]; |
| 627 | if (!converted) |
| 628 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 629 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 630 | return NULL; |
| 631 | } |
| 632 | strcpy(converted, SSML_PITCH_MEDIUM); |
| 633 | } |
| 634 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 635 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 636 | converted = new char[4]; |
| 637 | if (!converted) |
| 638 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 639 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 640 | return NULL; |
| 641 | } |
| 642 | strcpy(converted, SSML_PITCH_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 643 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 644 | else if (strcmp(value, "high") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 645 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 646 | converted = new char[4]; |
| 647 | if (!converted) |
| 648 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 649 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 650 | return NULL; |
| 651 | } |
| 652 | strcpy(converted, SSML_PITCH_HIGH); |
| 653 | } |
| 654 | else if (strcmp(value, "x-high") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 655 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 656 | converted = new char[4]; |
| 657 | if (!converted) |
| 658 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 659 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 660 | return NULL; |
| 661 | } |
| 662 | strcpy(converted, SSML_PITCH_XHIGH); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 663 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 664 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 668 | convertToSvoxRate |
| 669 | Converts SSML rate labels to SVOX speed levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 670 | */ |
| 671 | char* SvoxSsmlParser::convertToSvoxRate(const char* value) |
| 672 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 673 | char* converted = NULL; |
| 674 | if (strcmp(value, "x-slow") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 675 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 676 | converted = new char[4]; |
| 677 | if (!converted) |
| 678 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 679 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 680 | return NULL; |
| 681 | } |
| 682 | strcpy(converted, SSML_RATE_XSLOW); |
| 683 | } |
| 684 | else if (strcmp(value, "slow") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 685 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 686 | converted = new char[4]; |
| 687 | if (!converted) |
| 688 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 689 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 690 | return NULL; |
| 691 | } |
| 692 | strcpy(converted, SSML_RATE_SLOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 693 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 694 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 695 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 696 | converted = new char[4]; |
| 697 | if (!converted) |
| 698 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 699 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 700 | return NULL; |
| 701 | } |
| 702 | strcpy(converted, SSML_RATE_MEDIUM); |
| 703 | } |
| 704 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 705 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 706 | converted = new char[4]; |
| 707 | if (!converted) |
| 708 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 709 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 710 | return NULL; |
| 711 | } |
| 712 | strcpy(converted, SSML_RATE_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 713 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 714 | else if (strcmp(value, "fast") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 715 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 716 | converted = new char[4]; |
| 717 | if (!converted) |
| 718 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 719 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 720 | return NULL; |
| 721 | } |
| 722 | strcpy(converted, SSML_RATE_FAST); |
| 723 | } |
| 724 | else if (strcmp(value, "x-fast") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 725 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 726 | converted = new char[4]; |
| 727 | if (!converted) |
| 728 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 729 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 730 | return NULL; |
| 731 | } |
| 732 | strcpy(converted, SSML_RATE_XFAST); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 733 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 734 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 738 | convertToSvoxVolume |
| 739 | Converts SSML volume labels to SVOX volume levels |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 740 | */ |
| 741 | char* SvoxSsmlParser::convertToSvoxVolume(const char* value) |
| 742 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 743 | char* converted = NULL; |
| 744 | if (strcmp(value, "silent") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 745 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 746 | converted = new char[4]; |
| 747 | if (!converted) |
| 748 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 749 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 750 | return NULL; |
| 751 | } |
| 752 | strcpy(converted, SSML_VOLUME_SILENT); |
| 753 | } |
| 754 | else if (strcmp(value, "x-low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 755 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 756 | converted = new char[4]; |
| 757 | if (!converted) |
| 758 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 759 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 760 | return NULL; |
| 761 | } |
| 762 | strcpy(converted, SSML_VOLUME_XLOW); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 763 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 764 | else if (strcmp(value, "low") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 765 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 766 | converted = new char[4]; |
| 767 | if (!converted) |
| 768 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 769 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 770 | return NULL; |
| 771 | } |
| 772 | strcpy(converted, SSML_VOLUME_LOW); |
| 773 | } |
| 774 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 775 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 776 | converted = new char[4]; |
| 777 | if (!converted) |
| 778 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 779 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 780 | return NULL; |
| 781 | } |
| 782 | strcpy(converted, SSML_VOLUME_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 783 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 784 | else if (strcmp(value, "default") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 785 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 786 | converted = new char[4]; |
| 787 | if (!converted) |
| 788 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 789 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 790 | return NULL; |
| 791 | } |
| 792 | strcpy(converted, SSML_VOLUME_MEDIUM); |
| 793 | } |
| 794 | else if (strcmp(value, "loud") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 795 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 796 | converted = new char[4]; |
| 797 | if (!converted) |
| 798 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 799 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 800 | return NULL; |
| 801 | } |
| 802 | strcpy(converted, SSML_VOLUME_LOUD); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 803 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 804 | else if (strcmp(value, "x-loud") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 805 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 806 | converted = new char[4]; |
| 807 | if (!converted) |
| 808 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 809 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 810 | return NULL; |
| 811 | } |
| 812 | strcpy(converted, SSML_VOLUME_XLOUD); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 813 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 814 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 818 | convertBreakStrengthToTime |
| 819 | Converts SSML break strength labels to SVOX break time |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 820 | */ |
| 821 | char* SvoxSsmlParser::convertBreakStrengthToTime(const char* value) |
| 822 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 823 | char* converted = NULL; |
| 824 | if (strcmp(value, "none") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 825 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 826 | converted = new char[6]; |
| 827 | if (!converted) |
| 828 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 829 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 830 | return NULL; |
| 831 | } |
| 832 | strcpy(converted, SSML_BREAK_NONE); |
| 833 | } |
| 834 | else if (strcmp(value, "x-weak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 835 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 836 | converted = new char[6]; |
| 837 | if (!converted) |
| 838 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 839 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 840 | return NULL; |
| 841 | } |
| 842 | strcpy(converted, SSML_BREAK_XWEAK); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 843 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 844 | else if (strcmp(value, "weak") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 845 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 846 | converted = new char[6]; |
| 847 | if (!converted) |
| 848 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 849 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 850 | return NULL; |
| 851 | } |
| 852 | strcpy(converted, SSML_BREAK_WEAK); |
| 853 | } |
| 854 | else if (strcmp(value, "medium") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 855 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 856 | converted = new char[6]; |
| 857 | if (!converted) |
| 858 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 859 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 860 | return NULL; |
| 861 | } |
| 862 | strcpy(converted, SSML_BREAK_MEDIUM); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 863 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 864 | else if (strcmp(value, "strong") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 865 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 866 | converted = new char[6]; |
| 867 | if (!converted) |
| 868 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 869 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 870 | return NULL; |
| 871 | } |
| 872 | strcpy(converted, SSML_BREAK_STRONG); |
| 873 | } |
| 874 | else if (strcmp(value, "x-strong") == 0) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 875 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 876 | converted = new char[6]; |
| 877 | if (!converted) |
| 878 | { |
Steve Block | 31a809c | 2012-01-06 19:10:34 +0000 | [diff] [blame] | 879 | ALOGE("Error: failed to allocate memory for string!\n"); |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 880 | return NULL; |
| 881 | } |
| 882 | strcpy(converted, SSML_BREAK_XSTRONG); |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 883 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 884 | return converted; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /** |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 888 | growDataSize |
| 889 | Increases the size of the internal text storage member |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 890 | */ |
| 891 | int SvoxSsmlParser::growDataSize(int sizeToGrow) |
| 892 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 893 | char* tmp = new char[m_datasize]; |
| 894 | if (!tmp) |
| 895 | return 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 896 | |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 897 | strcpy(tmp, m_data); |
| 898 | delete [] m_data; |
| 899 | m_data = NULL; |
| 900 | m_data = new char[m_datasize + sizeToGrow]; |
| 901 | if (!m_data) |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 902 | { |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 903 | m_data = tmp; |
| 904 | return 0; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 905 | } |
Jean-Michel Trivi | 4bbdb2d | 2009-07-08 12:22:43 -0700 | [diff] [blame] | 906 | m_datasize += sizeToGrow; |
| 907 | strcpy(m_data, tmp); |
| 908 | delete [] tmp; |
| 909 | tmp = NULL; |
| 910 | return 1; |
Jean-Michel Trivi | 39358f0 | 2009-07-01 18:13:11 -0700 | [diff] [blame] | 911 | } |