Ejemplo n.º 1
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);
       }
     }
   }
 }
  /**
   * @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;
  }