@Ignore
  @Test
  @Override
  public void testExactPlaceWordSpotting() throws MalformedURLException {
    // given
    URL aWavUrl = getWavFile().toURI().toURL();
    Collection<Marker> keywordMarkers =
        findKeywordSegment(SEARCH_KEY_WORD, getWavFile(), KEY_WORD_SEQUENCE_ARR);
    SignalSegment keySegment = new SignalSegment(keywordMarkers.iterator().next());
    getSpottingService().setDelta(1);
    getSpottingService().addKeySegment(keySegment);
    AcceptableSyllableThresholdDaoImpl acceptableSyllableThresholdDaoImpl =
        new AcceptableSyllableThresholdDaoImpl();
    Map<String, Double> test =
        acceptableSyllableThresholdDaoImpl.read(getRepositoryPath().getAbsolutePath(), "word");
    Double keyword_threshold = test.get(SEARCH_KEY_WORD);

    // when
    IExtractorInputReader reader = getSpottingService().createReader(aWavUrl);
    SignalSegment recalculatedFeatures =
        getSpottingService().recalculateFeatures(reader, keySegment.getMarker());
    List<RecognitionResult> matchedResults = getSpottingService().match(recalculatedFeatures);

    // then

    assertNotNull(matchedResults);
    assertTrue("Results", matchedResults.size() > 1);
    RecognitionResult matched = matchedResults.get(0);
    assertEquals("Results", SEARCH_KEY_WORD, matched.getInfo().getName());
    assertEquals(
        "Results",
        keyword_threshold,
        matched.getDetails().getDistances().get(ExtractorEnum.MFCC_EXTRACTOR.name()),
        keyword_threshold);
  }
Пример #2
0
 protected void playResult(String id) {
   //        Long lid = Long.valueOf(id);
   if ("-1".equals(id)) {
     AudioManagerFactory.createAudioManager()
         .play(
             getTargetWavURL(),
             (getTargetMarker().getStart().floatValue() / 1000),
             (getTargetMarker().getLength().floatValue() / 1000));
   }
   for (RecognitionResult recognitionResult : results) {
     if (recognitionResult.getInfo().getId().equals(id)) {
       try {
         AudioManagerFactory.createAudioManager()
             .play((new File(recognitionResult.getDetails().getAudioFilePath()).toURI().toURL()));
         break;
       } catch (MalformedURLException ex) {
         log.error(ex);
         throw new ProcessingException(ex);
       }
     }
   }
 }
Пример #3
0
 protected void showResult(String id) {
   // check if number that mean sample id
   if (Pattern.matches("^\\d*$", id)) {
     //            Long key = Long.valueOf(id);
     if (id.equals(selectedSampleId)) {
       selectedSampleId = null;
     } else {
       selectedSampleId = id;
     }
     selectedFeatureId = null;
   } else {
     // if this not a number lets say is feature id
     selectedFeatureId = id;
   }
   updateCtx(results);
   if (selectedSampleId == null) {
     getChartPanel().setRecognitionResult(null);
     getChartPanel().repaintCharts(null, null);
     return;
   }
   for (RecognitionResult recognitionResult : results) {
     if (recognitionResult.getInfo().getId().equals(selectedSampleId)) {
       getChartPanel().repaintCharts(recognitionResult, selectedFeatureId);
       //                List<Point> points =
       // recognitionResultDetails.getPath().get(selctedFeatureId);
       //                if (points != null) {
       //                    //if some feature selected paint only this feature
       //                    getChartPanel().setRecognitionResult(recognitionResultDetails,
       // selctedFeatureId);
       //                } else {
       //                    //if none feature is selected paint all features
       //                    getChartPanel().setRecognitionResult(recognitionResultDetails);
       //                }
       break;
     }
   }
   getChartPanel().repaint();
 }
