Beispiel #1
0
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;
}
Beispiel #2
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);
}
Beispiel #3
0
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;
}
Beispiel #4
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;
	}

}