static void unload_voice_plugins(SList *plugins, s_erc *error) { SIterator *itr; SObject *plugin; S_CLR_ERR(error); itr = S_ITERATOR_GET(plugins, error); if (S_CHK_ERR(error, S_CONTERR, "unload_voice_plugins", "Call to \"S_ITERATOR_GET\" failed")) return; while (itr != NULL) { plugin = SIteratorUnlink(itr, error); if (S_CHK_ERR(error, S_CONTERR, "unload_voice_plugins", "Call to \"SIteratorUnlink\" failed")) { S_DELETE(itr, "unload_voice_plugins", error); return; } S_DELETE(plugin, "unload_voice_plugins", error); itr = SIteratorNext(itr); } S_DELETE(plugins, "unload_voice_plugins", error); }
static void DestroyUtt(void *obj, s_erc *error) { SUtterance *self = obj; SIterator *itr; SRelation *rel; S_CLR_ERR(error); s_mutex_lock(&(self->utt_mutex)); S_DELETE(self->features, "DestroyUtt", error); /* Relations don't delete their contents (no dispose) */ itr = S_ITERATOR_GET(self->relations, error); if (S_CHK_ERR(error, S_CONTERR, "DestroyUtt", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(self->relations, "DestroyUtt", error); s_mutex_unlock(&(self->utt_mutex)); s_mutex_destroy(&(self->utt_mutex)); return; } while (itr) { rel = S_RELATION(SIteratorUnlink(itr, error)); if (S_CHK_ERR(error, S_CONTERR, "DestroyUtt", "Call to \"SMapIteratorUnlink\" failed")) { S_DELETE(self->relations, "DestroyUtt", error); S_DELETE(itr, "DestroyUtt", error); s_mutex_unlock(&(self->utt_mutex)); s_mutex_destroy(&(self->utt_mutex)); return; } S_FORCE_DELETE(rel, "DestroyUtt", error); itr = SIteratorNext(itr); } S_DELETE(self->relations, "DestroyUtt", error); s_mutex_unlock(&(self->utt_mutex)); s_mutex_destroy(&(self->utt_mutex)); s_mutex_destroy(&(self->utt_id_mutex)); }
_PMapIterator *__iter__() { _PMapIterator *pitr; SIterator *itr; s_erc error; S_CLR_ERR(&error); itr = S_ITERATOR_GET($self->relations, &error); if (error != S_SUCCESS) return NULL; pitr = _make_PMapIterator(itr, &error); if (error != S_SUCCESS) return NULL; return pitr; }
static void Run(const SUttProcessor *self, SUtterance *utt, s_erc *error) { SG2P *g2p = NULL; SLexicon *lexicon = NULL; SAddendum *addendum = NULL; SSyllabification *syllab = NULL; const SRelation *wordRel; SRelation *syllableRel = NULL; SRelation *sylStructRel = NULL; SRelation *segmentRel = NULL; SItem *wordItem; char *downcase_word; SList *phones; s_bool syllabified; SList *syllablesPhones; SItem *sylStructureWordItem; SItem *syllableItem; SItem *sylStructSylItem; SItem *segmentItem; SIterator *sylItr = NULL; SIterator *phoneItr = NULL; const SObject *phone; s_bool is_present; S_CLR_ERR(error); s_get_lexical_objects(self, utt, &g2p, &lexicon, &addendum, &syllab, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_get_lexical_objects\" failed")) goto quit_error; /* we require the word relation */ is_present = SUtteranceRelationIsPresent(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit_error; if (!is_present) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to find 'Word' relation in utterance"); goto quit_error; } wordRel = SUtteranceGetRelation(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) goto quit_error; /* create relations */ syllableRel = SUtteranceNewRelation(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; sylStructRel = SUtteranceNewRelation(utt, "SylStructure", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; segmentRel = SUtteranceNewRelation(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceNewRelation\" failed")) goto quit_error; /* start at the first item in the word relation, cast away * const, we want to add daughter items. * iterate over the word relation and fill in the * phones and the associated structure. */ wordItem = (SItem*)SRelationHead(wordRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; while (wordItem != NULL) { /* get word and downcase it */ downcase_word = s_strlwr(s_strdup(SItemGetName(wordItem, error), error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to down-case word item")) goto quit_error; if (downcase_word == NULL || s_strcmp(downcase_word, "", error) == 0) goto continue_cycle; phones = NULL; syllabified = FALSE; /* get phone sequence for word */ if (addendum != NULL) { phones = S_ADDENDUM_CALL(addendum, get_word)(addendum, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SAddendum) failed")) goto quit_error; } if ((phones == NULL) && (lexicon != NULL)) { phones = S_LEXICON_CALL(lexicon, get_word)(lexicon, downcase_word, NULL, &syllabified, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"get_word\" (SLexicon) failed")) goto quit_error; } if ((phones == NULL) && (g2p != NULL)) { phones = S_G2P_CALL(g2p, apply)(g2p, downcase_word, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"apply\" (SG2P) failed")) goto quit_error; } if (phones == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to get phone sequence for word '%s'", downcase_word); S_FREE(downcase_word); continue; } S_FREE(downcase_word); /* syllabify phone sequence */ if (syllabified == FALSE) { if (syllab != NULL) { syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab, wordItem, phones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to method \"syllabify\" failed")) goto quit_error; S_DELETE(phones, "Run", error); } else { syllablesPhones = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to create new 'SList' object")) goto quit_error; SListAppend(syllablesPhones, S_OBJECT(phones), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SListAppend\" failed")) goto quit_error; } } else syllablesPhones = (SList*)phones; /* create new syllable structure word item, shares content * with word item. */ sylStructureWordItem = SRelationAppend(sylStructRel, wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; /* iterate over syllables */ sylItr = S_ITERATOR_GET(syllablesPhones, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET\" failed")) goto quit_error; while (sylItr != NULL) { /* new item in syllable relation */ syllableItem = SRelationAppend(syllableRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(syllableItem, "syl", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName\" failed")) goto quit_error; /* daughter of above item, but in SylStructure */ sylStructSylItem = SItemAddDaughter(sylStructureWordItem, syllableItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; /* iterate over phones and add segments */ phoneItr = S_ITERATOR_GET((SList*)SIteratorObject(sylItr, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"S_ITERATOR_GET/SIteratorObject\" failed")) goto quit_error; while (phoneItr != NULL) { phone = SIteratorObject(phoneItr, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SIteratorObject\" failed")) goto quit_error; segmentItem = SRelationAppend(segmentRel, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationAppend\" failed")) goto quit_error; SItemSetName(segmentItem, SObjectGetString(phone, error), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetName/SObjectGetString\" failed")) goto quit_error; SItemAddDaughter(sylStructSylItem, segmentItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemAddDaughter\" failed")) goto quit_error; phoneItr = SIteratorNext(phoneItr); } sylItr = SIteratorNext(sylItr); } S_DELETE(syllablesPhones, "Run", error); continue_cycle: wordItem = SItemNext(wordItem, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemNext\" failed")) goto quit_error; } /* here all is OK */ return; /* error clean-up code */ quit_error: if (syllableRel != NULL) { SUtteranceDelRelation(utt, "Syllable", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylStructRel != NULL) { SUtteranceDelRelation(utt, "SylStructure", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (segmentRel != NULL) { SUtteranceDelRelation(utt, "Segment", error); S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceDelRelation\" failed"); } if (sylItr != NULL) S_DELETE(sylItr, "Run", error); if (phoneItr != NULL) S_DELETE(phoneItr, "Run", error); self = NULL; }
S_LOCAL void _s_load_voice_utterance_processors(const SMap *voiceConfig, SVoice *voice, s_erc *error) { SMap *uttProcessors; const SObject *tmp; const SMap *voiceConfigUttProcessors; s_bool key_present; SIterator *itr; const char *uttproc_name; const char *uttproc_class; const char *uttproc_plugin; const SMap *uttProcInfo; const SMap *uttProcFeats; SUttProcessor *uProcessor; SPlugin *plugin; SList *uttProcPlugins; S_CLR_ERR(error); /* create a map container for utterance-processors */ uttProcessors = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Failed to create new map for voice utterance-processors")) return; /* look for "utterance-processors" key in voiceConfig map */ key_present = SMapObjectPresent(voiceConfig, "utterance-processors", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapObjectPresent\" failed for \'utterance-processors\' key")) { S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); return; } if (!key_present) { /* no defined utterance-processors */ voice->uttProcessors = uttProcessors; return; } /* get utterance-processors from voiceConfig */ tmp = SMapGetObject(voiceConfig, "utterance-processors", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapGetObject\" failed")) { S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); return; } voiceConfigUttProcessors = S_CAST(tmp, SMap, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"S_CAST (SMap)\" failed for \'utterance-processors\' object")) { S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); return; } /* * iterate through the voiceConfigUttProcessors, create the * utterance-processors and add their features (if any), and add * them to the uttProcessors map */ itr = S_ITERATOR_GET(voiceConfigUttProcessors, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); return; } if (itr) { /* create a plug-in list */ uttProcPlugins = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Failed to create new list for voice utterance-processor plug-ins")) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); return; } } else uttProcPlugins = NULL; while (itr) { /* the utterance-processor name */ uttproc_name = SIteratorKey(itr, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SIteratorKey\" failed")) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* the utterance-processor info (SMap) */ tmp = SIteratorObject(itr, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SIteratorObject\" failed")) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } uttProcInfo = S_CAST(tmp, SMap, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"S_CAST (SMap)\" failed for utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* * uttProcInfo must have "class" and "plug-in" and * optionally "features" */ uttproc_class = SMapGetString(uttProcInfo, "class", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapGetString\" failed for \'class\' name of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } uttproc_plugin = SMapGetString(uttProcInfo, "plug-in", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapGetString\" failed for \'plug-in\' name of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* * load the plug-in, add it to the list of utterance-processor plug-ins and create * the utterance-processor object */ plugin = s_pm_load_plugin(uttproc_plugin, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"s_pm_load_plugin\" failed for utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } SListPush(uttProcPlugins, S_OBJECT(plugin), error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SListPush\" failed for utterance-processor plug-ins")) { S_DELETE(plugin, "_s_load_voice_utterance_processors", error); S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } uProcessor = S_UTTPROCESSOR(S_NEW_FROM_NAME(uttproc_class, error)); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Failed to create new utterance-processor of class \'%s\'", uttproc_class)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* add the utterance-processor to the map of utterance-processors */ SMapSetObject(uttProcessors, uttproc_name, S_OBJECT(uProcessor), error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapSetObject\" failed")) { S_DELETE(uProcessor, "_s_load_voice_utterance_processors", error); S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* Check if this utterance-processor has any defined features */ key_present = SMapObjectPresent(uttProcInfo, "features", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapObjectPresent\" failed for \'features\' key of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } if (key_present) { /* get utterance-processors "features" */ tmp = SMapGetObject(uttProcInfo, "features", error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapGetObject\" failed for \'features\' of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } uttProcFeats = S_CAST(tmp, SMap, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"S_CAST (SMap)\" failed for \'features\' of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } /* copy them to the utterance-processor */ SMapCopy(uProcessor->features, uttProcFeats, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SMapCopy\" failed for \'features\' of utterance-processor \'%s\'", uttproc_name)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } } /* initialize the utterance processor */ SUttProcessorInit(&uProcessor, voice, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SUttProcessorInit\" failed for utterance-processor of class \'%s\'", uttproc_class)) { S_DELETE(itr, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } itr = SIteratorNext(itr); } if (uttProcPlugins != NULL) { SListMerge(voice->plugins, uttProcPlugins, error); if (S_CHK_ERR(error, S_CONTERR, "_s_load_voice_utterance_processors", "Call to \"SListMerge\" failed")) { S_DELETE(uttProcessors, "_s_load_voice_utterance_processors", error); S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); return; } S_DELETE(uttProcPlugins, "_s_load_voice_utterance_processors", error); } voice->uttProcessors = uttProcessors; }
void __setitem__(int key, PyObject *val, s_erc *error) { SIterator *itr; uint32 i; s_bool found_point; SObject *toDelete; SObject *newObject; uint32 n = (uint32)key; size_t num_objects; S_CLR_ERR(error); num_objects = SListSize($self, error); if (*error != S_SUCCESS) return; if ((key >= (int)num_objects) || (key < 0)) { PyErr_SetString(PyExc_IndexError, "Given key index out of bounds"); return; } itr = S_ITERATOR_GET(self, error); if (*error != S_SUCCESS) return; i = 0; found_point = FALSE; while (itr) { if (i == n) { found_point = TRUE; break; } i++; itr = SIteratorNext(itr); } if ((!found_point) || (!itr)) { S_CTX_ERR(error, S_FAILURE, "SList::__setitem__()", "Failed to find item to replace"); if (itr) S_DELETE(itr, "SList::__setitem__()", error); return; } newObject = s_pyobject_2_sobject(val, error); if (*error != S_SUCCESS) return; SListInsertBefore(self, itr, newObject, error); if (*error != S_SUCCESS) { S_DELETE(newObject, "SList::__setitem__()", error); S_DELETE(itr, "SList::__setitem__()", error); return; } toDelete = SIteratorUnlink(itr, error); if (*error != S_SUCCESS) { S_DELETE(itr, "SList::__setitem__()", error); return; } S_DELETE(itr, "SList::__setitem__()", error); S_DELETE(toDelete, "SList::__setitem__()", error); }
void __delitem__(int key, s_erc *error) { SIterator *itr; uint32 i; s_bool found_point; SObject *toDelete; uint32 n = (uint32)key; size_t num_objects; S_CLR_ERR(error); num_objects = SListSize($self, error); if (*error != S_SUCCESS) return; if ((key >= (int)num_objects) || (key < 0)) { PyErr_SetString(PyExc_IndexError, "Given key index out of bounds"); return; } itr = S_ITERATOR_GET($self, error); if (*error != S_SUCCESS) { PyErr_SetString(PyExc_RuntimeError, "Failed to get list iterator"); return; } i = 0; found_point = FALSE; while (itr) { if (i == n) { found_point = TRUE; break; } i++; itr = SIteratorNext(itr); } if ((!found_point) || (!itr)) { S_CTX_ERR(error, S_FAILURE, "SList::__delitem__()", "Failed to find item to delete"); if (itr) S_DELETE(itr, "SList::__delitem__()", error); return; } toDelete = SIteratorUnlink(itr, error); if (*error != S_SUCCESS) { S_DELETE(itr, "SList::__delitem__()", error); return; } S_DELETE(itr, "SList::__delitem__()", error); S_DELETE(toDelete, "SList::__delitem__()", error); }
static void get_windows(const SList *windows, char ***cwindows, int *num, const char *voice_base_path, s_erc *error) { size_t tsize; SIterator *itr; int counter; S_CLR_ERR(error); tsize = SListSize(windows, error); if (S_CHK_ERR(error, S_CONTERR, "get_windows", "Call to \"SListSize\" failed")) return; *num = tsize; *cwindows = S_CALLOC(char*, tsize); if (*cwindows == NULL) { S_FTL_ERR(error, S_MEMERROR, "get_windows", "Failed to allocate memory for 'char*' object"); return; } itr = S_ITERATOR_GET(windows, error); if (S_CHK_ERR(error, S_CONTERR, "get_windows", "Call to \"S_ITERATOR_GET\" failed")) { S_FREE(*cwindows); return; } counter = 0; while (itr != NULL) { const char *tmp; tmp = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "get_windows", "Call to \"SIteratorObject/SObjectGetString\" failed")) { S_FREE(*cwindows); return; } /* get data path, the one in the config file may be relative * to the voice base path */ (*cwindows)[counter++] = s_path_combine(voice_base_path, tmp, error); if (S_CHK_ERR(error, S_CONTERR, "get_windows", "Call to \"s_path_combine\" failed")) { S_FREE(*cwindows); return; } itr = SIteratorNext(itr); } }
int main() { s_erc error = S_SUCCESS; SList *list = NULL; SIterator *itr; SObject *a = NULL; SObject *b = NULL; SObject *c = NULL; PyObject *speectModule = NULL; /* for SWIG functions to work */ /* Initialize the Python interpreter. Required. */ Py_Initialize(); /* import speect python module */ speectModule = PyImport_ImportModule("speect"); if (speectModule == NULL) { char *py_error = s_get_python_error_str(); if (py_error) { S_CTX_ERR(&error, S_FAILURE, "main", "Call to \"PyImport_ImportModule\" failed. Reported error: %s", py_error); S_FREE(py_error); } else { S_CTX_ERR(&error, S_FAILURE, "main", "Call to \"PyImport_ImportModule\" failed"); } goto quit; } /* * initialize speect python native module */ error = s_python_native_objects_init(); if (error != S_SUCCESS) { printf("Failed to initialize Speect Python native module\n"); goto quit; } /* Create and populate Python list */ list = create_and_populate_py_list(&error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"create_and_populate_py_list\" failed")) goto quit; /* * get iterator to list, should be NULL as there are no objects * in the list */ itr = S_ITERATOR_GET(list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get iterator to list")) goto quit; /* Create some objects and put the into the list */ a = SObjectSetInt(10, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set int object")) goto quit; b = SObjectSetFloat(3.14, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set float object")) goto quit; c = SObjectSetString("python list test", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to set string object")) goto quit; SListPush(list, a, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else a = NULL; /* object belongs to list now, we don't want to * delete it directly. */ SListPush(list, b, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else b = NULL; /* object belongs to list now, we don't want to * delete it directly. */ SListPush(list, c, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to add object to list")) goto quit; else c = NULL; /* object belongs to list now, we don't want to * delete it directly. */ /* * get iterator to list, should not be NULL as there are now * objects in the list */ itr = S_ITERATOR_GET(list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get iterator to list")) goto quit; /* iterate through list objects and print them to stdout */ for (/* NOP */; itr != NULL; itr = SIteratorNext(itr)) { char *buf; const SObject *tmp; tmp = SIteratorObject(itr, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get list iterator object")) goto quit; buf = SObjectPrint(tmp, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to print object")) goto quit; printf("list object = %s\n", buf); S_FREE(buf); } quit: if (list != NULL) S_DELETE(list, "main", &error); if (itr != NULL) S_DELETE(itr, "main", &error); if (a != NULL) S_DELETE(a, "main", &error); if (b != NULL) S_DELETE(b, "main", &error); if (c != NULL) S_DELETE(c, "main", &error); Py_XDECREF(speectModule); Py_Finalize(); return 0; }
static void read_g2p_rewrites_zeros(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error) { uint32 id; SList *tmpZeros; size_t list_size; SIterator *itr; s_bool container_exhausted; s_gzero *tmp; S_CLR_ERR(error); /* read S_G2PREWRITES_EBML_ZEROS container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"container\" failed")) return; /* create a temporary SList storage */ tmpZeros = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Failed to create new 'SList' object")) return; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"container_at_end\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } if (container_exhausted) break; /* peek id */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"peek_id\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } switch(id) { case S_G2PREWRITES_EBML_ZEROS_SYMBOL: { char *symbol; symbol = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"read_utf8\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* put symbol in list */ SListAppend(tmpZeros, SObjectSetString(symbol, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListAppend\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_FREE(symbol); return; } S_FREE(symbol); break; } case S_G2PREWRITES_EBML_ZEROS_REPLACEMENT: { char *replacement; replacement = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"read_utf8\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* put replacement in list */ SListAppend(tmpZeros, SObjectSetString(replacement, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListAppend\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_FREE(replacement); return; } S_FREE(replacement); break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_zeros", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "ebmlRead method \"element_skip\" failed")) return; } } /* get list size */ list_size = SListSize(tmpZeros, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListSize\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* make sure it is divisible by 2 */ if (list_size%2 != 0) { S_CTX_ERR(error, S_FAILURE, "read_g2p_rewrites_zeros", "Number of read symbol/replacement zero's not divisible by 2"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } /* create zeros structure */ g2p->zeros = S_CALLOC(s_gzero, list_size + 1); if (g2p->zeros == NULL) { S_FTL_ERR(error, S_MEMERROR, "read_g2p_rewrites_zeros", "Failed to allocate memory for 's_gzero' object"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } itr = S_ITERATOR_GET(tmpZeros, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } tmp = g2p->zeros; while (itr != NULL) { const char *symbol; const char *replacement; symbol = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SIteratorObject/SObjectGetString\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } tmp->symbol = s_strdup(symbol, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"s_strdup\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } itr = SIteratorNext(itr); if (itr == NULL) { S_CTX_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Expected replacement zero is NULL"); S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; } replacement = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"SListIterator/SObjectGetString\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } tmp->replacement = s_strdup(replacement, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_zeros", "Call to \"s_strdup\" failed")) { S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); S_DELETE(itr, "read_g2p_rewrites_zeros", error); return; } itr = SIteratorNext(itr); tmp++; } S_DELETE(tmpZeros, "read_g2p_rewrites_zeros", error); return; }
static void ReSynthUtt(const SVoice *self, const char *utt_type, SUtterance *utt, s_erc *error) { const SList *uttType; const SUttProcessor *uttProc; /* utterance processor */ const char *utt_processor_name; SIterator *itr; S_CLR_ERR(error); uttType = SVoiceGetUttType(self, utt_type, error); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Call to \"SVoiceGetUttType\" failed")) return; SUtteranceSetFeature(utt, "utterance-type", SObjectSetString(utt_type, error), error); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Failed to set utterance \'utterance-type\' feature")) return; /* run utterance processors on utterance */ itr = S_ITERATOR_GET(uttType, error); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Call to \"S_ITERATOR_GET\" failed")) return; for (/* NOP */; itr != NULL; itr = SIteratorNext(itr)) { /* get utterance processor name */ utt_processor_name = SObjectGetString(SIteratorObject(itr, error), error); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Failed to get utterance processor name")) { S_DELETE(itr, "ReSynthUtt", error); return; } uttProc = S_UTTPROCESSOR(SMapGetObjectDef(self->uttProcessors, utt_processor_name, NULL, error)); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Call to \"SMapGetObjectDef\" failed")) { S_DELETE(itr, "ReSynthUtt", error); return; } if (uttProc == NULL) { S_CTX_ERR(error, S_FAILURE, "ReSynthUtt", "Utterance processor \'%s\' not defined", utt_processor_name); S_DELETE(itr, "ReSynthUtt", error); return; } S_DEBUG(S_DBG_INFO, "executing \'%s\' utterance processor ...", utt_processor_name); SUttProcessorRun(uttProc, utt, error); if (S_CHK_ERR(error, S_CONTERR, "ReSynthUtt", "Execution of utterance processor \'%s\' failed", utt_processor_name)) { S_DELETE(itr, "ReSynthUtt", error); return; } } }
static void DestroyVoice(void *obj, s_erc *error) { SVoice *self = obj; SIterator *itr; const char *data_name; S_CLR_ERR(error); s_mutex_lock(&self->voice_mutex); free_voice_info(self->info); if (self->features != NULL) S_DELETE(self->features, "DestroyVoice", error); if (self->featProcessors != NULL) S_DELETE(self->featProcessors, "DestroyVoice", error); if (self->uttProcessors != NULL) S_DELETE(self->uttProcessors, "DestroyVoice", error); if (self->uttTypes != NULL) S_DELETE(self->uttTypes, "DestroyVoice", error); if (self->plugins != NULL) { unload_voice_plugins(self->plugins, error); S_CHK_ERR(error, S_CONTERR, "DestroyVoice", "Call to \"unload_voice_plugins\" failed"); } if (self->data != NULL) { /* * now iterate through data config and delete everything */ itr = S_ITERATOR_GET(self->data->dataObjects, error); if (S_CHK_ERR(error, S_CONTERR, "DestroyVoice", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(itr, "DestroyVoice", error); /* * leave data objects, this will probably cause * memory leaks, but at the risk of deleting * shared data. */ S_FREE(self->data); s_mutex_unlock(&self->voice_mutex); s_mutex_destroy(&self->voice_mutex); return; } while (itr) { data_name = SIteratorKey(itr, error); if (S_CHK_ERR(error, S_CONTERR, "DestroyVoice", "Call to \"SIteratorKey\" failed")) { S_DELETE(itr, "DestroyVoice", error); /* * leave data objects, this will probably cause * memory leaks, but at the risk of deleting * shared data. */ S_FREE(self->data); s_mutex_unlock(&self->voice_mutex); s_mutex_destroy(&self->voice_mutex); return; } unload_data_entry(self, data_name, error); if (S_CHK_ERR(error, S_CONTERR, "DestroyVoice", "Call to \"unload_data_entry\" failed")) { S_DELETE(itr, "DestroyVoice", error); /* * leave data objects, this will probably cause * memory leaks, but at the risk of deleting * shared data. */ S_FREE(self->data); s_mutex_unlock(&self->voice_mutex); s_mutex_destroy(&self->voice_mutex); return; } itr = SIteratorNext(itr); } S_DELETE(self->data->dataObjects, "DestroyVoice", error); S_FREE(self->data); } s_mutex_unlock(&self->voice_mutex); s_mutex_destroy(&self->voice_mutex); }
S_LOCAL void _s_voice_load_data(SVoice *self, const SMap *dataConfig, s_erc *error) { SIterator *itr; const char *data_name; const SObject *loaded; const SMap *dataObjectMap; s_data_info *data_info; const SObject *vcfgObject; char *voice_base_path; S_CLR_ERR(error); if (self == NULL) { S_CTX_ERR(error, S_ARGERROR, "_s_voice_load_data", "Argument \"self\" is NULL"); return; } /* get voice base path */ vcfgObject = SVoiceGetFeature(self, "config_file", error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"SVoiceGetFeature\" failed, failed to get voice config file")) return; voice_base_path = s_get_base_path(SObjectGetString(vcfgObject, error), error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"s_get_base_path/SObjectGetString\" failed")) return; /* * now iterate through data config and load everything */ itr = S_ITERATOR_GET(dataConfig, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } while (itr) { char *combined_path; data_name = SIteratorKey(itr, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"SIteratorKey\" failed")) { S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } /* * We have already checked this cast in * _s_voice_load_dataConfig (_s_load_voice_data_config) */ dataObjectMap = (const SMap*)SMapGetObjectDef(dataConfig, data_name, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"SMapGetObjectDef\" for data '%s' failed", data_name)) { S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } if (dataObjectMap == NULL) { S_CTX_ERR(error, S_CONTERR, "_s_voice_load_data", "Data object map for data '%s' in data config in NULL", data_name); S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } data_info = get_data_info(dataObjectMap, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"get_data_info\" for data '%s' in data config failed", data_name)) { S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } /* get data path, the one in the config file may be relative * to the voice base path */ combined_path = s_path_combine(voice_base_path, data_info->path, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"s_path_combine\" failed")) { S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } loaded = _s_vm_load_data(data_info->plugin, combined_path, data_info->format, error); S_FREE(combined_path); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"_s_vm_load_data\" for data '%s' in data config failed", data_name)) { S_FREE(data_info); S_DELETE(itr, "_s_voice_load_data", error); S_FREE(voice_base_path); return; } S_FREE(data_info); SMapSetObject(self->data->dataObjects, data_name, loaded, error); if (S_CHK_ERR(error, S_CONTERR, "_s_voice_load_data", "Call to \"SMapSetObject\" for data '%s' in data config failed", data_name)) { s_erc local_err = S_SUCCESS; S_FREE(voice_base_path); S_DELETE(itr, "_s_voice_load_data", error); _s_vm_unload_data((SObject*)loaded, &local_err); /* error is already set */ return; } itr = SIteratorNext(itr); } S_FREE(voice_base_path); }
static void Initialize(SFeatProcessor *self, const SMap* features, s_erc *error) { S_CLR_ERR(error); SPhraseTypeFeatProc *castSelf = S_CAST(self, SPhraseTypeFeatProc, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to S_CAST failed")) goto quit_error; castSelf->symbols = S_CAST( SMapGetObject(features , "list definitions", error), SMap, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapGetObject\" failed")) goto quit_error; castSelf->symbols = SMapCopy ( NULL , castSelf->symbols , error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapCopy\" failed")) goto quit_error; /* Get the iterator for the SMap */ SIterator *itrList = S_ITERATOR_GET(castSelf->symbols, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"S_ITERATOR_GET\" failed")) goto quit_error; while( itrList != NULL ) { const char *curStr = SIteratorKey(itrList, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SIteratorKey\" failed")) goto quit_error; SList *valueList; valueList = S_CAST(SMapGetObject(castSelf->symbols, curStr, error), SList, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapGetObject\" failed")) goto quit_error; /* Initializing a new SMap */ SMap *newCastMap= S_MAP(S_NEW(SMapHashTable, error)); SIterator *itrValueList = S_ITERATOR_GET(valueList, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"S_ITERATOR_GET\" failed")) goto quit_error; while(itrValueList != NULL) { const SObject *curValueObj = SIteratorObject(itrValueList, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SIteratorObject\" failed")) goto quit_error; const char *curValueStr = SObjectGetString(curValueObj, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SObjectGetString\" failed")) goto quit_error; /* Insert the string inside the map */ SMapSetString(newCastMap, curValueStr, curValueStr, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapSetObject\" failed")) goto quit_error; itrValueList = SIteratorNext(itrValueList); } /* Insertion of the SMap inside the SMap */ SMapSetObject(castSelf->symbols, curStr, (SObject *) newCastMap, error); if (S_CHK_ERR(error, S_CONTERR, "Initialize", "Call to \"SMapSetObject\" failed")) goto quit_error; itrList = SIteratorNext(itrList); } /* error cleanup */ quit_error: return; }
int main(int argc, char **argv) { s_erc error = S_SUCCESS; /* the syllabification can be started from the voice */ const SVoice *voice = NULL; SRelation *wordRel = NULL; SUtterance *utt = NULL; SItem *wordItem = NULL; SList *phones = NULL; SList *syllablesPhones = NULL; char* buffer = NULL; size_t buffer_size = 0; ssize_t buffer_length = 0; /* Config type will handle the command line input */ struct Config config = {0}; SPCT_PRINT_AND_WAIT("parsing options, press ENTER\n"); parse_arguments(&argc, argv, &config); SPCT_PRINT_AND_WAIT("going to initialize speect, press ENTER\n"); /* * initialize speect */ error = speect_init(NULL); if (error != S_SUCCESS) { printf("Failed to initialize Speect\n"); return 1; } SPCT_PRINT_AND_WAIT("initialized speect, loading voice, press ENTER\n"); /* load voice */ voice = s_vm_load_voice(config.voicefile, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"s_vm_load_voice\" failed")) goto quit; SPCT_PRINT_AND_WAIT("loaded voice, doing syllabification, press ENTER\n"); const SUttProcessor *uttProc = SVoiceGetUttProc(voice, "LexLookup", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SVoiceGetUttProc\" failed")) goto quit; utt = S_NEW(SUtterance, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"S_NEW\" failed")) goto quit; /* Utterance initialization */ SUtteranceInit(&utt, voice, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SUtteranceInit\" failed")) goto quit; /* Create new relation */ wordRel = SUtteranceNewRelation(utt, "Word", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"NewRelation\" failed")) goto quit; wordItem = SRelationAppend(wordRel, NULL, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SRelationAppend\" failed")) goto quit; SItemSetName(wordItem, "", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SItemSetName\" failed")) goto quit; SPCT_PRINT_AND_WAIT("load syllabification function, press ENTER\n"); SSyllabification* syllab = (SSyllabification*)SVoiceGetData(voice , "syllabification", &error); if (syllab == NULL) { syllab = (SSyllabification*)SMapGetObjectDef(uttProc -> features , "_syll_func", NULL, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SMapGetObjectDef\" failed")) goto quit; } SPCT_PRINT_AND_WAIT("everything ready to perform syllabification, press ENTER\n"); char inter_buffer[MAX_PHONEME_LENGTH+1] = {0}; buffer_length = getline(&buffer, &buffer_size, stdin); while (buffer_length != -1) { phones = S_LIST(S_NEW(SListList, &error)); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"S_NEW\" failed")) goto quit; int j = 0; while (buffer[j] != '\0') { int k; int inter_buffer_c; if (!isspace(buffer[j])) { inter_buffer[0] = buffer[j]; k = j + 1; inter_buffer_c = 1; while (!isspace(buffer[k]) && inter_buffer_c < MAX_PHONEME_LENGTH) { inter_buffer[inter_buffer_c] = buffer[k]; inter_buffer_c++; k++; } j += (inter_buffer_c - 1); inter_buffer[inter_buffer_c] = '\0'; /* for each phoneme in the line, put it in 'ph' */ SObject* ph = SObjectSetString(inter_buffer, &error); /* then add ph to the phoneme list */ SListAppend(phones, ph, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to \"SListAppend\" failed")) goto quit; } j++; } SPCT_PRINT_AND_WAIT("run syllabification on next phones string, press ENTER\n"); syllablesPhones = NULL; syllablesPhones = S_SYLLABIFICATION_CALL(syllab, syllabify)(syllab, wordItem, phones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"syllabify\" failed")) goto quit; /* PRINT LOOP */ uint32 k = 0; SIterator *itr_syllablesPhones = S_ITERATOR_GET(syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "Run", "Execution of \"S_ITERATOR_GET\" failed")) goto quit; size_t syllables_list_size = SListSize(syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SListSize\" failed")) goto quit; while (itr_syllablesPhones != NULL) { const SList* syl_list = (const SList*) SIteratorObject(itr_syllablesPhones, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SIteratorObject\" failed")) goto quit; size_t syl_list_size = SListSize(syl_list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SListSize\" failed")) goto quit; uint32 l = 0; SIterator *itr_syl_list = S_ITERATOR_GET(syl_list, &error); while (itr_syl_list != NULL) { const SObject* ph = SIteratorObject(itr_syl_list, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SIteratorObject\" failed")) goto quit; const char* phone_string = SObjectGetString(ph, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Call to method \"SObjectGetString\" failed")) goto quit; fprintf(stdout, "%s", phone_string); if (l < syl_list_size - 1){ fprintf(stdout, " "); } itr_syl_list = SIteratorNext(itr_syl_list); l++; } if (k < syllables_list_size - 1) { fprintf(stdout, " - "); } itr_syllablesPhones = SIteratorNext(itr_syllablesPhones); k++; } fprintf(stdout, "\n"); if (syllablesPhones != NULL) S_DELETE(syllablesPhones, "main", &error); if (phones != NULL) S_DELETE(phones, "main", &error); phones = NULL; buffer_length = getline(&buffer, &buffer_size, stdin); } quit: SPCT_PRINT_AND_WAIT("deleting iteration support structures, press ENTER\n"); if (buffer != NULL) free(buffer); if (phones != NULL) S_DELETE(phones, "main", &error); if (syllablesPhones != NULL) S_DELETE(syllablesPhones, "main", &error); SPCT_PRINT_AND_WAIT("deleting utterance, press ENTER\n"); if (utt != NULL) S_DELETE(utt, "main", &error); SPCT_PRINT_AND_WAIT("deleting voice, press ENTER\n"); if (voice != NULL) S_DELETE(voice, "main", &error); SPCT_PRINT_AND_WAIT("quitting speect, press ENTER\n"); /* * quit speect */ error = speect_quit(); if (error != S_SUCCESS) { printf("Call to 'speect_quit' failed\n"); return 1; } SPCT_PRINT_AND_WAIT("done, press ENTER\n"); return 0; }
static void print_list(const SList *list, char *buf, s_erc *error) { SIterator *itr; size_t list_size; S_CLR_ERR(error); list_size = SListSize(list, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"list_size\" failed")) return; s_strcat(buf, "[", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) return; itr = S_ITERATOR_GET(list, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"S_ITERATOR_GET\" failed")) return; for (/* NOP */; itr != NULL; itr = SIteratorNext(itr), --list_size) { s_bool type_ok; const SObject *tmp; tmp = SIteratorObject(itr, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SIteratorObject\" failed")) { S_DELETE(itr, "print_list", error); return; } type_ok = SObjectIsType(tmp, "SList", error); if (S_CHK_ERR(error, S_CONTERR, "print_word", "Call to \"SObjectIsType\" failed")) { S_DELETE(itr, "print_list", error); return; } if (type_ok) { print_list(S_LIST(tmp), buf, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"print_list\" failed")) { S_DELETE(itr, "print_list", error); return; } } else { type_ok = SObjectIsType(tmp, "SString", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SObjectIsType\" failed")) { S_DELETE(itr, "print_list", error); return; } if (type_ok) { const char *string = SObjectGetString(S_OBJECT(tmp), error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"SObjectGetString\" failed")) { S_DELETE(itr, "print_list", error); return; } s_strcat(buf, string, error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) { S_DELETE(itr, "print_list", error); return; } if ((list_size-1) != 0) { s_strcat(buf, " ", error); if (S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed")) { S_DELETE(itr, "print_list", error); return; } } } else { S_CTX_ERR(error, S_FAILURE, "print_list", "Unknown type in list"); { S_DELETE(itr, "print_list", error); return; } } } } s_strcat(buf, "]", error); S_CHK_ERR(error, S_CONTERR, "print_list", "Call to \"s_strcat\" failed"); }
static int write_relation(SDatasource *ds, const SRelation *rel, int num_tiers, float end_time, s_erc *error) { const char *relname; const SItem *head = NULL; const char *tier_header = "\titem [%d]:\n\t\tclass = \"IntervalTier\"\n\t\tname = \"%s\"\n"; const char *tier_start_end = "\t\txmin = 0\n\t\txmax = %f\n"; const char *tier_intervals = "\t\tintervals: size = %d\n"; const char *tier_item = " \t\tintervals [%d]:\n\t\t\txmin = %f\n\t\t\txmax = %f\n\t\t\ttext = \"%s\"\n"; char *buff; size_t str_size; float prev_end = 0.0; const SItem *itr; float item_start = 0.0; float item_end = 0.0; const char *item_name = NULL; SList *info; size_t l_size; int counter; SIterator *litr; S_CLR_ERR(error); if (rel == NULL) return num_tiers; num_tiers += 1; relname = SRelationName(rel, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SRelationName\" failed")) return 0; head = SRelationHead(rel, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SRelationHead\" failed")) return 0; /* tier header */ s_asprintf(&buff, error, tier_header, num_tiers, relname); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_asprintf\" failed")) return 0; str_size = s_strsize(buff, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_strsize\" failed")) { S_FREE(buff); return 0; } SDatasourceWrite(ds, buff, sizeof(char), str_size, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SDatasourceWrite\" failed")) { S_FREE(buff); return 0; } S_FREE(buff); /* start time and end time (always 0 and utt end) */ s_asprintf(&buff, error, tier_start_end, end_time); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_asprintf\" failed")) return 0; str_size = s_strsize(buff, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_strsize\" failed")) { S_FREE(buff); return 0; } SDatasourceWrite(ds, buff, sizeof(char), str_size, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SDatasourceWrite\" failed")) { S_FREE(buff); return 0; } S_FREE(buff); info = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Failed to create new list for info cache")) return 0; prev_end = 0.0; itr = head; while (itr != NULL) { item_start = get_start(itr, relname, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"get_start\" failed")) { S_DELETE(info, "write_relation", error); return 0; } item_end = get_end(itr, relname, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"get_end\" failed")) { S_DELETE(info, "write_relation", error); return 0; } if (!s_float_equal(item_start, prev_end)) { /* prepend extra "SIL" */ add_info(info, prev_end, item_start, "SIL", error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"add_info\" failed")) { S_DELETE(info, "write_relation", error); return 0; } } item_name = SItemGetName(itr, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SItemGetName\" failed")) { S_DELETE(info, "write_relation", error); return 0; } add_info(info, item_start, item_end, item_name, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"add_info\" failed")) { S_DELETE(info, "write_relation", error); return 0; } prev_end = item_end; itr = SItemNext(itr, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SItemNext\" failed")) { S_DELETE(info, "write_relation", error); return 0; } } if (!s_float_equal(item_end, end_time)) { add_info(info, item_end, end_time, "SIL", error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"add_info\" failed")) { S_DELETE(info, "write_relation", error); return 0; } } l_size = SListSize(info, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SListSize\" failed")) { S_DELETE(info, "write_relation", error); return 0; } /* tier intervals */ s_asprintf(&buff, error, tier_intervals, l_size); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_asprintf\" failed")) { S_DELETE(info, "write_relation", error); return 0; } str_size = s_strsize(buff, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_strsize\" failed")) { S_FREE(buff); S_DELETE(info, "write_relation", error); return 0; } SDatasourceWrite(ds, buff, sizeof(char), str_size, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SDatasourceWrite\" failed")) { S_FREE(buff); S_DELETE(info, "write_relation", error); return 0; } S_FREE(buff); litr = S_ITERATOR_GET(info, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"S_ITERATOR_GET\" failed")) { S_DELETE(info, "write_relation", error); return 0; } for (counter = 1; litr != NULL; litr = SIteratorNext(litr), counter++) { SList *itemList; SObject *tmp; char *name; itemList = S_LIST(SIteratorObject(litr, error)); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SIteratorObject\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); return 0; } tmp = SListPop(itemList, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SIteratorObject\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); return 0; } item_name = SObjectGetString(tmp, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SObjectGetString\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_DELETE(tmp, "write_relation", error); return 0; } name = s_strdup(item_name, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_strdup\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_DELETE(tmp, "write_relation", error); return 0; } S_DELETE(tmp, "write_relation", error); tmp = SListPop(itemList, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SIteratorObject\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_FREE(name); return 0; } item_end = SObjectGetFloat(tmp, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SObjectGetFloat\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_DELETE(tmp, "write_relation", error); S_FREE(name); return 0; } S_DELETE(tmp, "write_relation", error); tmp = SListPop(itemList, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SIteratorObject\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_FREE(name); return 0; } item_start = SObjectGetFloat(tmp, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SObjectGetFloat\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_DELETE(tmp, "write_relation", error); S_FREE(name); return 0; } S_DELETE(tmp, "write_relation", error); /* tier item */ s_asprintf(&buff, error, tier_item, counter, item_start, item_end, name); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_asprintf\" failed")) { S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_FREE(name); return 0; } str_size = s_strsize(buff, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"s_strsize\" failed")) { S_FREE(buff); S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_FREE(name); return 0; } SDatasourceWrite(ds, buff, sizeof(char), str_size, error); if (S_CHK_ERR(error, S_CONTERR, "write_relation", "Call to \"SDatasourceWrite\" failed")) { S_FREE(buff); S_DELETE(info, "write_relation", error); S_DELETE(litr, "write_relation", error); S_FREE(name); return 0; } S_FREE(buff); S_FREE(name); } S_DELETE(info, "write_relation", error); return num_tiers; }