public void testStretch2() { double[] signal = FFTTest.getSampleSignal(16000); int samplingRate = 8000; double rateFactor = 0.5; NaiveVocoder nv = new NaiveVocoder(new BufferedDoubleDataSource(signal), samplingRate, rateFactor); double[] result = nv.getAllData(); double meanSignalEnergy = MathUtils.mean(MathUtils.multiply(signal, signal)); double meanResultEnergy = MathUtils.mean(MathUtils.multiply(result, result)); double percentDifference = Math.abs(meanSignalEnergy - meanResultEnergy) / meanSignalEnergy * 100; assertTrue( "Stretching changed signal energy by " + percentDifference + "%", percentDifference < 6); }
@Override public boolean compute() throws IOException, MaryConfigurationException { logger.info("Duration tree trainer started."); FeatureFileReader featureFile = FeatureFileReader.getFeatureFileReader(getProp(FEATUREFILE)); UnitFileReader unitFile = new UnitFileReader(getProp(UNITFILE)); FeatureVector[] allFeatureVectors = featureFile.getFeatureVectors(); int maxData = Integer.parseInt(getProp(MAXDATA)); if (maxData == 0) maxData = allFeatureVectors.length; FeatureVector[] featureVectors = new FeatureVector[Math.min(maxData, allFeatureVectors.length)]; System.arraycopy(allFeatureVectors, 0, featureVectors, 0, featureVectors.length); logger.debug( "Total of " + allFeatureVectors.length + " feature vectors -- will use " + featureVectors.length); AgglomerativeClusterer clusterer = new AgglomerativeClusterer( featureVectors, featureFile.getFeatureDefinition(), null, new DurationDistanceMeasure(unitFile), Float.parseFloat(getProp(PROPORTIONTESTDATA))); DirectedGraphWriter writer = new DirectedGraphWriter(); DirectedGraph graph; int iteration = 0; do { graph = clusterer.cluster(); iteration++; if (graph != null) { writer.saveGraph(graph, getProp(DURTREE) + ".level" + iteration); } } while (clusterer.canClusterMore()); if (graph == null) { return false; } // Now replace each leaf with a FloatLeafNode containing mean and stddev for (LeafNode leaf : graph.getLeafNodes()) { FeatureVectorLeafNode fvLeaf = (FeatureVectorLeafNode) leaf; FeatureVector[] fvs = fvLeaf.getFeatureVectors(); double[] dur = new double[fvs.length]; for (int i = 0; i < fvs.length; i++) { dur[i] = unitFile.getUnit(fvs[i].getUnitIndex()).duration / (float) unitFile.getSampleRate(); } double mean = MathUtils.mean(dur); double stddev = MathUtils.standardDeviation(dur, mean); FloatLeafNode floatLeaf = new FloatLeafNode(new float[] {(float) stddev, (float) mean}); Node mother = fvLeaf.getMother(); assert mother != null; if (mother.isDecisionNode()) { ((DecisionNode) mother).replaceDaughter(floatLeaf, fvLeaf.getNodeIndex()); } else { assert mother.isDirectedGraphNode(); assert ((DirectedGraphNode) mother).getLeafNode() == fvLeaf; ((DirectedGraphNode) mother).setLeafNode(floatLeaf); } } writer.saveGraph(graph, getProp(DURTREE)); return true; }