예제 #1
0
파일: hts_labels.c 프로젝트: Oghma/speect
static s_bool segment_is_pause(const SItem *item, s_erc *error)
{
	const SVoice *voice;
	const SPhoneset *phoneset;
	s_bool is_pause;


	S_CLR_ERR(error);

	voice = SItemVoice(item, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "segment_is_pause",
				  "Call to \"SItemVoice\" failed"))
		return FALSE;

	if (voice == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "segment_is_pause",
				  "Item voice is NULL, voice is required to get phoneset");
		return FALSE;
	}

	phoneset = S_PHONESET(SVoiceGetData(voice, "phoneset", error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "segment_is_pause",
				  "Call to \"SVoiceGetData\" failed"))
		return FALSE;

	if (phoneset == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "segment_is_pause",
				  "Phoneset is NULL, phoneset is required to get silence phone");
		return FALSE;
	}

	is_pause = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset,
															SItemGetName(item, error),
															"pause",
															error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "segment_is_pause",
				  "Call to \"phone_has_feature/SItemGetName\" failed"))
		return FALSE;

	return is_pause;
}
예제 #2
0
static void s_get_lexical_objects(const SUttProcessor *self, SUtterance *utt,
								  SG2P **g2p, SLexicon **lexicon, SAddendum **addendum,
								  SSyllabification **syllab, s_erc *error)
{
	const SVoice *voice;


	S_CLR_ERR(error);

	voice = SUtteranceVoice(utt, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SUtteranceVoice\" failed"))
		return;

	*g2p = (SG2P*)SVoiceGetData(voice , "g2p", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	*lexicon = (SLexicon*)SVoiceGetData(voice , "lexicon", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	*addendum = (SAddendum*)SVoiceGetData(voice , "addendum", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	/* first try for syllabification in voice data, new method */
	*syllab = (SSyllabification*)SVoiceGetData(voice , "syllabification", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_get_lexical_objects",
				  "Call to \"SVoiceGetData\" failed"))
		return;

	/* if not found try old method */
	if ((*syllab) == NULL)
	{
		*syllab = (SSyllabification*)SMapGetObjectDef(self->features , "_syll_func", NULL,
													  error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "s_get_lexical_objects",
					  "Call to \"SMapGetObjectDef\" failed"))
			return;
	}

	/* now check for least requirements */
	if ((*addendum == NULL)
		&& (*lexicon == NULL)
		&& (*g2p == NULL))
	{
		S_CTX_ERR(error, S_FAILURE,
				  "s_get_lexical_objects",
				  "No grapheme to phoneme conversion options (lexicon, addendum, g2p) "
				  "found in voice");
		return;
	}
}
예제 #3
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;
}
예제 #4
0
static SObject *Run(const SFeatProcessor *self, const SItem *item,
					s_erc *error)
{
	SObject *extractedFeat = NULL;
	const SVoice *voice;
	const SPhoneset *phoneset;
	const char *feature;
	const char *begin;
	const char *token;
	s_bool feature_value;


	S_CLR_ERR(error);

	if (item == NULL)
		return NULL;

	voice = SItemVoice(item, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemVoice\" failed"))
		return NULL;

	if (voice == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Run",
				  "Item voice is NULL, voice is required to get phoneset");
		return NULL;
	}

	phoneset = S_PHONESET(SVoiceGetData(voice, "phoneset", error));
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SVoiceGetData\" failed"))
		return NULL;

	if (phoneset == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "Run",
				  "Phoneset is NULL, phoneset is required to get phone feature");
		return NULL;
	}

	token = SItemGetString(item, "_phoneset_feature", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"SItemGetString\" failed"))
		return NULL;

	/* get part of token (actual feature), after _ */
	begin = s_strchr(token, '_', error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "SItemPath",
				  "Call to \"s_strchr\" failed"))
		return NULL;

	if (begin != NULL)
	{
		feature = begin + 1;
	}
	else
	{
		/* no feature */
		return NULL;
	}

	feature_value = S_PHONESET_CALL(phoneset, phone_has_feature)(phoneset,
																 SItemGetName(item, error),
																 feature,
																 error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "Run",
				  "Call to \"phone_has_feature/SItemGetName\" failed"))
		return NULL;

	if (feature_value == TRUE)
	{
		extractedFeat = SObjectSetInt(1, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetInt\" failed"))
			return NULL;
	}
	else
	{
		extractedFeat = SObjectSetInt(0, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SObjectSetInt\" failed"))
			return NULL;
	}

	return extractedFeat;


	return NULL;

	S_UNUSED(self);
}
예제 #5
0
파일: syl_vowel.c 프로젝트: Oghma/speect
static const SPhoneset *_get_phoneset(const SItem *item, s_bool *multilingual, s_erc *error)
{
	const SPhoneset *phoneset;
	const SVoice *voice;
	s_bool is_present;


	S_CLR_ERR(error);

	/* get the voice */
	voice = SItemVoice(item, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_get_phoneset",
				  "Call to \"SItemVoice\" failed"))
		return NULL;

	if (voice == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "_get_phoneset",
				  "Item voice is NULL, voice is required to get phoneset");
		return NULL;
	}

	/*
	 * do we have a 'voices' feature in the voice,
	 * i.e. is this a multilingual voice
	 */
	is_present = SVoiceFeatureIsPresent(voice, "voices", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "_get_phoneset",
				  "Call to \"SVoiceFeatureIsPresent\" failed"))
		return NULL;

	if (is_present)
	{
		/* This is a multilingual voice.
		 * Get language feature of item, which is language feature
		 * of item's token.
		 */
		const SItem *tokenItem;
		const char *lang;
		const SMap *voicesMap;
		const SVoice *thisVoice;


		(*multilingual) = TRUE;
		tokenItem = SItemPathToItem(item, "R:SylStructure.parent.R:Token.parent",
									error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_get_phoneset",
					  "Call to \"SItemPathToItem\" failed"))
			return NULL;

		if (tokenItem == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "_get_phoneset",
					  "Failed to find item's token, which is required to get language feature");
			return NULL;
		}

		lang = SItemGetString(tokenItem, "lang", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_get_phoneset",
					  "Call to \"SItemGetString\" failed"))
			return NULL;

		/* now get the phoneset */
		voicesMap = (const SMap*)SVoiceGetFeature(voice, "voices", error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_get_phoneset",
					  "Call to \"SVoiceGetFeature\" failed"))
			return NULL;

		thisVoice = (const SVoice*)SMapGetObjectDef(voicesMap, lang, NULL, error);
		if (S_CHK_ERR(error, S_CONTERR,
					  "_get_phoneset",
					  "Call to \"SMapGetObjectDef\" failed"))
			return NULL;

		if (thisVoice == NULL)
		{
			S_CTX_ERR(error, S_FAILURE,
					  "_get_phoneset",
					  "Failed to find the voice for language '%s', which is required to get the phoneset", lang);
			return NULL;
		}

		phoneset = S_PHONESET(SVoiceGetData(thisVoice, "phoneset", error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "_get_phoneset",
					  "Call to \"SVoiceGetData\" failed"))
			return NULL;
	}
	else
	{
		/* not multilingual voice */
		(*multilingual) = FALSE;

		phoneset = S_PHONESET(SVoiceGetData(voice, "phoneset", error));
		if (S_CHK_ERR(error, S_CONTERR,
					  "Run",
					  "Call to \"SVoiceGetData\" failed"))
			return NULL;
	}

	if (phoneset == NULL)
	{
		S_CTX_ERR(error, S_FAILURE,
				  "_get_phoneset",
				  "Item phoneset is NULL, required to extract phone features");
		return NULL;
	}

	return phoneset;
}
예제 #6
0
static void s_compute_phonetic_features (SItem* word, s_erc *error )
{
	SItem *syllable;
	SItem * phone;
	char* position_in_syllable_string = NULL;

	/* Extract Phoneset from Voice*/
	const SVoice* voice = SItemVoice (word, error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_compute_phonetic_features",
				  "Call to \"SItemGetVoice\" failed"))
		return;

	const SPhoneset* phoneset = (SPhoneset*)SVoiceGetData(voice, "phoneset", error);
	if (S_CHK_ERR(error, S_CONTERR,
				  "s_compute_phonetic_features",
				  "Call to \"SVoiceGetData\" failed"))
		return;
	SItem *wordAsSylStructure = SItemAs(word, "SylStructure", error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "s_compute_stresses",
		      "Call to \"SItemAs\" failed"))
		return;

	syllable = SItemDaughter(wordAsSylStructure, error);
	if (S_CHK_ERR(error, S_CONTERR,
		      "s_compute_stresses",
		      "Call to \"SItemDaughter\" failed"))
		return;

	while (syllable != NULL)
	{
		phone = SItemDaughter(syllable, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "s_compute_phonetic_features",
			      "Call to \"SItemDaughter\" failed"))
			return;

		s_bool nucleusFound = FALSE;
		while (phone != NULL)
		{
			const char* phone_value = SItemGetName(phone, error);
			if (S_CHK_ERR(error, S_CONTERR,
				      "s_compute_phonetic_features",
				      "Call to \"SItemGetName\" failed"))
				return;
			s_bool isVowel = S_PHONESET_CALL(phoneset, phone_has_feature)
				(phoneset,
				 phone_value,
				 "vowel",
				 error);
			if (S_CHK_ERR(error, S_CONTERR,
				      "s_compute_phonetic_features",
				      "Call to \"phone_has_feature\" failed"))
				return;

			if( isVowel )
			{
				nucleusFound = TRUE;
				position_in_syllable_string = "nucleus";
			}
			else
			{
				if( nucleusFound == TRUE )
					position_in_syllable_string = "coda";
				else
					position_in_syllable_string = "onset";
			}

			SItemSetString ( phone, "syllablepart", position_in_syllable_string, error );
			if (S_CHK_ERR(error, S_CONTERR,
						  "s_compute_phonetic_features",
						  "Call to \"SItemSetString\" failed"))
				return;

			s_bool hasLong = S_PHONESET_CALL(phoneset, phone_has_feature)
				(phoneset,
				 phone_value,
				 "duration_long",
				 error);
			if (S_CHK_ERR(error, S_CONTERR,
				      "s_compute_phonetic_features",
				      "Call to \"phone_has_feature\" failed"))
				return;

			s_bool hasShort = S_PHONESET_CALL(phoneset, phone_has_feature)
				(phoneset,
				 phone_value,
				 "duration_short",
				 error);
			if (S_CHK_ERR(error, S_CONTERR,
				      "s_compute_phonetic_features",
				      "Call to \"phone_has_feature\" failed"))
				return;

			const char * feat = NULL;
			if( hasLong )
			{
				feat = "+";
			}
			else if( hasShort )
			{
				feat = "-";
			}

			if(feat != NULL)
			{
				SItemSetString ( phone, "duration", feat, error );
				if (S_CHK_ERR(error, S_CONTERR,
					      "s_compute_phonetic_features",
					      "Call to \"SItemSetString\" failed"))
					return;
			}

			phone = SItemNext ( phone, error);
			if (S_CHK_ERR(error, S_CONTERR,
				      "s_compute_phonetic_features",
				      "Call to \"SItemNext\" failed"))
				return;
		}

		syllable = SItemNext (syllable, error);
		if (S_CHK_ERR(error, S_CONTERR,
			      "s_compute_phonetic_features",
			      "Call to \"SItemNext\" failed"))
			return;
	}

}