Package letweb.semanticum.tsd

Examples of letweb.semanticum.tsd.Audio


      ArrayList<Long> beginTimeAnnot = new ArrayList<Long>();
      ArrayList<Long> endTimeAnnot = new ArrayList<Long>();
     
      StringBuffer document = new StringBuffer();
      Iterator audioIt = aJCas.getAnnotationIndex(Audio.type).iterator();
      Audio audio = (Audio) audioIt.next();
      Result result;
     
  //    getContext().getLogger().log("CF File is " + ConfigFile);
     
  //    if(audioIt.hasNext())
     
      ConcatAudioFileDataSource data = (ConcatAudioFileDataSource) cm.lookup("dataSource");
     
      for(String i: audio.getAudioPath().toArray())
        batch.add(new File(i));
     
      data.setBatchFiles(batch);
     
      recognizer.allocate();
     
      getContext().getLogger().log(Level.INFO, "Start recognition of " + audio.getAudioPath().toString(0));
      Long comp1 = System.currentTimeMillis();
     
      while((result = recognizer.recognize()) != null){
       
        ArrayList<TextAndTime> stt = TextAndTime.convert(result);
       
        if(stt != null)
          for(TextAndTime t: stt){
           
            String word = t.getWord();
           
            if(word.matches(TextAndTime.PATTERN_SIL))
              document.append(word);
            else{           
              beginAnnot.add(document.length());
              document.append(word);
              endAnnot.add(document.length());
             
              beginTimeAnnot.add(t.getIniTime());
              endTimeAnnot.add(t.getEndTime());
            }
            document.append(" ");
          }
       
      }
     
          Long comp2 = System.currentTimeMillis();
          getContext().getLogger().log(Level.INFO, "End recognition of " + audio.getAudioPath().toString(0));
          getContext().getLogger().log(Level.INFO, TextAndTime.getFormattedLong(comp2 - comp1)
              + " is total recognition time of this audio files " + audio.getAudioPath().toString(0));
          getContext().getLogger().log(Level.INFO, "Text " + document.toString());
         
          aJCas.setDocumentText(document.toString());
         
          Iterator<Long> itb = beginTimeAnnot.iterator(),
View Full Code Here


  }

  @Override
  public void process(JCas aJCas) throws AnalysisEngineProcessException {
   
    Audio audio = new Audio(aJCas);
   
    // Prelievo dell'array di link dal aJCas
    Iterator linkIT = aJCas.getAnnotationIndex(LinkType.type).iterator();
    LinkType link = (LinkType) linkIT.next();
    // LinkType uri=null;
    // StringArray tempPath=null;
    // int i=0;
    // FSIndex linkT = aJCas.getAnnotationIndex(LinkType.type);
   
    // Assegnazione dell'array di link alla variabile locale
    StringArray videoUri = link.getArrayVideoUri();
   
    //Log degli uri dei video
    int i;
    for(i = 0; i < videoUri.size(); i++)
      getContext().getLogger().log(Level.WARNING, videoUri.get(i));
   
    // Ciclo per il download dei singoli video
    // Thread download = null;
    // for(i=0; i<videoUri.size(); i++){
    // //Istanziazione dei thread
    // download = new Thread( new Runnable() {
    // public void run() {
    // try {
    // //Assegnazione all'iesimo elemento il path in cui è stato scaricato
    // il file audio
    // tempPath.set(i,
    // AudioVideoProcessing.audioDownloadEndExtraction(uri.getSourceType(),
    // videoUri.get(i)));
    // } catch (IOException e) {
    // getContext().getLogger().log(Level.WARNING, "Error: " + e.getMessage());
    // } catch (InterruptedException e) {
    // getContext().getLogger().log(Level.WARNING, "Error: " + e.getMessage());
    // }
    // }
    // });
    // //Partenza di ogni singola istanza
    // download.start();
    // }
    // //Attesa della fine dei thread
    // try {
    // download.join();
    // } catch (InterruptedException e) {
    // getContext().getLogger().log(Level.WARNING, "Error: " + e.getMessage());
    // }
   
    //Inizializzazione dell'insieme di threads
    ExecutorService es = Executors.newCachedThreadPool();
    ArrayList<Callable<String>> tasks = new ArrayList<Callable<String>>();
    List<Future<String>> results = new ArrayList<Future<String>>();
   
    StringArray path = new StringArray(aJCas, videoUri.size());
    // Assegnazione dell'array di competenza
    audio.setAudioPath(path);
   
    for (i = 0; i < videoUri.size(); i++)
      tasks.add(new ThreadCallDownload(videoUri.get(i),link.getSourceType(),tp));
   
    try {
      //Metodo che esegue tutti i threads e restituisce i risultati una volta
      //terminati tutti i trheads
      results = es.invokeAll(tasks);
      for(i = 0; i < results.size(); i++){
        audio.setAudioPath(i, results.get(i).get());
        getContext().getLogger().log(Level.WARNING, "Path: " + results.get(i).get());
      }
     
    } catch (InterruptedException e) {
      getContext().getLogger().log(Level.WARNING, "InterruptedError: " + e.getMessage());
    } catch (ExecutionException e) {
      getContext().getLogger().log(Level.WARNING, "IOError/InterruptedError: " + e.getMessage());
    }
   
    // Aggiornamento degli indici
    audio.addToIndexes();
  }
View Full Code Here

TOP

Related Classes of letweb.semanticum.tsd.Audio

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.