コード例 #1
0
static s_bool _item_match(const char *PATT, const char *THING, const SMap *sets,
						  s_erc *error)
{
	int rv;
	s_bool is_present;
	const SObject *tmp;
	const SList *setList;
	SObject *thingObject;

	S_CLR_ERR(error);
	rv = s_strcmp(PATT, THING, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_item_match",
				  "Call to \"s_strcmp\" failed"))
		return FALSE;

	if (rv == 0)
		return TRUE;

	if (sets == NULL)
		return FALSE;

	tmp = SMapGetObjectDef(sets, PATT, NULL, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_item_match",
				  "Call to \"SMapGetObjectDef\" failed"))
		return FALSE;

	if (tmp == NULL)
		return FALSE;

	setList = S_CAST(tmp, SList, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_item_match",
				  "Call to \"S_CAST(SList)\" failed"))
		return FALSE;

	thingObject = SObjectSetString(THING, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_item_match",
				  "Call to \"SObjectSetString\" failed"))
		return FALSE;

	is_present = SListValPresent(setList, thingObject, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_item_match",
				  "Call to \"SListValPresent\" failed"))
	{
		S_DELETE(thingObject, "_item_match", error);
		return FALSE;
	}

	S_DELETE(thingObject, "_item_match", error);
	return is_present;
}
コード例 #2
0
ファイル: primitives.c プロジェクト: Oghma/speect
static SObject *CopyString(const SObject *self, s_erc *error)
{
    SObject *newString;
    const char *s;


    S_CLR_ERR(error);
    s = ((SString*)self)->s;
    newString = SObjectSetString(s, error);
    if (S_CHK_ERR(error, S_FAILURE,
                  "CopyString",
                  "Call to \"SObjectSetString\" failed"))
    {
        if (newString != NULL)
            S_DELETE(newString, "CopyString", error);
        return NULL;
    }

    return newString;
}
コード例 #3
0
ファイル: phrase_type.c プロジェクト: mivoq/speect
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	char* type;

	SPhraseTypeFeatProc *castSelf = S_CAST(self, SPhraseTypeFeatProc, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "Initialize",
		      "Call to S_CAST failed"))
		goto quit_error;

	type = setSentenceType(item, castSelf->symbols, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SetSentenceType\" failed"))
		goto quit_error;

	if( type == NULL )
		goto quit_error;

	extractedFeat = SObjectSetString( type, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetString\" failed"))
		goto quit_error;

	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
	S_UNUSED(item);
}
コード例 #4
0
ファイル: load_addendum.c プロジェクト: Cyofanni/speect
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);
}
コード例 #5
0
ファイル: syll_test.c プロジェクト: Oghma/speect
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;
}
コード例 #6
0
ファイル: phrase_endtone.c プロジェクト: Oghma/speect
static SObject *Run(const SFeatProcessor *self, const SItem *item,
                    s_erc *error)
{
    SObject *extractedFeat = NULL;
    s_bool found = FALSE;

    SItem *boundary = SItemLastDaughter ( item, error);
    if (S_CHK_ERR(error, S_CONTERR,
                  "Run",
                  "Call to \"SItemLastDaughter\" failed"))
        goto quit_error;

    boundary = SItemAs (boundary, "Boundaries", error);
    if (S_CHK_ERR(error, S_CONTERR,
                  "Run",
                  "Call to \"SItemAs\" failed"))
        goto quit_error;

    SItem * boundaryNext = SItemNext (boundary, error);
    if (S_CHK_ERR(error, S_CONTERR,
                  "Run",
                  "Call to \"SItemNext\" failed"))
        goto quit_error;

    if (boundaryNext != NULL)
        boundary = boundaryNext;

    while (!found && boundary != NULL)
    {
        found = SItemFeatureIsPresent( boundary, "tobi_endtone", error);
        if (S_CHK_ERR(error, S_CONTERR,
                      "Run",
                      "Call to \"SItemFeatureIsPresent\" failed"))
            goto quit_error;

        if (!found)
        {
            boundary = SItemPrev(boundary, error );
            if (S_CHK_ERR(error, S_CONTERR,
                          "Run",
                          "Call to \"SItemPrev\" failed"))
                goto quit_error;
        }
    }

    if ( found )
    {
        const char* tone = SItemGetString( boundary, "tobi_endtone", error);
        if (S_CHK_ERR(error, S_CONTERR,
                      "Run",
                      "Call to \"SItemGetFeature\" failed"))
            goto quit_error;

        extractedFeat = SObjectSetString( tone, error);
        if (S_CHK_ERR(error, S_CONTERR,
                      "Run",
                      "Call to \"SObjectSetString\" failed"))
            goto quit_error;
    }

    return extractedFeat;

    /* error cleanup */
quit_error:
    if (extractedFeat != NULL)
        S_DELETE(extractedFeat, "Run", error);

    return NULL;

    S_UNUSED(self);
    S_UNUSED(item);
}
コード例 #7
0
ファイル: syl_vowel.c プロジェクト: Oghma/speect
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SItem *itemInSylStructRel;
	const SItem *segment;
	const SPhoneset *phoneset;
	s_bool multilingual = FALSE;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	/* get the phoneset */
	phoneset = _get_phoneset(item, &multilingual, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"_get_phoneset\" failed"))
		return NULL;

	itemInSylStructRel = SItemAs(item, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		goto quit_error;

	segment = SItemDaughter(itemInSylStructRel, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemDaughter\" failed"))
		goto quit_error;

	while (segment != NULL)
	{
		s_bool is_vowel;
		const char *item_name;


		item_name = SItemGetName(segment, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemGetName\" failed"))
			goto quit_error;

		if (item_name == NULL)
			continue;

		is_vowel = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset,
																item_name,
																"vowel",
																error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"phone_has_feature\" failed"))
			goto quit_error;

		if (is_vowel)
		{
			if (multilingual)
			{
				extractedFeat = SItemPathToFeatProc(segment,
													"segment_name_multilingual",
													error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SItemPathToFeatProc\" failed"))
					goto quit_error;
			}
			else
			{
				extractedFeat = SObjectSetString(item_name, error);
				if (S_CHK_ERR(error, S_CONTERR,
							  "Run",
							  "Call to \"SObjectSetString\" failed"))
					goto quit_error;
			}

			return extractedFeat;
		}

		segment = SItemNext(segment, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SItemNext\" failed"))
			goto quit_error;
	}

	/* did not find a vowel */
	extractedFeat = SObjectSetString("novowel", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetString\" failed"))
		goto quit_error;

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
コード例 #8
0
ファイル: read.c プロジェクト: Cyofanni/speect
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;
}
コード例 #9
0
ファイル: voice.c プロジェクト: Cyofanni/speect
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;
		}
	}
}
コード例 #10
0
ファイル: py_list_example.c プロジェクト: Cyofanni/speect
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;
}
コード例 #11
0
ファイル: hts_labels.c プロジェクト: Oghma/speect
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	char *hts_label = NULL;
	char *tmp = NULL;
	const SItem *segItem;
	s_bool is_pause;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	segItem = SItemAs(item, "Segment", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemAs\" failed"))
		goto quit_error;

	if (segItem == NULL)
		return NULL;

	is_pause = segment_is_pause(segItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"segment_is_pause\" failed"))
		goto quit_error;

	/* get phone context */
	tmp = create_phone_context(segItem, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"create_phone_context\" failed"))
		goto quit_error;

	s_sappend(&hts_label, tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"s_sappend\" failed"))
		goto quit_error;

	S_FREE(tmp);

	if (is_pause)
	{
		/* syllable context */
		tmp = create_syl_context_pause(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_syl_context_pause\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* A context */
		tmp = create_A_context_pause(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_A_context_pause\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* B context */
		tmp = create_B_context_pause(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_B_context_pause\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* C context */
		tmp = create_C_context_pause(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_C_context_pause\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);
	}
	else
	{
		/* syllable context */
		tmp = create_syl_context(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_syl_context\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* A context */
		tmp = create_A_context(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_A_context\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* B context */
		tmp = create_B_context(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_B_context\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);

		/* C context */
		tmp = create_C_context(segItem, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"create_C_context\" failed"))
			goto quit_error;

		s_sappend(&hts_label, tmp, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"s_sappend\" failed"))
			goto quit_error;

		S_FREE(tmp);
	}

	extractedFeat = SObjectSetString(hts_label, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SObjectSetString\" failed"))
		goto quit_error;

	S_FREE(hts_label);

	/* all OK here */
	return extractedFeat;

	/* error cleanup */
quit_error:
	if (tmp != NULL)
		S_FREE(tmp);

	if (hts_label != NULL)
		S_FREE(hts_label);

	if (extractedFeat != NULL)
		S_DELETE(extractedFeat, "Run", error);

	return NULL;

	S_UNUSED(self);
}
コード例 #12
0
ファイル: write.c プロジェクト: Cyofanni/speect
static void add_info(SList *info, float start, float end, const char *name, s_erc *error)
{
	SList *itemList = NULL;
	SObject *tmp = NULL;


	S_CLR_ERR(error);
	itemList = S_LIST(S_NEW(SListList, error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Failed to create new list for item info"))
		goto quit;

	tmp = SObjectSetFloat(start, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SObjectSetFloat\" failed"))
		goto quit;

	SListAppend(itemList, tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SListAppend\" failed"))
		goto quit;

	tmp = SObjectSetFloat(end, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SObjectSetFloat\" failed"))
		goto quit;

	SListAppend(itemList, tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SListAppend\" failed"))
		goto quit;

	tmp = SObjectSetString(name, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SObjectSetString\" failed"))
		goto quit;

	SListAppend(itemList, tmp, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SListAppend\" failed"))
		goto quit;

	tmp = NULL;
	SListAppend(info, S_OBJECT(itemList), error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "add_info",
				  "Call to \"SListAppend\" failed"))
		goto quit;

	itemList = NULL;

quit:
	if (itemList != NULL)
		S_DELETE(itemList, "add_info", error);

	if (tmp != NULL)
		S_DELETE(tmp, "add_info", error);
}