Пример #4
0
  private StringBuilder representResults(List<RecognitionResult> results) {
    StringBuilder sb = new StringBuilder();
    if (results.isEmpty()) {
      return representEmptyResults();
    }
    String playImgSrc =
        getClass().getClassLoader().getResource(ImageResourcesEnum.play.getCode()).toString();

    sb.append(getI18n().getMessage(TARGET))
        .append(html(": <a href=\"play={0,number,#}\">", -1))
        .append(
            html(
                "<img src=\"{0}\" alt=\"play\" border=\"0\" width=\"24\" height=\"24\" />",
                playImgSrc))
        .append("</a>");
    sb.append("<table class=\"resultTable\">");
    sb.append("<tr><th>")
        .append(getI18n().getMessage(SAMPLE_LABEL))
        .append("</th><th>")
        .append(getI18n().getMessage(TOTAL_SCORE))
        .append("</th><th>")
        .append(FEATURE)
        .append("</th><th>")
        .append(FEATURE_SCORE)
        .append("</th><th>")
        .append(FEATURE_DISTANCE)
        .append("</th></tr>");
    for (RecognitionResult recognitionResult : results) {
      StringBuilder subTable = new StringBuilder();
      int rowsSize = 1;
      String selectionClass = "notSelected";

      if (recognitionResult.getInfo().getId().equals(selectedSampleId)) {
        selectionClass = "selected";
        rowsSize = recognitionResult.getScores().size() + 1;
        for (Entry<String, Double> scoreEntry : recognitionResult.getScores().entrySet()) {
          Double distance = recognitionResult.getDetails().getDistances().get(scoreEntry.getKey());
          subTable.append("<tr>");
          subTable
              .append(html("<td  class=\"{0}\">", selectionClass))
              .append(html("<a href=\"show={0}\">", scoreEntry.getKey()))
              .append(getI18n().getMessage(scoreEntry.getKey()))
              .append("</a>")
              .append("</td>")
              .append(html("<td  class=\"{0}\">", selectionClass))
              .append(getI18n().getDecimalFormat().format(scoreEntry.getValue()))
              .append("</td>")
              .append(html("<td  class=\"{0}\">", selectionClass))
              .append(getI18n().getDecimalFormat().format(distance))
              .append("</td>");

          subTable.append("</tr>");
        }
      }

      sb.append("<tr>");

      sb.append(html("<td ROWSPAN=\"{0}\" class=\"{1}\">", rowsSize, selectionClass));

      sb.append(html("<a href=\"play={0}\">", recognitionResult.getInfo().getId()))
          .append(
              html(
                  "<img src=\"{0}\" alt=\"play\" border=\"0\" width=\"24\" height=\"24\" />",
                  playImgSrc))
          .append("</a>")
          .append(html("<a href=\"show={0}\">", recognitionResult.getInfo().getId()));
      if (recognitionResult.getInfo().getId().equals(selectedSampleId)) {
        // collapsed +
        sb.append("&#8863;");
      } else {
        // expanded -
        sb.append("&#8862;");
      }
      sb.append(recognitionResult.getInfo().getName()).append("</a>");
      // show expanded id
      if (recognitionResult.getInfo().getId().equals(selectedSampleId)) {
        sb.append("<span>[id=").append(recognitionResult.getInfo().getId()).append("]</span>");
      }
      sb.append("</td>");
      sb.append(html("<td ROWSPAN=\"{0}\" class=\"{1}\">", rowsSize, selectionClass))
          .append(getI18n().getDecimalFormat().format(recognitionResult.getDistance()))
          .append("</td>");
      // how features are generated
      if (rowsSize == 1) {
        sb.append(html("<td  class=\"{0}\">", selectionClass)).append("</td>");
        sb.append(html("<td  class=\"{0}\">", selectionClass)).append("</td>");
        sb.append(html("<td  class=\"{0}\">", selectionClass)).append("</td>");
      }
      sb.append("</tr>");
      sb.append(subTable);
    }

    sb.append("</table>");
    return sb;
  }