Package com.sun.speech.freetts

Examples of com.sun.speech.freetts.Item


     */
    public void processUtterance(Utterance utterance) throws ProcessException {
  Relation segmentRelation = utterance.getRelation(Relation.SEGMENT);
        Relation targetRelation = utterance.getRelation(Relation.TARGET);

        Item segment = segmentRelation.getHead();
        Item target = null;
  if (targetRelation != null) target = targetRelation.getHead();
        float prevEnd = 0f;
        while (segment != null) {
            // String name = segment.getFeatures().getString("name");
            // Accumulated duration of all segments in the utterance,
            // in seconds:
            float end = segment.getFeatures().getFloat("end");
            // Individual duration of segment, in milliseconds:
            int dur = (int) ((end - prevEnd) * 1000);
            StringBuffer targetStringBuffer = new StringBuffer();
            while (target != null &&
                   target.getFeatures().getFloat("pos") <= end) {
                float pos = target.getFeatures().getFloat("pos");
                // time axis as percentage of segment duration:
                int percentage = ((int) ((pos - prevEnd) * 1000)) * 100 / dur;
                // f0 as an integer:
                int f0 = (int) target.getFeatures().getFloat("f0");
                targetStringBuffer.append(" ");
                targetStringBuffer.append(percentage);
                targetStringBuffer.append(" ");
                targetStringBuffer.append(f0);
                target = target.getNext();
            }
            // System.err.println(name + " " + dur + targetStringBuffer);
            segment.getFeatures().setInt("mbr_dur", dur);
            segment.getFeatures().setString("mbr_targets",
                                            targetStringBuffer.toString().trim());
View Full Code Here


     *         processing of the utterance
     */
    public void processUtterance(Utterance utterance) throws ProcessException {
        // Go through Segment relation and print values into Mbrola
  Relation segmentRelation = utterance.getRelation(Relation.SEGMENT);
        Item segment = segmentRelation.getHead();

  if (segment == null) {
      return;
  }

        // Open Mbrola
        Process process;
        try {
            process = Runtime.getRuntime().exec(cmd);
        } catch (Exception e) {
            throw new ProcessException("Cannot start mbrola program: " + cmd);
        }
        PrintWriter toMbrola = new PrintWriter(process.getOutputStream());
        BufferedInputStream fromMbrola =
            new BufferedInputStream(process.getInputStream());

        while (segment != null) {
            String name = segment.getFeatures().getString("name");
            // Individual duration of segment, in milliseconds:
            int dur = segment.getFeatures().getInt("mbr_dur");
            // List of time-f0 targets. In each target, the first value
            // indicates where on the time axis the target is reached,
            // expressed in percent of segment duration; the second value in
            // each pair is f0, in Hz.
            String targets = segment.getFeatures().getString("mbr_targets");
            String output = (name + " " + dur + " " + targets);
            // System.out.println(output);
            toMbrola.println(output);
            segment = segment.getNext();
        }

        toMbrola.flush();

        // BUG:
View Full Code Here

     *
     * @param utterance the utterance that gets the new unit relation
     */
    private void createUnitRelation(Utterance utterance) {

  Item segmentItem0, segmentItem1;
  float end0, end1;
  int targetEnd;
 
  Item unitItem0, unitItem1;
   
  String diphoneName;
     
  Relation unitRelation = utterance.createRelation(Relation.UNIT);
  Relation segmentRelation = utterance.getRelation(Relation.SEGMENT);
View Full Code Here

  if (diphone == null) {
      System.err.println
    ("FreeTTS: unit database failed to find entry for: " +
     diphoneName);
  }
  Item unit = unitRelation.appendItem();
  FeatureSet unitFeatureSet = unit.getFeatures();

  unitFeatureSet.setString("name", diphoneName);
  unitFeatureSet.setInt("target_end", targetEnd);
  unitFeatureSet.setObject("unit", new DiphoneUnit(diphone, unitPart));
  // unitFeatureSet.setInt("unit_part", unitPart);
View Full Code Here

     * @param segmentRelation the segmentRelation of interest
     * @param time the time
     */
    public static Item getItem(Relation segmentRelation, float time) {

  Item lastSegment = segmentRelation.getTail();
 
  // if given time is closer to the front than the end, search from
  // the front; otherwise, start search from end
  // this might not be the best strategy though

View Full Code Here

     * @param time the time of the Segment Item
     *
     * @return the Segment Item
     */
    public static Item findFromFront(Relation segmentRelation, float time) {
  Item item = segmentRelation.getHead();

  while (item != null &&
         time > SegmentRelationUtils.getSegmentEnd(item)) {
      item = item.getNext();
  }

  return item;
    }
View Full Code Here

     * @param time the time of the Segment Item
     *
     * @return the Segment Item
     */
    public static Item findFromEnd(Relation segmentRelation, float time) {
  Item item = segmentRelation.getTail();
   
  while (item != null &&
         SegmentRelationUtils.getSegmentEnd(item) > time) {
      item = item.getPrevious();
  }

  if (item != segmentRelation.getTail()) {
      item = item.getNext();
  }

  return item;
    }
View Full Code Here

     * Prepends a schwa to the given item
     *
     * @param item the item to prepend the schwa to.
     */
    private static void prependSchwa(Item item) {
  Item schwa = item.prependItem(null);
  schwa.getFeatures().setString("name", "ax");
  item.getItemAs(
      Relation.SYLLABLE_STRUCTURE).prependItem(schwa);
    }
View Full Code Here

    }
      }
  }

  if (utterance.getRelation(Relation.SEGMENT).getHead() != null) {
      Item first = target.getHead();
      if (first == null) {
    addTargetPoint(target, 0, mean);
      } else  if (first.getFeatures().getFloat("pos") > 0) {
        Item newItem = first.prependItem(null);
        newItem.getFeatures().setFloat("pos", 0.0f);
        newItem.getFeatures().setFloat(
          "f0", first.getFeatures().getFloat("f0"));
      }
      Item last = (Item) target.getTail();
      Item lastSegment
    = utterance.getRelation(Relation.SEGMENT).getTail();
      float segEnd = 0.0f;

      if (lastSegment != null) {
    segEnd = lastSegment.getFeatures().getFloat("end");
      }

      if (last.getFeatures().getFloat("pos") < segEnd) {
    addTargetPoint(target, segEnd, last.getFeatures().
      getFloat("f0"));
View Full Code Here

     *
     * @return the time point mid way in vowel in this syllable
     */
    private final float vowelMid(Item syllable) {
  Voice voice = syllable.getUtterance().getVoice();
  Item firstSeg  = syllable.getItemAs(
            Relation.SYLLABLE_STRUCTURE).getDaughter();
  Item segment;
  float val;

  for (segment = firstSeg; segment != null; segment =segment.getNext()) {
      // TODO refactor phone feature stuff like this so that
      // it can be understood.
      if ("+".equals(voice.getPhoneFeature(segment.toString(), "vc"))) {
    val = (segment.getFeatures().getFloat("end") +
         ((Float) vowelMidPath.findFeature(segment)).floatValue()) / 2.0f;
    return val;
      }
  }

View Full Code Here

TOP

Related Classes of com.sun.speech.freetts.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.