⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 featureprocessors.java

📁 这是java 开发的的免费语音播放插件,很值得学习参考!!!!!!!!!!!!111
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * processing	 */	public String process(Item syl) throws ProcessException {	    int count = 0;	    Item daughter = syl.getItemAs(                Relation.SYLLABLE_STRUCTURE).getLastDaughter();	    while (daughter != null) {		if ("+".equals(getPhoneFeature(daughter, "vc"))) {		    break;		}		daughter = daughter.getPrevious();		count++;	    }	    return Integer.toString(rail(count));	}    }    /**     * Checks for fricative     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegCodaFric implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 * 	 * @return "1" if fricative; else "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segCodaCtype(seg, "f");	}    }    /**     * Checks for fricative     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegOnsetFric implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 * 	 * @return "1" if fricative; else "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segOnsetCtype(seg, "f");	}    }    /**     * Checks for coda stop     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegCodaStop implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if coda stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segCodaCtype(seg, "s");	}    }    /**     * Checks for onset stop     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegOnsetStop implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if Onset Stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segOnsetCtype(seg, "s");	}    }    /**     * Checks for coda nasal     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegCodaNasal implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if coda stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segCodaCtype(seg, "n");	}    }    /**     * Checks for onset nasal     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegOnsetNasal implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if Onset Stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    return segOnsetCtype(seg, "n");	}    }    /**     * Checks for coda glide     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegCodaGlide implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if coda stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    if (segCodaCtype(seg, "r").equals("0")) {		return segCodaCtype(seg, "l");	    }	    return "1";	}    }    /**     * Checks for onset glide     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegOnsetGlide implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if coda stop "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    if (segOnsetCtype(seg, "r").equals("0")) {		return segOnsetCtype(seg, "l");	    }	    return "1";	}    }    /**     * Checks for onset coda      * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegOnsetCoda implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return if onset coda "1"; otherwise "0"	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    Item s = seg.getItemAs(Relation.SYLLABLE_STRUCTURE);            if (s == null) {                return "coda";            }            s = s.getNext();	    while (s != null) {		if ("+".equals(getPhoneFeature(s, "vc"))) {		    return "onset";		}		s = s.getNext();	    }            	    return "coda";	}    }    /**     * Counts the number of phrases before this one.     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SubPhrases implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  item  the item to process	 *	 * @return the number of phrases before this one	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item item) throws ProcessException {	    int count = 0;	    Item inPhrase  = SUB_PHRASE_PATH.findItem(item);	    for (Item p = inPhrase; p != null; p = p.getPrevious() )  {		count++;	    }	    return Integer.toString(rail(count));	}    }    /**     * Returns the duration of the given segment     * This is a feature processor. A feature processor takes an item,     * performs some sort of processing on the item and returns an object.     */    public static class SegmentDuration implements FeatureProcessor {	/**	 * Performs some processing on the given item.	 *	 * @param  seg  the item to process	 *	 * @return the duration of the segment as a string.	 *	 * @throws ProcessException if an exception occurred during the	 * processing	 */	public String process(Item seg) throws ProcessException {	    if (seg == null) {		return "0";	    } else if (seg.getPrevious() == null) {		return seg.getFeatures().getObject("end").toString();	    } else {		return Float.toString(			seg.getFeatures().getFloat("end") -		        seg.getPrevious().getFeatures().getFloat("end")		   );	    }	}    }    /**     * Gets the phoneset feature with the given name     *     * @param item item the phoneme of interest     * @param featureName the feature of interest     *     * @return the phone feature for the item     *     */    public static String getPhoneFeature(Item item, String featureName) {	Voice voice = item.getUtterance().getVoice();	String feature = voice.getPhoneFeature(item.toString(), featureName);	return feature;    }    /**     * Classifies the type of word break     *     * @param  item  the item to process     *     * @return  "4" for a big break, "3" for  a break; otherwise "1"     *     * @throws ProcessException if an exception occurred during the     * processing     */    public static String wordBreak(Item item) throws ProcessException {	Item ww = item.getItemAs(Relation.PHRASE);	if (ww == null || ww.getNext() != null) {	    return "1";	} else {	    String pname = ww.getParent().toString();	    if (pname.equals("BB")) {		return "4";	    } else if (pname.equals("B")) {		return "3";	    } else {		return "1";	    }	}    }    /**     * Gets the punctuation associated with the word     *     * @param  item  the word to process     *     * @return  the punctuation associated with the word     *     * @throws ProcessException if an exception occurred during the     * processing     */    public static String wordPunc(Item item) throws ProcessException {	Item ww = item.getItemAs(Relation.TOKEN);	if (ww != null && ww.getNext() != null) {	    return "";	} else {	    if (ww != null && ww.getParent() != null) {		return ww.getParent().getFeatures().getString("punc");	    } else {		return "";	    }	}    }    /**     * Tests the coda ctype of the given segment.     *     * @param seg the segment to test     * @param ctype the ctype to check for     *      * @return "1" on match "0" on no match     */    private static String segCodaCtype(Item seg, String ctype) {	Item daughter 	    = seg.getItemAs(		Relation.SYLLABLE_STRUCTURE).getParent().getLastDaughter();	while (daughter != null) {	    if ("+".equals(getPhoneFeature(daughter, "vc"))) {		return "0";	    }	    if (ctype.equals(getPhoneFeature(daughter, "ctype"))) {		return "1";	    }	    daughter = daughter.getPrevious();	}	return "0";    }    /**     * Tests the onset ctype of the given segment.     *     * @param  seg  the segment to test to process     * @param ctype the ctype to check for     *     * @return if Onset Stop "1"; otherwise "0"     *     */    private static  String segOnsetCtype(Item seg, String ctype) {	Item daughter = seg.getItemAs(	    Relation.SYLLABLE_STRUCTURE).getParent().getDaughter();	while (daughter != null) {	    if ("+".equals(getPhoneFeature(daughter, "vc"))) {		return "0";	    }	    if (ctype.equals(getPhoneFeature(daughter, "ctype"))) {		return "1";	    }	    daughter = daughter.getNext();	}	return "0";    }    /**     * Determines if the given item is accented     *     * @param item the item of interest     *     * @return <code>true</code> if the item is accented, otherwise     * <code>false</code>     */    private static boolean isAccented(Item item) {	return (item.getFeatures().isPresent("accent") ||	    item.getFeatures().isPresent("endtone"));    }    /**     * Rails an int. flite never returns an int more than 19 from     * a feature processor, we duplicate that behavior     * here so that our tests will match.     *     * @param val the value to rail     *     * @return val clipped to be betweein 0 and 19     */    private static int rail(int val) {	return val > 19 ? 19 : val;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -