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 * 16 */ 17 18 #include <stdio.h> 19 #include <stdlib.h> 20 #include <libexpat/expat.h> 21 22 #ifndef _SVOX_SSML_PARSER_H_ 23 #define _SVOX_SSML_PARSER_H_ 24 25 /** 26 * SvoxSsmlParser 27 * Parses SSML 1.0 XML documents and convertes it to Pico compatible text input 28 */ 29 class SvoxSsmlParser 30 { 31 public: /* construction code */ 32 33 /** 34 Constructor 35 Creates Expat parser and allocates initial text storage 36 */ 37 SvoxSsmlParser(); 38 39 /** 40 Destructor 41 Deallocates all resources 42 */ 43 ~SvoxSsmlParser(); 44 45 /** 46 initSuccessful 47 Verifies that construction was successful 48 return 1 if successful, 0 otherwise 49 */ 50 int initSuccessful(); 51 52 public: /* public members */ 53 54 /** 55 parseDocument 56 Parses SSML 1.0 document passed in as argument 57 @ssmldoc - SSML document, partial document input is supported 58 @isFinal - indicates whether input is a complete or partial document, 1 indicates complete document, 0 indicates partial 59 return Expat status code 60 */ 61 int parseDocument(const char* ssmldoc, int isFinal); 62 63 /** 64 getParsedDocument 65 Returns string containing parse result. This can be passed on to Pico for synthesis 66 return parsed string, NULL if error occurred 67 */ 68 char* getParsedDocument(); 69 70 /** 71 getParsedDocumentLanguage 72 Returns language string specified in xml:lang attribute of the <speak> tag 73 return language code of SSML document, NULL if not set 74 */ 75 char* getParsedDocumentLanguage(); 76 77 private: /* static callback functions */ 78 79 /** 80 starttagHandler 81 Static callback function for Expat start-tag events, internal use only 82 */ 83 static void starttagHandler(void* data, const XML_Char* element, const XML_Char** attributes); 84 85 /** 86 endtagHandler 87 Static callback function for Expat end-tag events, internal use only 88 */ 89 static void endtagHandler(void* data, const XML_Char* element); 90 91 /** 92 textHandler 93 Static callback function for Expat text events, internal use only 94 */ 95 static void textHandler(void* data, const XML_Char* text, int length); 96 97 private: /* element handlers */ 98 99 /** 100 startElement 101 Handles start of element, called by starttagHandler. 102 */ 103 void startElement(const XML_Char* element, const XML_Char** attributes); 104 105 /** 106 endElement 107 Handles end of element, called by endtagHandler. 108 */ 109 void endElement(const XML_Char* element); 110 111 /** 112 textElement 113 Handles text element, called by textHandler. 114 */ 115 void textElement(const XML_Char* text, int length); 116 117 /* helper functions */ 118 119 /** 120 convertToSvoxPitch 121 Convertes SSML prosody tag pitch values to SVOX Pico pitch values. 122 */ 123 char* convertToSvoxPitch(const char* value); 124 125 /** 126 convertToSvoxRate 127 Convertes SSML prosody tag rate values to SVOX Pico speed values. 128 */ 129 char* convertToSvoxRate(const char* value); 130 131 /** 132 convertToSvoxVolume 133 Convertes SSML prosody tag volume values to SVOX Pico volume values. 134 */ 135 char* convertToSvoxVolume(const char* value); 136 137 /** 138 convertBreakStrengthToTime 139 Convertes SSML break tag strength attribute values to SVOX Pico break time values. 140 */ 141 char* convertBreakStrengthToTime(const char* value); 142 143 /** 144 growDataSize 145 Increases size of internal text field. 146 */ 147 int growDataSize(int sizeToGrow); 148 149 private: /* data members*/ 150 151 char* m_data; /* internal text field, holds parsed text */ 152 int m_datasize; /* size of internal text field */ 153 XML_Parser mParser; /* Expat XML parser pointer */ 154 int m_isInBreak; /* indicator for handling break tag parsing */ 155 char* m_appendix; /* holds Pico pitch, speed and volume close tags for prosody tag parsing */ 156 char* m_docLanguage; /* language set in speak tag of SSML document */ 157 }; 158 159 #endif // _SVOX_SSML_PARSER_H_ 160