コード例 #1
0
  /**
   * @param file
   * @return
   * @throws MalformedURLException
   */
  private WordSpotResult doWordspot(File aWavFile) throws MalformedURLException {
    WordSpotResult result = new WordSpotResult();
    URL aWavUrl = aWavFile.toURI().toURL();
    Collection<Marker> keywordMarkers =
        findKeywordSegment(SEARCH_KEY_WORD, aWavFile, KEY_WORD_SEQUENCE_ARR);
    SignalSegment keySegment = new SignalSegment(keywordMarkers.iterator().next());
    Assert.assertNotNull("keyword not found", keySegment);
    Long length = AudioManagerFactory.createAudioManager().findLengthInMils(aWavUrl);
    result.setAudioLength(length);
    result.getOriginalMarker().addAll(keywordMarkers);
    result.setFileName(aWavFile.getName());
    result.setExperimentStarted(System.currentTimeMillis());
    final Map<RecognitionResult, SignalSegment> segments = new LinkedHashMap<>();
    if (getSpottingService().getKeySegmentList() != null) {
      getSpottingService().getKeySegmentList().clear();
    }
    getSpottingService().addKeySegment(keySegment);

    final SignalSegment foundSegment = new SignalSegment();
    // when
    getSpottingService()
        .wordSpotting(
            aWavUrl,
            new SpottingListener() {
              @Override
              public String foundSegment(
                  String sourceId,
                  SignalSegment newSegment,
                  List<RecognitionResult> recognitionResults) {
                foundSegment.setMarker(newSegment.getMarker());
                newSegment.getMarker().setId(Long.valueOf(segments.size()));
                segments.put(recognitionResults.get(0), newSegment);
                return newSegment.getMarker().getLabel();
              }
            });

    result.setExperimentEnded(System.currentTimeMillis());
    result.setSegments(segments);

    return result;
  }
コード例 #2
0
  //	 @Ignore
  @Test
  @Category(SlowTests.class)
  public void bulkTest() throws MalformedURLException {
    wspotDao.setRecreate(true);
    wspotDao.init();
    LOG.debug("path: {}", getWavFile().getParentFile().getAbsoluteFile());
    File[] files = getWavFile().getParentFile().listFiles(new ExtNameFilter("wav"));
    LOG.debug("fileSize: {}", files.length);
    int foundSize = 0;
    int index = 0;
    for (File file : files) {
      // if(!file.getName().contains(
      // "RBg031126_13_31-30_1.wav"
      // )){
      // continue;
      // }
      Long start = System.currentTimeMillis();
      LOG.debug("start {}: {}", index, file);
      WordSpotResult result = doWordspot(file);
      wspotDao.save(result);
      foundSize += result.getSegments().size();
      // String resultsStr = extractResultStr(result.getSegments());
      LOG.debug("Marker => {}", result.getOriginalMarker());
      LOG.debug("KeySegmentList => {}", getSpottingService().getKeySegmentList().size());

      LOG.debug("{} => {}", getWavFile(), order.sortedCopy(result.getSegments().entrySet()));
      LOG.debug("{} => {}", getWavFile(), order.sortedCopy(result.getSegments().entrySet()));
      LOG.debug(
          "done {} in {} : {}\n", new Object[] {index, System.currentTimeMillis() - start, file});
      index++;
    }
    // log.error("files =>" + files.length);
    LOG.debug("foundSize =>{}", foundSize);
    // Assert.assertEquals(0, list.size());
    wspotDao.destroy();
    Assert.assertTrue("One element at least", foundSize > 0);
  }