static void InitUtterance(void *obj, s_erc *error) { SUtterance *self = obj; S_CLR_ERR(error); self->voice = NULL; self->features = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitUtterance", "Failed to create new map-list features")) return; self->relations = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitUtterance", "Failed to create new map-list relations")) return; /* item id's */ SMapSetInt(self->features, "_id", 0, error); S_CHK_ERR(error, S_CONTERR, "InitUtterance", "Call to SMapSetInt failed"); s_mutex_init(&(self->utt_mutex)); s_mutex_init(&(self->utt_id_mutex)); }
static SRelation *UttNewRelation(SUtterance *self, const char *name, s_erc *error) { SRelation *newRel; S_CLR_ERR(error); newRel = S_NEW(SRelation, error); if (S_CHK_ERR(error, S_CONTERR, "UttNewRelation", "Failed to create new relation")) return NULL; SRelationInit(&newRel, name, error); if (S_CHK_ERR(error, S_CONTERR, "UttNewRelation", "Failed to initialize new relation")) return NULL; UttSetRelation(self, newRel, error); if (S_CHK_ERR(error, S_CONTERR, "UttNewRelation", "Call to \"UttSetRelation\" failed")) { S_FORCE_DELETE(newRel, "UttNewRelation", error); return NULL; } return newRel; }
static void InitVoice(void *obj, s_erc *error) { SVoice *self = obj; S_CLR_ERR(error); self->info = NULL; self->plugins = NULL; self->features = NULL; self->featProcessors = NULL; self->uttProcessors = NULL; self->uttTypes = NULL; self->data = S_CALLOC(s_voice_data, 1); if (self->data == NULL) { S_FTL_ERR(error, S_MEMERROR, "InitVoice", "Failed to allocate memory for 's_voice_data' object"); return; } self->data->dataObjects = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitVoice", "Failed to create new data objects map")) return; s_mutex_init(&self->voice_mutex); }
S_API SObject *SObjectSetString(const char *s, s_erc *error) { SString *self; S_CLR_ERR(error); if (s == NULL) { S_CTX_ERR(error, S_ARGERROR, "SObjectSetString", "Argument \"s\" is NULL"); return NULL; } self = S_NEW(SString, error); if (S_CHK_ERR(error, S_FAILURE, "SObjectSetString", "Failed to create new SString object")) return NULL; self->s = s_strdup(s, error); if (S_CHK_ERR(error, S_CONTERR, "SObjectSetString", "Failed to copy string")) { S_DELETE(self, "SObjectSetString", error); return NULL; } return S_OBJECT(self); }
/* search for item, if not found create a new one and add it. */ static SItem *get_item(s_hash_table *relation_items, uint32 item_node_number, s_erc *error) { uint32 *item_node_number_copy; SItem *item; const s_hash_element *he; /* search for item, if not found create a new one and add it. */ he = s_hash_table_find(relation_items, (void*)&item_node_number, sizeof(uint32), error); if (S_CHK_ERR(error, S_CONTERR, "get_item", "Call to \"s_hash_table_find\" failed")) return NULL; if (he == NULL) { /* create new item */ item = S_NEW(SItem, error); if (S_CHK_ERR(error, S_CONTERR, "get_item", "Failed to create new Item")) return NULL; item_node_number_copy = S_MALLOC(uint32, 1); if (item_node_number_copy == NULL) { S_FTL_ERR(error, S_MEMERROR, "get_item", "Failed to allocated memory for 'uint32' object"); S_FORCE_DELETE(item, "get_item", error); return NULL; } *item_node_number_copy = item_node_number; /* add to hash table */ s_hash_table_add(relation_items, (void*)item_node_number_copy, sizeof(uint32), (void*)item, error); if (S_CHK_ERR(error, S_CONTERR, "get_item", "Call to \"s_hash_table_add\" failed")) { S_FREE(item_node_number_copy); S_FORCE_DELETE(item, "get_item", error); return NULL; } } else { item = (SItem*)s_hash_element_get_data(he, error); if (S_CHK_ERR(error, S_CONTERR, "get_item", "Call to \"s_hash_element_get_data\" failed")) return NULL; } return item; }
static void InitMapPy(void *obj, s_erc *error) { SMapPy *self = obj; S_CLR_ERR(error); self->staticObjects = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitMapPy", "Failed to create new 'SListList' object")) return; self->pyObject = S_NEW(SPyObject, error); S_CHK_ERR(error, S_CONTERR, "InitMapPy", "Failed to create new 'SPyObject' object"); }
static void InitItmContent(void *obj, s_erc *error) { SItmContent *self = obj; S_CLR_ERR(error); self->features = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitItmContent", "Failed to create features map")) return; self->relations = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "InitItmContent", "Failed to create relations map")) return; /* so that it will only be deleted with S_FORCE_DELETE */ SObjectIncRef(obj); s_mutex_init(&(self->content_mutex)); }
S_API SObject *SObjectSetVoid(void *ptr, const char *type_name, s_svoid_free_fp free_func, s_erc *error) { SVoid *self; S_CLR_ERR(error); if (ptr == NULL) { S_CTX_ERR(error, S_ARGERROR, "SObjectSetVoid", "Argument \"ptr\" is NULL"); return NULL; } if (type_name == NULL) { S_CTX_ERR(error, S_ARGERROR, "SObjectSetVoid", "Argument \"type_name\" is NULL"); return NULL; } self = S_NEW(SVoid, error); if (S_CHK_ERR(error, S_FAILURE, "SObjectSetVoid", "Failed to create new 'SVoid' object")) return NULL; self->ptr = ptr; self->free_func = free_func; self->type_name = s_strdup(type_name, error); if (S_CHK_ERR(error, S_CONTERR, "SObjectSetVoid", "Failed to copy type name")) { S_DELETE(self, "SObjectSetVoid", error); return NULL; } return S_OBJECT(self); }
static void Init(void *obj, s_erc *error) { SViterbiPath *self = obj; S_CLR_ERR(error); self->score = 0.0; self->state = 0; self->c = NULL; self->from = NULL; self->next = NULL; self->features = S_MAP(S_NEW(SMapList, error)); S_CHK_ERR(error, S_CONTERR, "Init", "Failed to create new 'SMap' object"); }
S_API SObject *SObjectSetInt(sint32 i, s_erc *error) { SInt *self; S_CLR_ERR(error); self = S_NEW(SInt, error); if (S_CHK_ERR(error, S_FAILURE, "SObjectSetInt", "Failed to create new SInt object")) return NULL; self->i = i; return S_OBJECT(self); }
S_API SObject *SObjectSetFloat(float f, s_erc *error) { SFloat *self; S_CLR_ERR(error); self = S_NEW(SFloat, error); if (S_CHK_ERR(error, S_FAILURE, "SObjectSetFloat", "Failed to create new SFloat object")) return NULL; self->f = f; return S_OBJECT(self); }
static void Init(void *obj, s_erc *error) { STokenstreamFile *self = obj; S_CLR_ERR(error); if (num_file_tokenstreams++ == 0) { /* create a tokenstream to give us access to the STokenstreamClass functions */ tokenstream = S_NEW(STokenstream, error); if (S_CHK_ERR(error, S_CONTERR, "Init", "Failed to create tokenstream to give STokenstreamClass function access")) return; } self->ds = NULL; }
S_API SDatasource *SMMapFilesourceOpenFile(const char *path, s_erc *error) { SMMapFilesource *self; uint8 *mem; size_t map_size; s_mmap_file_handle *handle; S_CLR_ERR(error); self = S_NEW(SMMapFilesource, error); if (S_CHK_ERR(error, S_CONTERR, "SMMapFilesourceOpenFile", "Failed to create new object")) return NULL; self->path = s_strdup(path, error); if (S_CHK_ERR(error, S_CONTERR, "SMMapFilesourceOpenFile", "Failed to duplicate file path")) { S_DELETE(self, "SMMapFilesourceOpenFile", error); return NULL; } handle = s_mmapfile_open(path, &map_size, &mem, error); if (S_CHK_ERR(error, S_CONTERR, "SMMapFilesourceOpenFile" "Call to \"s_mmapfile_open\" failed for file \"%s\"", path)) { S_DELETE(self, "SMMapFilesourceOpenFile", error); return NULL; } self->handle = handle; self->mem = mem; self->map_size = map_size; return S_DATASOURCE(self); }
static SIterator *MapPyIterator(const SContainer *self, s_erc *error) { SMapPyIterator *itr; S_CLR_ERR(error); itr = S_NEW(SMapPyIterator, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyIterator", "Failed to create new iterator")) return NULL; SMapPyIteratorInit(&itr, S_MAPPY(self), error); S_CHK_ERR(error, S_CONTERR, "MapPyIterator", "Failed to initialize iterator"); return S_ITERATOR(itr); }
static void read_g2p_rewrites_rules(SG2PRewrites *g2p, SEbmlRead *ebmlReader, s_erc *error) { uint32 id; s_bool container_exhausted; SList *graphemeRuleList = NULL; SG2PRewritesRule *rule = NULL; S_CLR_ERR(error); /* read S_G2PREWRITES_EBML_RULES_CONTAINER container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container\" failed")) return; /* create rules SMap */ g2p->rules = S_MAP(S_NEW(SMapHashTable, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SMap' object")) return; /* 64 should be enough for graphemes */ SMapHashTableResize(S_MAPHASHTABLE(g2p->rules), 64, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SMapHashTableResize\" failed")) { S_DELETE(g2p->rules, "read_g2p_rewrites_rules", error); return; } while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container_at_end\" failed")) 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_rules", "ebmlRead method \"peek_id\" failed")) return; switch(id) { case S_G2PREWRITES_EBML_RULES_GRAPHEME: { char *grapheme; grapheme = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; /* create rule list for this grapheme */ graphemeRuleList = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SList' object")) return; /* add it to the rules SMap */ SMapSetObject(g2p->rules, grapheme, S_OBJECT(graphemeRuleList), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SMapSetObject\" failed")) { S_DELETE(graphemeRuleList, "read_g2p_rewrites_rules", error); S_FREE(grapheme); return; } S_FREE(grapheme); break; } case S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER: { /* read S_G2PREWRITES_EBML_SINGLE_RULE_CONTAINER container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container\" failed")) return; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"container_at_end\" failed")) 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_rules", "ebmlRead method \"peek_id\" failed")) return; switch(id) { case S_G2PREWRITES_EBML_SINGLE_RULE_LEFT_CONTEXT: { /* elements are ordered so we create a rule here */ rule = S_NEW(SG2PRewritesRule, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Failed to create new 'SG2PRewritesRule' object")) return; /* add it to the list */ SListAppend(graphemeRuleList, S_OBJECT(rule), error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "Call to \"SListAppend\" failed")) { S_DELETE(rule, "read_g2p_rewrites_rules", error); return; } rule->left_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } case S_G2PREWRITES_EBML_SINGLE_RULE_RIGHT_CONTEXT: { rule->right_context = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } case S_G2PREWRITES_EBML_SINGLE_RULE_PHONEME: { rule->phone = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_g2p_rewrites_rules", "ebmlRead method \"read_utf8\" failed")) return; break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_rules", "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_rules", "ebmlRead method \"element_skip\" failed")) return; } } break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_g2p_rewrites_rules", "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_rules", "ebmlRead method \"element_skip\" failed")) return; } } return; }
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; }
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; }
int main() { s_erc error; SDatasource *ds = NULL; SPlugin *plugin = NULL; s_ebml_header *header = NULL; const char *doc_type = "spct_ebml_test"; SEbmlWrite *ebmlWriter = NULL; S_CLR_ERR(&error); /* * initialize speect */ error = speect_init(NULL); if (error != S_SUCCESS) { printf("Failed to initialize Speect\n"); return 1; } /* * load the ebml plug-in */ plugin = s_pm_load_plugin("ebml.spi", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to load plug-in at 'ebml.spi'")) { printf("failed to load plug-in\n"); goto quit; } else { printf("plug-in loaded\n"); } /* * create a data source, "wb" = write, binary */ ds = SFilesourceOpenFile("ebml_test.bin", "wb", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to create data source 'ebml_test.bin'")) { printf("failed to create data source\n"); goto quit; } else { printf("data source created\n"); } /* * create ebml header */ header = S_MALLOC(s_ebml_header, 1); if (header == NULL) { S_FTL_ERR(&error, S_MEMERROR, "main", "Failed to allocate memory for s_ebml_header object"); goto quit; } header->ebml_version = 1; header->ebml_read_version = 1; header->max_id_width = 4; header->max_size_width = 4; header->doctype_version = 1; header->doctype_read_version = 1; header->doctype = s_strdup(doc_type, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to duplicate 'doc_type' for ebml header")) goto quit; /* * create ebml writer object */ ebmlWriter = S_NEW(SEbmlWrite, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to create new SEbmlWrite object")) { printf("failed to create SEbmlWrite object\n"); goto quit; } else { printf("created SEbmlWrite object\n"); } /* * initialize ebml writer object */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_init)) { S_EBMLWRITE_CALL(ebmlWriter, write_init)(&ebmlWriter, ds, header, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to initialize SEbmlWrite object")) { printf("failed to initialize SEbmlWrite object"); goto quit; } else { printf("initialized SEbmlWrite object\n"); /* * ebml writer takes hold of the header and the data * source, we dont want a reference to it anymore (for * quit to work). */ header = NULL; ds = NULL; } } else { S_CTX_ERR(&error, S_METHINVLD, "main", "EbmlWrite method \"write_init\" not implemented"); printf("cannot do write_init"); goto quit; } /* * Start a container */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, start_container)) { S_EBMLWRITE_CALL(ebmlWriter, start_container)(ebmlWriter, 129, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to start ebml container")) { printf("failed to start container\n"); goto quit; } else { printf("container started, id = %d\n", 129); } } /* * Write a few unsigned int values */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_uint)) { S_EBMLWRITE_CALL(ebmlWriter, write_uint)(ebmlWriter, 130, 234, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write uint [%d]", 234)) { printf("failed to write uint [%d]\n", 234); goto quit; } else { printf("wrote uint [%d], id = %d\n", 234, 130); } S_EBMLWRITE_CALL(ebmlWriter, write_uint)(ebmlWriter, 130, 31234, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write uint [%d]", 31234)) { printf("Failed to write uint [%d]\n", 31234); goto quit; } else { printf("wrote uint [%d], id = %d\n", 31234, 130); } } /* * Write a few signed int values */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_sint)) { S_EBMLWRITE_CALL(ebmlWriter, write_sint)(ebmlWriter, 131, -69, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write sint [%d]", -69)) { printf("Failed to write sint [%d]\n", -69); goto quit; } else { printf("wrote sint [%d], id = %d\n", -69, 131); } S_EBMLWRITE_CALL(ebmlWriter, write_sint)(ebmlWriter, 131, -132769, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write sint [%d]", -132769)) { printf("Failed to write sint [%d]\n", -132769); goto quit; } else { printf("wrote sint [%d], id = %d\n", -132769, 131); } } /* * Start a container */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, start_container)) { S_EBMLWRITE_CALL(ebmlWriter, start_container)(ebmlWriter, 132, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to start ebml container")) { printf("failed to start container\n"); goto quit; } else { printf("container started, id = %d\n", 132); } } /* * Write some floats */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_float)) { S_EBMLWRITE_CALL(ebmlWriter, write_float)(ebmlWriter, 133, 20.343, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write float [%f]", 20.343)) { printf("Failed to write float [%f]\n", 20.343); goto quit; } else { printf("wrote float [%f], id = %d\n", 20.343, 133); } S_EBMLWRITE_CALL(ebmlWriter, write_float)(ebmlWriter, 133, -12320.7603, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write float [%f]", -12320.7603)) { printf("Failed to write float [%f]\n", -12320.7603); goto quit; } else { printf("wrote float [%f], id = %d\n", -12320.7603, 133); } } /* * Write some doubles */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_double)) { S_EBMLWRITE_CALL(ebmlWriter, write_double)(ebmlWriter, 134, -3.145343234223321, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write double [%f]", -3.145343234223321)) { printf("Failed to write double [%f]\n", -3.145343234223321); goto quit; } else { printf("wrote double [%f], id = %d\n", -3.145343234223321, 134); } S_EBMLWRITE_CALL(ebmlWriter, write_double)(ebmlWriter, 134, 533.145343234223321145343234223321, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write double [%f]", 533.145343234223321145343234223321)) { printf("Failed to write double [%f]\n", 533.145343234223321145343234223321); goto quit; } else { printf("wrote double [%f], id = %d\n", 533.145343234223321145343234223321, 134); } } /* * Close container */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, stop_container)) { S_EBMLWRITE_CALL(ebmlWriter, stop_container)(ebmlWriter, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to stop ebml container")) { printf("failed to stop container\n"); goto quit; } else { printf("container stop\n"); } } /* * Write some ascii */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_ascii)) { S_EBMLWRITE_CALL(ebmlWriter, write_ascii)(ebmlWriter, 135, "hello world", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write ascii [%s]", "hello world")) { printf("Failed to write ascii [%s]\n", "hello world"); goto quit; } else { printf("wrote ascii [%s], id = %d\n", "hello world", 135); } } /* * Write some utf8 */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, write_utf8)) { S_EBMLWRITE_CALL(ebmlWriter, write_utf8)(ebmlWriter, 136, "hello world in Japanese: ハロー世界", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to write utf8 [%s]", "hello world in Japanese")) { printf("Failed to write utf8 [%s]\n", "hello world in Japanese: ハロー世界"); goto quit; } else { printf("wrote utf8 [%s], id = %d\n", "hello world in Japanese: ハロー世界", 136); } } /* * Close container */ if (S_EBMLWRITE_METH_VALID(ebmlWriter, stop_container)) { S_EBMLWRITE_CALL(ebmlWriter, stop_container)(ebmlWriter, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to stop ebml container")) { printf("failed to stop container\n"); goto quit; } else { printf("container stop\n"); } } /* * quit */ quit: if (ds != NULL) S_DELETE(ds, "main", &error); if (header != NULL) { if (header->doctype != NULL) S_FREE(header->doctype); S_FREE(header); } if (ebmlWriter != NULL) S_DELETE(ebmlWriter, "main", &error); /* must be after ebmlWriter */ if (plugin != NULL) S_DELETE(plugin, "main", &error); /* * quit speect */ error = speect_quit(); if (error != S_SUCCESS) { printf("Call to 'speect_quit' failed\n"); return 1; } return 0; }
S_LOCAL SG2PRewrites *s_read_g2p_rewrites(SDatasource *ds, s_erc *error) { SG2PRewrites *g2p = NULL; SEbmlRead *ebmlReader = NULL; uint32 id; s_bool container_exhausted; int scomp; S_CLR_ERR(error); /* create and initialize ebml reader */ ebmlReader = S_NEW(SEbmlRead, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Failed to create new SEbmlRead object")) goto quit_error; S_EBMLREAD_CALL(ebmlReader, read_init)(&ebmlReader, ds, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Failed to initialize SEbmlRead object")) goto quit_error; /* check that we have the correct doc type */ scomp = s_strcmp(ebmlReader->header->doctype, "spct_g2p_rewrites", error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Call to \"s_strcmp\" failed")) goto quit_error; if (scomp != 0) { S_CTX_ERR(error, S_FAILURE, "s_read_g2p_rewrites", "Ebml file format not of type 'spct_g2p_rewrites', read format is '%s'", ebmlReader->header->doctype); goto quit_error; } /* create and initialize new g2p rewrites object */ g2p = S_NEW(SG2PRewrites, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Failed to create new 'SG2PRewrites' object")) goto quit_error; /* read top level container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "ebmlRead method \"container\" failed")) goto quit_error; /* sanity check id */ S_EBML_ID_SANITY(id, S_G2PREWRITES_EBML, "s_read_g2p_rewrites", "ID mismatch", error); while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "ebmlRead method \"container_at_end\" failed")) goto quit_error; if (container_exhausted) break; /* we are finished reading the g2p rewrites file */ /* peek id for g2p rewrites elements */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "ebmlRead method \"peek_id\" failed")) goto quit_error; switch(id) { case S_G2PREWRITES_EBML_DEF: { read_g2p_rewrites_def(g2p, ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Call to \"read_g2p_rewrites_def\" failed")) goto quit_error; break; } case S_G2PREWRITES_EBML_SETS: { S_WARNING(S_WARNERR, "s_read_g2p_rewrites", "G2P Rewrites sets not yet implemented, skipping"); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "ebmlRead method \"element_skip\" failed")) goto quit_error; break; } case S_G2PREWRITES_EBML_RULES_CONTAINER: { read_g2p_rewrites_rules(g2p, ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Call to \"read_g2p_rewrites_rules\" failed")) goto quit_error; break; } case S_G2PREWRITES_EBML_ZEROS: { read_g2p_rewrites_zeros(g2p, ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "Call to \"read_g2p_rewrites_zeros\" failed")) goto quit_error; break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "s_read_g2p_rewrites", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_g2p_rewrites", "ebmlRead method \"element_skip\" failed")) goto quit_error; } } /* if we get here then everything was OK */ goto quit; /* errors start clean up code here */ quit_error: if (g2p != NULL) S_DELETE(g2p, "s_read_g2p_rewrites", error); /* sets g2p = NULL */ /* normal exit start clean up code here */ quit: if (ebmlReader != NULL) S_DELETE(ebmlReader, "s_read_g2p_rewrites", error); return g2p; }
static void create_new_entry(SAddendum *addendum, s_erc *error) { SMap *features = NULL; SList *phones = NULL; int i; SObject *stringObject = NULL; S_CLR_ERR(error); /* create a word features map */ features = S_MAP(S_NEW(SMapList, error)); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to create new 'SMapList' object")) goto quit_error; /* now create a phones list */ phones = S_LIST(S_NEW(SListList, error)); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to create new 'SListList' object")) goto quit_error; SMapSetObject(features, "phones", S_OBJECT(phones), error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Failed to initialize new 'SListList' object")) { S_DELETE(phones, "create_new_entry", error); goto quit_error; } /* add the phones to list */ for (i = 0; test_word_phones[i] != NULL; i++) { /* create a string object */ stringObject = SObjectSetString(test_word_phones[i], error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to \"SObjectSetString\" failed")) goto quit_error; /* add string object to list */ SListAppend(phones, stringObject, error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to \"SListAppend\" failed")) { S_DELETE(stringObject, "create_new_entry", error); goto quit_error; } } /* add entry to addendum */ S_ADDENDUM_CALL(addendum, add_word)(addendum, test_word, features, error); if (S_CHK_ERR(error, S_CONTERR, "create_new_entry", "Call to method \"add_word\" failed")) goto quit_error; return; quit_error: if (features != NULL) S_DELETE(features, "create_new_entry", error); }
int main() { s_erc error; STokenstream *ts = NULL; s_bool eof; const SToken *token; const char *tmp; S_CLR_ERR(&error); /* * initialize speect */ error = speect_init(NULL); if (error != S_SUCCESS) { printf("Failed to initialize Speect\n"); return 1; } /* create file tokenstream */ ts = (STokenstream*)S_NEW(STokenstreamFile, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to create new file tokenstream")) goto quit; /* initialize file tokenstream */ STokenstreamFileInit((STokenstreamFile**)&ts, "test_file.txt", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to initialize file tokenstream")) goto quit; eof = STokenstreamQueryEOF(ts, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to query end of file")) goto quit; while (!eof) { token = STokenstreamPeekToken(ts, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to peek token")) goto quit; tmp = STokenGetString(token, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token string")) goto quit; if (tmp == NULL) break; else { token = STokenstreamGetToken(ts, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token")) goto quit; } printf("\nTOKEN:\n"); /* white space */ tmp = STokenGetWhitespace(token, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token white-space")) goto quit; if (tmp != NULL) printf("token whitespace = \"%s\".\n", tmp); else printf("token whitespace = NULL.\n"); /* pre-punctuation */ tmp = STokenGetPrePunc(token, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token pre-punctuation")) goto quit; if (tmp != NULL) printf("token pre-punctuation = \"%s\".\n", tmp); else printf("token pre-punctuation = NULL.\n"); /* token string */ tmp = STokenGetString(token, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token string")) goto quit; if (tmp != NULL) printf("token string = \"%s\".\n", tmp); else printf("token string = NULL.\n"); /* post-punctuation */ tmp = STokenGetPostPunc(token, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to get token post-punctuation")) goto quit; if (tmp != NULL) printf("token post-punctuation = \"%s\".\n", tmp); else printf("token post-punctuation = NULL.\n"); eof = STokenstreamQueryEOF(ts, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to query end of file")) goto quit; } /* * quit */ quit: if (ts != NULL) S_DELETE(ts, "main", &error); /* * quit speect */ error = speect_quit(); if (error != S_SUCCESS) { printf("Call to 'speect_quit' failed\n"); return 1; } 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; }
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; }
int main() { s_erc error; SDatasource *ds = NULL; SPlugin *plugin = NULL; const char *doc_type = "spct_ebml_test"; SEbmlRead *ebmlReader = NULL; int rv; S_CLR_ERR(&error); /* * initialize speect */ error = speect_init(NULL); if (error != S_SUCCESS) { printf("Failed to initialize Speect\n"); return 1; } /* * load the ebml plug-in */ plugin = s_pm_load_plugin("ebml.spi", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to load plug-in at 'ebml.spi'")) { printf("failed to load plug-in\n"); goto quit; } else { printf("plug-in loaded\n"); } /* * create a data source, "rb" = read, binary */ ds = SFilesourceOpenFile("ebml_test.bin", "rb", &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to create data source 'ebml_test.bin'")) { printf("failed to create data source\n"); goto quit; } else { printf("data source created\n"); } /* * create ebml reader object */ ebmlReader = S_NEW(SEbmlRead, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to create new SEbmlRead object")) { printf("failed to create SEbmlRead object\n"); goto quit; } else { printf("created SEbmlRead object\n"); } /* * initialize ebml reader object */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_init)) { S_EBMLREAD_CALL(ebmlReader, read_init)(&ebmlReader, ds, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to initialize SEbmlRead object")) { printf("failed to initialize SEbmlRead object\n"); goto quit; } else { printf("initialized SEbmlRead object\n"); /* * ebml reader takes hold of the data source, we dont want * a reference to it anymore (for quit to work). */ ds = NULL; } } else { S_CTX_ERR(&error, S_METHINVLD, "main", "EbmlRead method \"read_init\" not implemented"); printf("cannot do read_init\n"); goto quit; } /* * verify doc_type */ rv = s_strcmp(ebmlReader->header->doctype, doc_type, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to compare doc_type's")) { printf("failed to compare document types\n"); goto quit; } if (rv != 0) { printf("document types differ\n"); goto quit; } else { printf("document types are good\n"); } /* * Open container */ if (S_EBMLREAD_METH_VALID(ebmlReader, container)) { uint32 id; id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to open ebml container")) { printf("failed to open container\n"); goto quit; } else { printf("container opened with id %d, should be %d\n", id, 129); } } /* * Read a few unsigned int values */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_uint)) { uint32 val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_uint)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read uint [%d]", 234)) { printf("failed to read uint [%d]\n", 234); goto quit; } else { printf("read uint [%d] with id %d (should be %d and id %d)\n", val, id, 234, 130); } val = S_EBMLREAD_CALL(ebmlReader, read_uint)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read uint [%d]", 31234)) { printf("failed to read uint [%d]\n", 31234); goto quit; } else { printf("read uint [%d] with id %d (should be %d and id %d)\n", val, id, 31234, 130); } } /* * Read a few signed int values */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_sint)) { sint32 val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_sint)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read sint [%d]", -69)) { printf("failed to read sint [%d]\n", -69); goto quit; } else { printf("read sint [%d] with id %d (should be %d, and id %d)\n", val, id, -69, 131); } val = S_EBMLREAD_CALL(ebmlReader, read_sint)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read sint [%d]", -132769)) { printf("failed to read sint [%d]\n", -132769); goto quit; } else { printf("read sint [%d] with id %d (should be %d, and id %d)\n", val, id, -132769, 131); } } /* * Open container */ if (S_EBMLREAD_METH_VALID(ebmlReader, container)) { uint32 id; id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to open ebml container")) { printf("failed to open container\n"); goto quit; } else { printf("container opened with id %d, should be %d\n", id, 132); } } /* * Read some floats */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_float)) { float val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_float)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read float [%f]", 20.343)) { printf("failed to read float [%f]\n", 20.343); goto quit; } else { printf("read float [%f] with id %d (should be %f and id %d)\n", val, id, 20.343, 133); } val = S_EBMLREAD_CALL(ebmlReader, read_float)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read float [%f]", -12320.7603)) { printf("failed to read float [%f]\n", -12320.7603); goto quit; } else { printf("read float [%f] with id %d (should be %f and id %d)\n", val, id, -12320.7603, 133); } } /* * Read some doubles */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_double)) { double val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_double)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read double [%f]", -3.145343234223321)) { printf("failed to read double [%f]\n", -3.145343234223321); goto quit; } else { printf("read double [%f] with id %d (should be %f and id %d)\n", val, id, -3.145343234223321, 134); } val = S_EBMLREAD_CALL(ebmlReader, read_double)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read double [%f]", 533.145343234223321145343234223321)) { printf("failed to read double [%f]\n", 533.145343234223321145343234223321); goto quit; } else { printf("read double [%f] with id %d (should be %f and id %d)\n", val, id, 533.145343234223321145343234223321, 134); } } /* * Check that container is at end */ if (S_EBMLREAD_METH_VALID(ebmlReader, container_at_end)) { s_bool at_end; at_end = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to check if container is at end")) { printf("failed to check if container is at end\n"); goto quit; } if (at_end) { printf("found container at end (correct)\n"); } else { printf("container not at end, error\n"); goto quit; } } /* * Read some ascii */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_ascii)) { char *val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_ascii)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read ascii [%s]", "hello world")) { printf("Failed to read ascii [%s]\n", "hello world"); goto quit; } else { printf("read ascii [%s] with id %d (should be 'hello world' and id %d)\n", val, id, 135); S_FREE(val); } } /* * Read some utf8 */ if (S_EBMLREAD_METH_VALID(ebmlReader, read_utf8)) { char *val; uint32 id; val = S_EBMLREAD_CALL(ebmlReader, read_utf8)(ebmlReader, &id, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to read utf8 [%s]", "hello world in Japanese")) { printf("Failed to read utf8 [%s]", "hello world in Japanese"); goto quit; } else { printf("read utf8 [%s] with id %d (should be 'hello world in Japanese: ハロー世界' and id %d)\n", val, id, 136); S_FREE(val); } } /* * Check that container is at end */ if (S_EBMLREAD_METH_VALID(ebmlReader, container_at_end)) { s_bool at_end; at_end = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, &error); if (S_CHK_ERR(&error, S_CONTERR, "main", "Failed to check if container is at end")) { printf("failed to check if container is at end\n"); goto quit; } if (at_end) { printf("found container at end (correct)\n"); } else { printf("container not at end, error\n"); goto quit; } } /* * quit */ quit: if (ds != NULL) S_DELETE(ds, "main", &error); if (ebmlReader != NULL) S_DELETE(ebmlReader, "main", &error); /* must be after ebmlReader */ if (plugin != NULL) S_DELETE(plugin, "main", &error); /* * quit speect */ error = speect_quit(); if (error != S_SUCCESS) { printf("Call to 'speect_quit' failed\n"); return 1; } return 0; }
static s_hash_table *read_item_contents(SEbmlRead *ebmlReader, s_erc *error) { s_hash_table *items_content_table = NULL; s_items_content_container *ic = NULL; uint32 *item_content_id = NULL; uint32 id; s_bool container_exhausted; S_CLR_ERR(error); /* read S_UTT_EBML_ITEMS_CONTENTS container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"container\" failed")) goto quit_error; /* 2^9 = 512 item contents for a start */ items_content_table = s_hash_table_new(&items_content_table_free_fp, 9, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "Call to \"s_hash_table_new\" failed")) goto quit_error; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"container_at_end\" failed")) goto quit_error; if (container_exhausted) break; /* peek id */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"peek_id\" failed")) goto quit_error; switch(id) { case S_UTT_EBML_ITEMS_CONTENT_ID: { item_content_id = S_MALLOC(uint32, 1); if (item_content_id == NULL) { S_FTL_ERR(error, S_MEMERROR, "read_item_contents", "Failed to allocate memory for 'uint32' object"); goto quit_error; } *item_content_id = S_EBMLREAD_CALL(ebmlReader, read_uint)(ebmlReader, &id, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"read_uint\" failed")) goto quit_error; /* make new item contents container */ ic = S_CALLOC(s_items_content_container, 1); if (ic == NULL) { S_FTL_ERR(error, S_MEMERROR, "read_item_contents", "Failed to allocate memory for 's_items_content_container' object"); goto quit_error; } /* create a new item contents */ ic->content = S_NEW(SItmContent, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "Failed to create new item content")) goto quit_error; break; } case S_UTT_EBML_ITEMS_CONTENT_FEATURES: { /* read S_UTT_EBML_ITEMS_CONTENT_FEATURES container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"container\" failed")) goto quit_error; while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"container_at_end\" failed")) goto quit_error; if (container_exhausted) { /* add item contents container to hash table */ s_hash_table_add(items_content_table, (void*)item_content_id, sizeof(uint32), ic, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "Call to \"s_hash_table_add\" failed")) goto quit_error; item_content_id = NULL; ic = NULL; break; /* we are finished reading the item content * features */ } /* peek id for item content feature elements */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"peek_id\" failed")) goto quit_error; switch(id) { case S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME: { char *feat_name; SObject *featObject; /* feature elements are ordered (feat name, feat object), * so we do it in one go */ read_feature(ebmlReader, &feat_name, S_UTT_EBML_ITEMS_CONTENT_FEAT_NAME, &featObject, S_UTT_EBML_ITEMS_CONTENT_FEAT_OBJECT, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "Call to \"read_feature\" failed")) goto quit_error; /* set item content feature */ SMapSetObject(ic->content->features, feat_name, featObject, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "Call to \"SMapSetObject\" failed")) goto quit_error; /* feat name is copied */ S_FREE(feat_name); /* sets to NULL */ featObject = NULL; break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_item_contents", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"element_skip\" failed")) goto quit_error; } } break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "read_item_contents", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "read_item_contents", "ebmlRead method \"element_skip\" failed")) goto quit_error; } } /* here everything went OK */ return items_content_table; /* errors here, clean up code */ quit_error: if (ic != NULL) { if (ic->content != NULL) S_FORCE_DELETE(ic->content, "read_item_contents", error); S_FREE(ic); } if (items_content_table != NULL) { s_erc local_err = S_SUCCESS; s_hash_table_delete(items_content_table, &local_err); S_CHK_ERR(&local_err, S_CONTERR, "read_item_contents", "Call to \"s_hash_table_delete\" failed"); } if (item_content_id != NULL) S_FREE(item_content_id); return NULL; }
static void Run(const SUttProcessor *self, SUtterance *utt, s_erc *error) { SHTSEngineMESynthUttProc105 *HTSsynth = (SHTSEngineMESynthUttProc105*)self; SPlugin *audioPlugin; const SRelation *segmentRel; SAudio *audio = NULL; s_bool is_present; char **label_data = NULL; int label_size; const SItem *item; const SItem *itemItr; int counter; uint i; int frame; int state; const double rate = HTSsynth->engine.global.fperiod * 1e+7 / HTSsynth->engine.global.sampling_rate; int nstate; S_CLR_ERR(error); /* we require the segment relation */ is_present = SUtteranceRelationIsPresent(utt, "Segment", 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 'Segment' relation in utterance"); goto quit_error; } segmentRel = SUtteranceGetRelation(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceGetRelation\" failed")) goto quit_error; item = SRelationHead(segmentRel, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SRelationHead\" failed")) goto quit_error; itemItr = item; label_size = 0; while (itemItr != NULL) { label_size++; itemItr = SItemNext(itemItr, error); } label_data = S_CALLOC(char*, label_size); itemItr = item; counter = 0; while (itemItr != NULL) { SObject *dFeat; const char *tmp; dFeat = SItemPathToFeatProc(itemItr, "hts_labels", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemPathToFeatProc\" failed")) goto quit_error; if (dFeat == NULL) { S_CTX_ERR(error, S_FAILURE, "Run", "Failed to generate hts labels for segment item"); goto quit_error; } tmp = SObjectGetString(dFeat, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SObjectGetString\" failed")) goto quit_error; label_data[counter++] = s_strdup(tmp, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"s_strdup\" failed")) goto quit_error; SItemSetObject((SItem*)itemItr, "hts_label", dFeat, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetObject\" failed")) goto quit_error; itemItr = SItemNext(itemItr, error); } /* speech synthesis part */ HTS_Engine_load_label_from_string_list(&(HTSsynth->engine), label_data, label_size); check_and_change_rate_volume(HTSsynth, utt, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"check_and_change_rate_volume\" failed")) goto quit_error; HTS_Engine_create_sstream(&(HTSsynth->engine)); check_and_change_tone(HTSsynth, utt, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"check_and_change_tone\" failed")) goto quit_error; HTS_Engine_create_pstream(&(HTSsynth->engine)); if (HTSsynth->me == TRUE) /* mixed excitation */ { HTS_Engine_create_gstream_me(&(HTSsynth->engine), HTSsynth->me_num_filters, HTSsynth->me_filter_order, HTSsynth->me_filter, HTSsynth->xp_sig, HTSsynth->xn_sig, HTSsynth->hp, HTSsynth->hn, HTSsynth->pd_filter, HTSsynth->pd_filter_order); } else { HTS_Engine_create_gstream(&(HTSsynth->engine)); } nstate = HTS_Speect_ModelSet_get_nstate(&(HTSsynth->engine)); itemItr = item; counter = 0; frame = 0; state = 0; while (itemItr != NULL) { int j; int duration = 0; float tmp; for (j = 0; j < nstate; j++) duration += HTS_Speect_SStreamSet_get_duration(&(HTSsynth->engine), state++); tmp = frame * rate; SItemSetFloat((SItem*)itemItr, "start", tmp/1e+7, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetFloat\" failed")) goto quit_error; tmp = (frame + duration) * rate; SItemSetFloat((SItem*)itemItr, "end", tmp/1e+7, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SItemSetFloat\" failed")) goto quit_error; frame += duration; itemItr = SItemNext(itemItr, error); counter++; } /* We need to give the utterance the audio plug-in. If we don't do * this and the voice is deleted before the utterance, then the * utterance can't do *anything* with the audio. Not even delete * it (segfault). This should be fast because it is already * loaded. * Note that this happens before the audio is set. This is because * utt features are a list implementation. */ audioPlugin = s_pm_load_plugin("audio.spi", error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceSetFeature\" failed")) goto quit_error; SUtteranceSetFeature(utt, "audio_plugin", S_OBJECT(audioPlugin), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceSetFeature\" failed")) { S_DELETE(audioPlugin, "Run", error); goto quit_error; } /* create an audio object */ audio = S_NEW(SAudio, error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Failed to create new 'SAudio' object")) goto quit_error; /* set audio feature in utterance */ SUtteranceSetFeature(utt, "audio", S_OBJECT(audio), error); if (S_CHK_ERR(error, S_CONTERR, "Run", "Call to \"SUtteranceSetFeature\" failed")) { S_DELETE(audio, "Run", error); goto quit_error; } audio->sample_rate = HTSsynth->engine.global.sampling_rate; audio->num_samples = (uint32)HTS_Speect_GStreamSet_get_total_nsample(&(HTSsynth->engine)); audio->samples = S_MALLOC(float, audio->num_samples); if (audio->samples == NULL) { S_FTL_ERR(error, S_MEMERROR, "Run", "Failed to allocate memory for 'float' object"); goto quit_error; } /* write data */ for (i = 0; i < audio->num_samples; i++) audio->samples[i] = (float)(HTS_Speect_GStreamSet_get_speech(&(HTSsynth->engine), i) * 1.0); for (counter = 0; counter < label_size; counter++) S_FREE(label_data[counter]); S_FREE(label_data); HTS_Engine_refresh(&(HTSsynth->engine)); /* all OK here */ return; /* error clean-up code */ quit_error: if (label_data != NULL) { for (counter = 0; counter < label_size; counter++) { if (label_data[counter] != NULL) S_FREE(label_data[counter]); } S_FREE(label_data); } return; }
S_LOCAL SUtterance *s_read_utt_ebml(SDatasource *ds, s_erc *error) { SUtterance *utt = NULL; SEbmlRead *ebmlReader = NULL; s_hash_table *items_content_table = NULL; uint32 id; int scomp; s_bool container_exhausted; S_CLR_ERR(error); /* create and initialize ebml reader */ ebmlReader = S_NEW(SEbmlRead, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Failed to create new SEbmlRead object")) goto quit_error; S_EBMLREAD_CALL(ebmlReader, read_init)(&ebmlReader, ds, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Failed to initialize SEbmlRead object")) goto quit_error; /* check that we have the correct doc type */ scomp = s_strcmp(ebmlReader->header->doctype, "spct_utt", error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Call to \"s_strcmp\" failed")) goto quit_error; if (scomp != 0) { S_CTX_ERR(error, S_FAILURE, "s_read_utt_ebml", "Ebml file format not of type 'spct_utt', read format is '%s'", ebmlReader->header->doctype); goto quit_error; } /* create and initialize new utterance */ utt = S_NEW(SUtterance, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Failed to create new utterance")) goto quit_error; SUtteranceInit(&utt, NULL, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Failed to initialize new utterance")) goto quit_error; /* read top level container */ id = S_EBMLREAD_CALL(ebmlReader, container)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "ebmlRead method \"container\" failed")) goto quit_error; /* sanity check id */ S_EBML_ID_SANITY(id, S_UTT_EBML, "s_read_utt_ebml", "ID mismatch", error); while (1) { container_exhausted = S_EBMLREAD_CALL(ebmlReader, container_at_end)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "ebmlRead method \"container_at_end\" failed")) goto quit_error; if (container_exhausted) break; /* we are finished reading the utterance file */ /* peek id for utterance elements */ id = S_EBMLREAD_CALL(ebmlReader, peek_id)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "ebmlRead method \"peek_id\" failed")) goto quit_error; switch(id) { case S_UTT_EBML_FEATURES: { read_utt_features(utt, ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Call to \"read_utt_features\" failed")) goto quit_error; break; } case S_UTT_EBML_ITEMS_CONTENTS: { items_content_table = read_item_contents(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Call to \"read_item_contents\" failed")) goto quit_error; break; } case S_UTT_EBML_RELATIONS: { read_utt_relations(ebmlReader, utt, items_content_table, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "Call to \"read_utt_relations\" failed")) goto quit_error; break; } default: /* unknown elements, skip */ S_WARNING(S_FAILURE, "s_read_utt_ebml", "Skipping element with unknown id '0x%x'", id); S_EBMLREAD_CALL(ebmlReader, element_skip)(ebmlReader, error); if (S_CHK_ERR(error, S_CONTERR, "s_read_utt_ebml", "ebmlRead method \"element_skip\" failed")) goto quit_error; } } /* if we get here then everything was OK */ goto quit; /* errors start clean up code here */ quit_error: if (utt != NULL) S_DELETE(utt, "s_read_utt_ebml", error); /* sets utt = NULL */ if (items_content_table != NULL) { s_erc local_err = S_SUCCESS; s_hash_table_delete(items_content_table, &local_err); items_content_table = NULL; } /* normal exit start clean up code here */ quit: if (items_content_table != NULL) delete_unused_items_content(items_content_table, error); if (ebmlReader != NULL) S_DELETE(ebmlReader, "s_read_utt_ebml", error); return utt; }
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; }
static SList *MapPyValKeys(const SMap *self, s_erc *error) { SMapPy *pMap = (SMapPy*)self; SListPy *pyList; PyObject *keys; S_CLR_ERR(error); S_CHECK_PY_MAP(pMap, "MapPyValKeys"); keys = PyDict_Keys(S_PY_DICT(pMap)); if (keys == NULL) { char *py_error = s_get_python_error_str(); if (py_error) { S_CTX_ERR(error, S_FAILURE, "MapPyValKeys", "Call to \"PyDict_Keys\" failed. Reported error: %s", py_error); S_FREE(py_error); } else { S_CTX_ERR(error, S_FAILURE, "MapPyValKeys", "Call to \"PyDict_Keys\" failed"); } return NULL; } pyList = S_NEW(SListPy, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyValKeys", "Failed to create new 'SListPy' object")) { /* decrement reference of keys */ Py_XDECREF(keys); return NULL; } SListPyInit(&pyList, keys, error); if (S_CHK_ERR(error, S_CONTERR, "MapPyValKeys", "Call to \"SListPyInit\" failed")) { /* decrement reference of keys */ Py_XDECREF(keys); return NULL; } /* decrement reference of keys */ Py_XDECREF(keys); return S_LIST(pyList); /* for S_CHECK_PY_MAP */ failure: return NULL; }
S_LOCAL void concat_units(SRelp *self, const SRelation *unitRel, s_erc *error) { S_CLR_ERR(error); /* get the number of frames in the track */ self->num_frames = get_num_frames(self, unitRel, error); if (S_CHK_ERR(error, S_CONTERR, "concat_units", "Call to \"get_num_frames\" failed")) return; if (self->symmetric == FALSE) { self->pmIndx = S_NEW(SArrayInt, error); if (S_CHK_ERR(error, S_CONTERR, "concat_units", "Failed to create new 'SArrayInt' object")) return; self->pmIndx->i = S_CALLOC(sint32, self->num_frames); if (self->pmIndx->i == NULL) { S_FTL_ERR(error, S_CONTERR, "concat_units", "Failed to allocate memory for 'sint32' object"); return; } self->pmIndx->count = self->num_frames; } /* setup new track */ self->track = S_NEW(STrackFloat, error); if (S_CHK_ERR(error, S_CONTERR, "concat_units", "Failed to create new 'STrackFloat' object")) return; self->track->time = S_CALLOC(float, self->num_frames); if (self->track->time == NULL) { S_FTL_ERR(error, S_CONTERR, "concat_units", "Failed to allocate memory for 'float' object"); return; } self->track->data->f = S_CALLOC(float*, self->num_frames); if (self->track->data->f == NULL) { S_FTL_ERR(error, S_CONTERR, "concat_units", "Failed to allocate memory for 'float*' object"); return; } self->track->data->row_count = self->num_frames; self->track->data->col_count = self->num_channels; /* setup residuals */ self->residuals = S_CALLOC(SArrayInt*, self->num_frames); if (self->residuals == NULL) { S_FTL_ERR(error, S_CONTERR, "concat_units", "Failed to allocate memory for 'SArrayInt*' object"); return; } /* copy track + res info */ copy_lpc_residuals(self, unitRel, error); S_CHK_ERR(error, S_CONTERR, "concat_units", "Call to \"copy_lpc_residuals\" failed"); }