rm temp files
Esse commit está contido em:
@@ -1,64 +0,0 @@
|
||||
function RecordAudio(stream, cfg) {
|
||||
|
||||
var config = cfg || {};
|
||||
var bufferLen = config.bufferLen || 4096;
|
||||
var numChannels = config.numChannels || 2;
|
||||
this.context = stream.context;
|
||||
var recordBuffers = [];
|
||||
var recording = false;
|
||||
this.node = (this.context.createScriptProcessor ||
|
||||
this.context.createJavaScriptNode).call(this.context,
|
||||
bufferLen, numChannels, numChannels);
|
||||
|
||||
stream.connect(this.node);
|
||||
this.node.connect(this.context.destination);
|
||||
|
||||
this.node.onaudioprocess = function(e) {
|
||||
if (!recording) return;
|
||||
for (var i = 0; i < numChannels; i++) {
|
||||
if (!recordBuffers[i]) recordBuffers[i] = [];
|
||||
recordBuffers[i].push.apply(recordBuffers[i], e.inputBuffer.getChannelData(i));
|
||||
}
|
||||
};
|
||||
|
||||
this.getData = function() {
|
||||
var tmp = recordBuffers;
|
||||
recordBuffers = [];
|
||||
return tmp; // returns an array of array containing data from various channels
|
||||
};
|
||||
|
||||
/* this.start() = function() {
|
||||
recording = true;
|
||||
};
|
||||
|
||||
this.stop() = function() {
|
||||
recording = false;
|
||||
};*/
|
||||
}
|
||||
var recorder;
|
||||
function toggleRecording( e ) {
|
||||
if (e.classList.contains("recording")) {
|
||||
alert("instop");
|
||||
recorder.stop();
|
||||
var recordedData = recorder.getData();
|
||||
e.classList.remove("recording");
|
||||
|
||||
// stop recording
|
||||
//audioRecorder.stop();
|
||||
//a/udioRecorder.getBuffers( gotBuffers );
|
||||
//saveAudio();
|
||||
|
||||
} else {
|
||||
recorder = new RecordAudio(userMedia);
|
||||
alert("started");
|
||||
recorder.start();
|
||||
e.classList.add("recording");
|
||||
/*window.addEventListener('load', initAudio );
|
||||
|
||||
alert("I am here");
|
||||
if (!audioRecorder)
|
||||
return;
|
||||
audioRecorder.clear();
|
||||
audioRecorder.record();*/
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public abstract class Classifier {
|
||||
public String arg="";
|
||||
public logger logger_instance;
|
||||
String configFile = "";
|
||||
String onyxentity = "";
|
||||
String intype="";
|
||||
public abstract boolean configure(JSONObject json);
|
||||
public abstract JSONObject classify(String inputString);
|
||||
public String getInType(){
|
||||
return intype;
|
||||
}
|
||||
}
|
||||
/* SAMPLE INPUT JSON CONF
|
||||
{
|
||||
"configs":[
|
||||
{
|
||||
"classifier":"opensmilesvm",
|
||||
"config":"IS09_emotion_A.conf",
|
||||
"onyxentity":"emovoc:arousal"
|
||||
},{
|
||||
"classifier":"opensmilesvm",
|
||||
"config":"IS09_emotion_V.conf",
|
||||
"onyxentity":"emovoc:pleasure"
|
||||
}
|
||||
]}
|
||||
|
||||
SAMPLE OUTPUT JSON RESULTS
|
||||
{
|
||||
"emovoc:pleasure":" 1.00",
|
||||
"confidence":0.2
|
||||
}
|
||||
*/
|
||||
@@ -1,757 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@Path("")
|
||||
public class EmoRecService extends ResourceConfig {
|
||||
logger logger_instance = new logger((new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")).format(Calendar.getInstance().getTime()).replace("/", "_").replace(":", "_").replace(" ", "_"));
|
||||
|
||||
@POST
|
||||
@Path("/upload")
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response uploadFile(
|
||||
@FormDataParam("file") InputStream uploadedInputStream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileDetail)// ,
|
||||
{
|
||||
String uploadedFileLocation = paths.FileDirectory
|
||||
+ fileDetail.getFileName();
|
||||
writeToFile(uploadedInputStream, uploadedFileLocation);
|
||||
String output = "File uploaded to : " + uploadedFileLocation;
|
||||
return Response.status(200).entity(output).build();
|
||||
}
|
||||
|
||||
@Path("/")
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response nothing(){
|
||||
return(Response.status(200).entity(genderateHelp()).build());
|
||||
}
|
||||
|
||||
boolean DOCKER = false;
|
||||
@Path("/getdims")
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
public Response getdims(@QueryParam("dims") String dim,
|
||||
@QueryParam("url") String url,
|
||||
@DefaultValue("") @QueryParam("json") String jsonfile,
|
||||
@DefaultValue("-1,-1") @QueryParam("timing") String time,
|
||||
@DefaultValue("false") @QueryParam("mobile") String mobilemode,
|
||||
@DefaultValue("") @QueryParam("texts") String texts)
|
||||
throws JSONException {
|
||||
logger_instance.write(1,"Inside getdims");
|
||||
if(dim==null){
|
||||
return(Response.status(200).entity(genderateHelp()).build());
|
||||
}
|
||||
dim = dim.toLowerCase();
|
||||
File file = wget(url);// wget command to retrieve the video content
|
||||
logger_instance.write(1,"URL downloaded to "+file.getAbsolutePath());
|
||||
String extension = "";
|
||||
int i = file.getName().lastIndexOf('.');
|
||||
String[] splitedTexts =null;
|
||||
if(texts.length()>0){
|
||||
splitedTexts = texts.split(";");
|
||||
}
|
||||
if (i >= 0) {
|
||||
extension = file.getName().substring(i + 1);
|
||||
}
|
||||
File wavFile;
|
||||
wavFile = convertToWave(file);
|
||||
logger_instance.write(1,"File converted to wav: "+wavFile.getAbsolutePath());
|
||||
String[] times = time.split(";");
|
||||
String asrname = "____________________";
|
||||
String text="";
|
||||
boolean doingASR = false;
|
||||
boolean asr_error=false;
|
||||
String temp_text = "";
|
||||
if (times[0].toLowerCase().compareTo("asr")==0 || times[0].toLowerCase().compareTo("asr_word")==0){
|
||||
if(DOCKER){
|
||||
return Response.status(200).entity("ASR and Sentiment are not available for the Docker version").build();
|
||||
}
|
||||
logger_instance.write(1, " Perform ASR");
|
||||
doingASR = true;
|
||||
try {
|
||||
double audioDuration = getAudioDuration(wavFile.getAbsolutePath());
|
||||
|
||||
String tim = "";
|
||||
double asraudioleng = 120;//audioDuration;
|
||||
for(double startTime = 0;startTime < audioDuration;startTime+=asraudioleng){
|
||||
double ending = Math.min(startTime+asraudioleng,audioDuration);
|
||||
double duration = ending - startTime;
|
||||
logger_instance.write(1, " Perform ASR, time:"+ startTime + " - " + ending);
|
||||
if(duration < .5)
|
||||
break;
|
||||
File cuttedaudioasr = cutAudio(wavFile, String.valueOf(startTime), String.valueOf(duration), 100000+startTime);
|
||||
JSONArray jasr = performASR2(cuttedaudioasr.getAbsolutePath());
|
||||
|
||||
if(jasr.length()==0){
|
||||
if(startTime==0 && startTime+asraudioleng>=audioDuration){//only one slice
|
||||
temp_text="NO TEXT IS DETECTED!";
|
||||
tim = "-1,-1";
|
||||
break;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else{
|
||||
ArrayList<String> temp_texta= new ArrayList<String>();
|
||||
ArrayList<Integer> start_time= new ArrayList<Integer>();
|
||||
ArrayList<Integer> end_time=new ArrayList<Integer>();
|
||||
for(int iw = 0;iw<jasr.length();iw++){
|
||||
if(jasr.getJSONObject(iw).getString("word").compareTo("<s>")!=0 && jasr.getJSONObject(iw).getString("word").compareTo("</s>")!=0){
|
||||
temp_texta.add(jasr.getJSONObject(iw).getString("word"));
|
||||
start_time.add(jasr.getJSONObject(iw).getInt("start"));
|
||||
end_time.add(jasr.getJSONObject(iw).getInt("end"));
|
||||
}
|
||||
}
|
||||
|
||||
if(times[0].toLowerCase().compareTo("asr_word")==0){
|
||||
for(int iw = 0;iw<temp_texta.size();iw++){
|
||||
if(temp_texta.get(iw).compareTo(".")==0)continue;
|
||||
double vst=start_time.get(iw).doubleValue()/10000000+startTime;
|
||||
double ven=end_time.get(iw).doubleValue()/10000000+startTime;
|
||||
tim+=((Double)vst).toString()+","+((Double)ven).toString()+";";
|
||||
temp_text+=temp_texta.get(iw)+";";
|
||||
}
|
||||
}
|
||||
else{
|
||||
boolean start = true;
|
||||
boolean prevDot = false;
|
||||
for(int iw = 0;iw<temp_texta.size();iw++){
|
||||
if(temp_texta.get(iw).compareTo(".")==0){
|
||||
if(prevDot)continue;//double dots
|
||||
double v=start_time.get(iw).doubleValue()/10000000+startTime;
|
||||
tim+=((Double)v).toString()+";";
|
||||
temp_text+=";";
|
||||
start=true;
|
||||
prevDot = true;
|
||||
continue;
|
||||
}
|
||||
prevDot = false;
|
||||
if(start==true){
|
||||
double v = start_time.get(iw).doubleValue()/10000000+startTime;
|
||||
tim+=((Double)v).toString()+",";
|
||||
start=false;
|
||||
}
|
||||
temp_text+= temp_texta.get(iw)+" ";
|
||||
if(iw==temp_texta.size()-1 && !temp_text.endsWith(".")){
|
||||
temp_text+=";";
|
||||
double v=end_time.get(iw).doubleValue()/10000000+startTime;
|
||||
tim+=((Double)v).toString()+";";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(tim.endsWith(";"))
|
||||
tim = tim.substring(0, tim.length()-1);
|
||||
if(temp_text.endsWith(";"))
|
||||
temp_text = temp_text.substring(0, temp_text.length()-1);
|
||||
splitedTexts = temp_text.split(";");
|
||||
times = tim.split(";");
|
||||
} catch (IOException e) {
|
||||
splitedTexts="IOException during ASR".split(",");
|
||||
logger_instance.write(1, "IOException during ASR"+e.getMessage());
|
||||
asr_error = true;
|
||||
dim=dim.replace("sentiment,", "").replace(",sentiment","").replace("sentiment", "");
|
||||
times = "-1,-1".split(";");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return Response.status(200).entity("InterruptedException during ASR").build();
|
||||
}
|
||||
}
|
||||
if(mobilemode.compareTo("true")==0){
|
||||
times=new String[]{"-1,-1"};
|
||||
if(doingASR)
|
||||
splitedTexts=new String[]{temp_text.replace("%20", " ").replace(";",". ")};
|
||||
}
|
||||
String finalJSONString = "[";
|
||||
String[] dims = dim.split(",");
|
||||
ArrayList<Classifier> clf = new ArrayList<Classifier>();
|
||||
logger_instance.write(1,"Loading config.json from :" + paths.getVar("REST_OPENSMILE")+ "configs.json");
|
||||
JSONObject jo = loadJsonObject(paths.getVar("REST_OPENSMILE")+ "configs.json");
|
||||
logger_instance.write(1,"JSON is loaded: "+ jo.toString());
|
||||
JSONArray ja = jo.getJSONArray("configs");
|
||||
logger_instance.write(1, "dims:" + dims.length);
|
||||
for (int d = 0; d < dims.length; d++) {
|
||||
if((dims[d].toLowerCase().compareTo("sentiment")==0 || dims[d].toLowerCase().compareTo("asr")==0) && DOCKER){
|
||||
return Response.status(200).entity("ASR and Sentiment are not available for the Docker version").build();
|
||||
}
|
||||
|
||||
boolean added = false;
|
||||
for(int j = 0;j<ja.length();j++){
|
||||
if(((JSONObject)ja.get(j)).getString("id").compareTo(dims[d].toLowerCase())==0){
|
||||
Classifier c = ClassifierFactory.createClassifier((JSONObject) ja
|
||||
.get(j),logger_instance);
|
||||
c.configure((JSONObject) ja.get(j));
|
||||
clf.add(c);
|
||||
added = true;break;
|
||||
}
|
||||
}
|
||||
if(!added)
|
||||
return Response.status(200).entity(dims[d] +" is not supported!").build();/**/
|
||||
}
|
||||
logger_instance.write(1,""+ clf.size()+ " classifiers are added");
|
||||
ExecutorService exec = Executors.newFixedThreadPool(times.length);
|
||||
logger_instance.write(1, "times:" + times.length);
|
||||
for (i = 0; i < times.length; i++) {
|
||||
String[] timesplit = times[i].split(",");
|
||||
String duration = "-1";
|
||||
if(timesplit[1].trim().compareTo("-1")==0)
|
||||
duration = "-1";
|
||||
else{
|
||||
Double d = Double.valueOf(timesplit[1].trim()) - Double.valueOf(timesplit[0].trim());
|
||||
duration = d.toString();
|
||||
}
|
||||
final File cuttedAudio = cutAudio(wavFile, timesplit[0],
|
||||
duration, i);
|
||||
final JSONArray jaresult = new JSONArray();
|
||||
final CountDownLatch latch = new CountDownLatch(clf.size());
|
||||
final String[] textttt = splitedTexts;
|
||||
final boolean da = doingASR;
|
||||
final int iiii = i;
|
||||
for (final Classifier cl : clf) {
|
||||
exec.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
logger_instance.write(1, " run ");
|
||||
try {
|
||||
if(cl.getInType().compareTo("audio")==0)
|
||||
jaresult.put(cl.classify(cuttedAudio.getAbsolutePath()));
|
||||
else if(cl.getInType().compareTo("text")==0 && da==true && textttt!=null)
|
||||
jaresult.put(cl.classify(textttt[iiii].replace(" " , "_")));
|
||||
} catch (Exception e) {
|
||||
logger_instance.write(1, " classification exception: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
logger_instance.write(1, " finished ");
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
logger_instance.write(1, " latch wait ");
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
logger_instance.write(1, " latch InterruptedException: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
// create json
|
||||
JSONObject jsonobj = write2JSON(url, i, timesplit[0], timesplit[1],
|
||||
jaresult);
|
||||
if(doingASR){
|
||||
JSONObject j = new JSONObject();
|
||||
j.put("ASR", "Powered by Phonexia");
|
||||
int n = jsonobj.getJSONArray("analysis").length();
|
||||
jsonobj.getJSONArray("analysis").put(n,j );
|
||||
}
|
||||
if(splitedTexts!=null && splitedTexts.length>0 && i<splitedTexts.length){
|
||||
jsonobj.put("Text",splitedTexts[i]);
|
||||
}
|
||||
if (jsonfile.compareTo("") != 0) {// add to already existed json
|
||||
JSONObject jsonobjexist = loadJsonObject(jsonfile);
|
||||
jsonobj = mergeJSONs(jsonobjexist, jsonobj);
|
||||
}
|
||||
finalJSONString += jsonobj.toString(4) + "\n";
|
||||
if(i!=times.length-1)
|
||||
finalJSONString += ",";
|
||||
System.out.println(""+i +"/"+times.length + " processed.");
|
||||
}
|
||||
finalJSONString+="]";
|
||||
if(mobilemode.compareTo("true")==0){
|
||||
finalJSONString=finalJSONString.substring(1, finalJSONString.length()-2);
|
||||
}
|
||||
//deleting
|
||||
String[] ss =asrname.split("/");
|
||||
final String ffnn = ss[ss.length-1];
|
||||
ss = file.toString().split("/");
|
||||
final String wwfn = ss[ss.length-1];
|
||||
final File folder = new File(paths.FileDirectory);
|
||||
final File[] files = folder.listFiles( new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept( final File dir,
|
||||
final String name ) {
|
||||
boolean b = false;
|
||||
b = b | name.startsWith(ffnn+"." );
|
||||
b = b | name.startsWith(wwfn+"." );
|
||||
return b;
|
||||
}
|
||||
} );
|
||||
for ( final File ffile : files ) {
|
||||
if ( !ffile.delete() ) {
|
||||
System.err.println( "Can't remove " + ffile.getAbsolutePath() );
|
||||
}
|
||||
}
|
||||
|
||||
return Response.status(200).entity(finalJSONString).build();
|
||||
}
|
||||
|
||||
@Path("/getByConfig")
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
public Response getByConfig(@QueryParam("url") String url,
|
||||
@DefaultValue("") @QueryParam("json") String jsonfile,
|
||||
@DefaultValue("") @QueryParam("conf") String conffile,
|
||||
@DefaultValue("-1,-1") @QueryParam("timing") String time,
|
||||
@DefaultValue("") @QueryParam("texts") String texts)
|
||||
throws JSONException {
|
||||
File file = wget(url);// wget command to retrieve the video content
|
||||
JSONObject jo = loadJsonObject(conffile);
|
||||
JSONArray ja = jo.getJSONArray("configs");
|
||||
ArrayList<Classifier> clf = new ArrayList<Classifier>();
|
||||
for (int i = 0; i < ja.length(); i++) {
|
||||
jo = ja.getJSONObject(i);
|
||||
Classifier c = ClassifierFactory.createClassifier(jo
|
||||
.getString("classifier"),logger_instance);
|
||||
c.configure(jo);
|
||||
clf.add(c);
|
||||
}
|
||||
String[] splitedTexts =null;
|
||||
if(texts.length()>0){
|
||||
splitedTexts = texts.split(";");
|
||||
}
|
||||
String extension = "";
|
||||
int i = file.getName().lastIndexOf('.');
|
||||
if (i >= 0) {
|
||||
extension = file.getName().substring(i + 1);
|
||||
}
|
||||
File wavFile;
|
||||
if (extension.toLowerCase().compareTo("wav") == 0) {
|
||||
wavFile = file;
|
||||
} else {
|
||||
wavFile = convertToWave(file);
|
||||
}
|
||||
String[] times = time.split(";");
|
||||
String finalJSONString = "";
|
||||
ExecutorService exec = Executors.newFixedThreadPool(times.length);
|
||||
for (i = 0; i < times.length; i++) {
|
||||
String[] timesplit = times[i].split(",");
|
||||
final File cuttedAudio = cutAudio(wavFile, timesplit[0],
|
||||
timesplit[1], i);
|
||||
final JSONArray jaresult = new JSONArray();
|
||||
final CountDownLatch latch = new CountDownLatch(clf.size());
|
||||
try {
|
||||
for (final Classifier cl : clf) {
|
||||
exec.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
jaresult.put(cl.classify(cuttedAudio.getAbsolutePath()));
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
latch.await();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
JSONObject jsonobj = write2JSON(url, i, timesplit[0], timesplit[1],
|
||||
jaresult);
|
||||
if(i<splitedTexts.length){
|
||||
jsonobj.put("Text",splitedTexts[i]);
|
||||
}
|
||||
if (jsonfile.compareTo("") != 0) {// add to already existed json
|
||||
JSONObject jsonobjexist = loadJsonObject(jsonfile);
|
||||
jsonobj = mergeJSONs(jsonobjexist, jsonobj);
|
||||
}
|
||||
finalJSONString += jsonobj.toString() + "\n";
|
||||
}
|
||||
exec.shutdown();
|
||||
return Response.status(200).entity(finalJSONString).build();
|
||||
}
|
||||
|
||||
@Path("/deleteFile")
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response deleteFile(@QueryParam("url") String url)
|
||||
throws JSONException {
|
||||
String[] urls = url.split("/");
|
||||
final String output = urls[urls.length - 1];
|
||||
File direct = new File(paths.FileDirectory);
|
||||
String[] files = direct.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.startsWith(output))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (String s : files) {
|
||||
File f = new File(paths.FileDirectory + s);
|
||||
f.delete();
|
||||
}
|
||||
return Response.status(200).entity(files.length + " file(s) deleted!")
|
||||
.build();
|
||||
}
|
||||
|
||||
private JSONObject mergeJSONs(JSONObject jsonobjexist, JSONObject jsonobj) {
|
||||
JSONObject jc = jsonobj.getJSONArray("@context").getJSONObject(0);
|
||||
jsonobjexist.accumulate("@context", jc);
|
||||
JSONObject janalysis = jsonobj.getJSONArray("analysis")
|
||||
.getJSONObject(0);
|
||||
JSONArray ja = jsonobjexist.getJSONArray("analysis");
|
||||
ja.put(janalysis);
|
||||
|
||||
String emotionid = jsonobjexist.getJSONArray("entries")
|
||||
.getJSONObject(0).getString("@id");
|
||||
JSONObject jemotions = jsonobj.getJSONArray("entries").getJSONObject(0)
|
||||
.getJSONArray("emotions").getJSONObject(0);
|
||||
String idnew = jemotions.getString("@id");
|
||||
String[] subid = idnew.split("#");
|
||||
jemotions.put("@id", emotionid + "#" + subid[1]);
|
||||
JSONArray jem2 = jsonobjexist.getJSONArray("entries").getJSONObject(0)
|
||||
.getJSONArray("emotions");
|
||||
jem2.put(jemotions);
|
||||
return jsonobjexist;
|
||||
}
|
||||
private JSONArray performASR2(String wavefilename) throws IOException,InterruptedException{
|
||||
String r = String.valueOf(Math.random()).replace(".", "_");
|
||||
Process p = Runtime.getRuntime().exec(paths.SMILExtractDir+"asr/asr_upload.sh "+wavefilename);
|
||||
p.waitFor();
|
||||
String line="";
|
||||
String fullLine1="";
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine1=fullLine1+line;
|
||||
JSONObject j = new JSONObject(fullLine1);
|
||||
if(!(j.has("result") && j.getJSONObject("result").has("name")))
|
||||
return null;//"ASR unsucessfull";
|
||||
//running asr
|
||||
p = Runtime.getRuntime().exec(paths.SMILExtractDir+"asr/asr_run.sh "+wavefilename);
|
||||
p.waitFor();
|
||||
String fullLine3="";
|
||||
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine3=fullLine3+line;
|
||||
j = new JSONObject(fullLine3);
|
||||
String id = j.getJSONObject("result").getJSONObject("info").getString("id");
|
||||
|
||||
while(true){
|
||||
String fullLine4="";
|
||||
Thread.sleep(2000);
|
||||
p = Runtime.getRuntime().exec(paths.SMILExtractDir+"asr/checkpending.sh "+id);
|
||||
p.waitFor();
|
||||
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine4=fullLine4+line;
|
||||
j = new JSONObject(fullLine4);
|
||||
if(!j.getJSONObject("result").has("info") || j.getJSONObject("result").getJSONObject("info").getString("state").compareTo("finished")==0)
|
||||
break;
|
||||
}
|
||||
p = Runtime.getRuntime().exec(paths.SMILExtractDir+"asr/asr_run.sh "+wavefilename);
|
||||
p.waitFor();
|
||||
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String fullLine5="";
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine5=fullLine5+line;
|
||||
j = new JSONObject(fullLine5);
|
||||
JSONArray jo = j.getJSONObject("result").getJSONObject("one_best_result").getJSONArray("segmentation");
|
||||
|
||||
return jo;
|
||||
|
||||
}
|
||||
private String performASR(String wavefilename) throws IOException,InterruptedException{
|
||||
String r = String.valueOf(Math.random());
|
||||
String fname = paths.FileDirectory + "asrout"+r+".tmp";
|
||||
Process p = Runtime.getRuntime().exec(
|
||||
"sh " + paths.SMILExtractDir +"asr_prep.sh "+ wavefilename);
|
||||
p.waitFor();
|
||||
|
||||
FileReader f = new FileReader(wavefilename+".asrupload.txt");
|
||||
BufferedReader br = new BufferedReader(f);
|
||||
String aline;
|
||||
boolean passed = false;
|
||||
while((aline = br.readLine())!=null){
|
||||
if(aline.contains("info format")){
|
||||
passed = true;break;
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
if (passed == false){
|
||||
return "Posting file to ASR server failed";
|
||||
}
|
||||
|
||||
f = new FileReader(wavefilename+".asrloc.txt");
|
||||
String locationOnServer="";
|
||||
|
||||
br = new BufferedReader(f);
|
||||
while((aline = br.readLine())!=null){
|
||||
if(aline.contains("Location")){
|
||||
locationOnServer = aline.substring(10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
|
||||
boolean asr = false;
|
||||
do{
|
||||
Thread.sleep(2000);
|
||||
p = Runtime.getRuntime().exec(
|
||||
"sh " + paths.SMILExtractDir +"asr_get_res.sh "+ locationOnServer +" "+fname+".trans.txt");
|
||||
p.waitFor();
|
||||
f = new FileReader(fname+".trans.txt");
|
||||
br = new BufferedReader(f);
|
||||
while((aline = br.readLine())!=null){
|
||||
if(aline.contains("result name=\"lvcsr\"")){
|
||||
asr = true;br.close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}while(asr==false);
|
||||
|
||||
|
||||
p = Runtime.getRuntime().exec(
|
||||
"bash " + paths.SMILExtractDir + "asr_processor.sh " + fname + ".trans.txt " + wavefilename +" "+fname+".json");
|
||||
p.waitFor();
|
||||
|
||||
return fname;
|
||||
|
||||
}
|
||||
|
||||
public static String readFile(String filename) throws IOException {
|
||||
FileReader f = new FileReader(filename);
|
||||
BufferedReader br = new BufferedReader(f);
|
||||
String s = "";
|
||||
String aline;
|
||||
while((aline = br.readLine())!=null){
|
||||
s = s + aline;
|
||||
}
|
||||
br.close();
|
||||
return s;
|
||||
}
|
||||
|
||||
static public JSONObject loadJsonObject(String jsonfilename) {
|
||||
String line = "";
|
||||
String jsonTxt = "";
|
||||
BufferedReader is = null;
|
||||
try {
|
||||
is = new BufferedReader(new InputStreamReader(new FileInputStream(
|
||||
jsonfilename)));
|
||||
while ((line = is.readLine()) != null) {
|
||||
jsonTxt += line;
|
||||
}
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
JSONObject jsonobjexist = new JSONObject(jsonTxt);
|
||||
return jsonobjexist;
|
||||
}
|
||||
|
||||
private JSONObject write2JSON(String url, Integer index, String time,
|
||||
String duration, JSONArray jaresult) {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray jarray = new JSONArray();
|
||||
JSONObject emovoc = new JSONObject();
|
||||
emovoc.put("emovoc",
|
||||
"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/emotionml/ns");
|
||||
jarray.put(emovoc);
|
||||
json.put("@context", jarray);
|
||||
|
||||
JSONArray janalysisarray = new JSONArray();
|
||||
JSONObject janalysis = new JSONObject();
|
||||
janalysis.put("@id", "me:SpeechAnalysis");
|
||||
janalysis.put("@type", "onyx:EmotionAnalysis");
|
||||
janalysis.put("onyx:usesEmotionModel", "emovoc:pad-dimensions");
|
||||
janalysisarray.put(janalysis);
|
||||
json.put("analysis", janalysisarray);
|
||||
|
||||
JSONArray jemotionsarray = new JSONArray();
|
||||
JSONObject jemotion = new JSONObject();
|
||||
jemotion.put("@id", "Entry" + index.toString() + "#time=" + time + ","
|
||||
+ duration);
|
||||
jemotion.put("prov:wasGeneratedBy", "me:SpeechAnalysis");
|
||||
jemotion.put("onyx:hasEmotion", jaresult);
|
||||
jemotionsarray.put(jemotion);
|
||||
|
||||
JSONObject jentry = new JSONObject();
|
||||
jentry.put("emotions", jemotionsarray);
|
||||
|
||||
JSONArray jentriesarray = new JSONArray();
|
||||
jentriesarray.put(jentry);
|
||||
|
||||
json.put("entries", jentriesarray);
|
||||
return json;
|
||||
}
|
||||
|
||||
private File cutAudio(File file, String startTime, String duration,
|
||||
double d) {
|
||||
File F = new File(file + "_p" + ((Double)d).toString() + ".wav");
|
||||
try {
|
||||
if (F.exists())
|
||||
F.delete();
|
||||
String durationStr = "";
|
||||
if(startTime.startsWith(".")){
|
||||
startTime = startTime+" ";
|
||||
startTime = "0"+String.copyValueOf(startTime.toCharArray(), 0, startTime.length()-1);
|
||||
}
|
||||
if (startTime.compareTo("-1") == 0)
|
||||
startTime = "0";
|
||||
if (duration.compareTo("-1") != 0)
|
||||
durationStr = " -t " + duration;
|
||||
if(durationStr.startsWith(".")){
|
||||
durationStr = durationStr+" ";
|
||||
durationStr = "0"+String.copyValueOf(durationStr.toCharArray(), 0, durationStr.length()-1);
|
||||
}
|
||||
Process p = Runtime.getRuntime().exec(
|
||||
"avconv" + " -i " + file + " -acodec copy " + " -ac 1 -ss "
|
||||
+ startTime + // start
|
||||
durationStr + // duration
|
||||
" " + F.toString());
|
||||
p.waitFor();
|
||||
p = Runtime.getRuntime().exec(
|
||||
"qwavheaderdump -q -F " + F.toString());// Fixing header
|
||||
p.waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return F;
|
||||
}
|
||||
|
||||
// convert av to .wav
|
||||
private File convertToWave(File file) {
|
||||
File F = new File(file.toString() + ".wav");
|
||||
try {
|
||||
if(F.exists())
|
||||
F.delete();
|
||||
//if (!F.exists())
|
||||
|
||||
Process p = Runtime.getRuntime().exec(
|
||||
"avconv -loglevel quiet -i " + file + " -ac 1 -vn -f wav "
|
||||
+ F.toString());
|
||||
p.waitFor();
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return F;
|
||||
}
|
||||
|
||||
// download the resource
|
||||
private File wget(String url) {
|
||||
String[] urls = url.split("/");
|
||||
String output = paths.FileDirectory + urls[urls.length - 1];
|
||||
File F = new File(output);
|
||||
try {
|
||||
if (!F.exists()) {
|
||||
Process p = Runtime.getRuntime().exec(
|
||||
"wget -q -O " + output + " " + url);
|
||||
p.waitFor();
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
F = null;
|
||||
logger_instance.write(
|
||||
1,
|
||||
"wget exception: wget -q -O " + output + " " + url + "\n"
|
||||
+ e.getMessage());
|
||||
logger_instance.close();
|
||||
}
|
||||
return F;
|
||||
}
|
||||
private double getAudioDuration(String filename){
|
||||
File file = new File(filename);
|
||||
AudioInputStream audioInputStream;
|
||||
float durationInSeconds = 0;
|
||||
try {
|
||||
audioInputStream = AudioSystem.getAudioInputStream(file);
|
||||
AudioFormat format = audioInputStream.getFormat();
|
||||
long audioFileLength = file.length();
|
||||
int frameSize = format.getFrameSize();
|
||||
float frameRate = format.getFrameRate();
|
||||
durationInSeconds = (audioFileLength / (frameSize * frameRate));
|
||||
} catch (UnsupportedAudioFileException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return durationInSeconds;
|
||||
}
|
||||
|
||||
private String genderateHelp(){
|
||||
return "You have to set these parameters:\n" +
|
||||
"getdims: desired dimentions separated by comma (arousal,valence,age,gender,big5O,big5C,big5E,big5A,big5N,sentiment)\n"+
|
||||
" note that, to have sentiment, you should only have 'asr' (automatic speech recognition) in the 'timing' parameter.'\n"+
|
||||
"url:the url of the video/audio or the name of the uploaded file\n"+
|
||||
"timing: start and end of the segments (in seconds). start1,end1;start2,end2, OR asr\n"+
|
||||
" when you choose 'asr', the audio file is segmented for each spoken sentence (useful for sentiment recognition) \n"+
|
||||
"Example:\n"+
|
||||
"http://mixedemotions.fim.uni-passau.de:8080/er/aer/getdims?dims=arousal,valence,gender,age,big5o,big5c,big5e,big5a,big5n&url=http://tv-download.dw.com/dwtv_video/flv/wikoe/wikoe20151114_wiruebli_sd_avc.mp4&timing=9,15;147,152"+
|
||||
"\n\n"+
|
||||
"To upload an audio/video file use curl:\n"+
|
||||
"Windows: curl -v -H \"Content-Type:multipart/form-data\" --user meuser -i -X POST -F \"file=@D:\\path\\to\\sample.wav\" http://mixedemotions.fim.uni-passau.de:8080/er/aer/upload\n"+
|
||||
"Linux: curl -v -H \"Content-Type:multipart/form-data\" --user meuser -i -X POST -F 'file=@./sample.wav' http://mixedemotions.fim.uni-passau.de:8080/er/aer/upload\n"+
|
||||
"\n"+
|
||||
"GUI interface: http://mixedemotions.fim.uni-passau.de:8080/er/FileUpload.html"
|
||||
;
|
||||
}
|
||||
|
||||
// save uploaded file to new location
|
||||
private void writeToFile(InputStream uploadedInputStream,
|
||||
String uploadedFileLocation) {
|
||||
|
||||
try {
|
||||
OutputStream out = new FileOutputStream(new File(
|
||||
uploadedFileLocation));
|
||||
int read = 0;
|
||||
byte[] bytes = new byte[1024];
|
||||
|
||||
out = new FileOutputStream(new File(uploadedFileLocation));
|
||||
while ((read = uploadedInputStream.read(bytes)) != -1) {
|
||||
out.write(bytes, 0, read);
|
||||
}
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
//package com.opensmile.first;
|
||||
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
@ApplicationPath("/")
|
||||
public class MyApplication extends ResourceConfig {
|
||||
public MyApplication(){
|
||||
super(EmoRecService.class,MultiPartFeature.class);
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class bashClassifier extends Classifier {
|
||||
String run_command = "";
|
||||
@Override
|
||||
public boolean configure(JSONObject json) {
|
||||
run_command = json.getString("run_command");
|
||||
onyxentity = json.getString("onyxentity");
|
||||
intype = json.getString("intype");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject classify(String audioFile) {
|
||||
String line="";
|
||||
String fullLine="";
|
||||
/*if(model.compareTo("Arousal")==0)
|
||||
prepareConfigFile("svmarousal");
|
||||
if(model.compareTo("Valence")==0)
|
||||
prepareConfigFile("svmvalence");
|
||||
*/
|
||||
int idx = run_command.lastIndexOf("/");
|
||||
String full_path = paths.SMILExtractDir+run_command.substring(0,idx);
|
||||
String str = "bash "+paths.SMILExtractDir+run_command+" "+audioFile;
|
||||
try {
|
||||
logger_instance.write(1,"full_path="+full_path);
|
||||
logger_instance.write(1,"bash command: " + str);
|
||||
for(int trial=0;trial<3;trial++){
|
||||
fullLine="";
|
||||
Process p = Runtime.getRuntime().exec(str,null,new File(full_path));
|
||||
p.waitFor();
|
||||
logger_instance.write(1,"bash command performed");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine=fullLine+line;
|
||||
in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine=fullLine+line;
|
||||
if(fullLine.length()>0)
|
||||
break;
|
||||
}
|
||||
logger_instance.write(1,"bash output:"+ fullLine);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject jo = null;
|
||||
try{
|
||||
jo = new JSONObject(fullLine.substring(fullLine.indexOf("{")));
|
||||
}catch (JSONException e){
|
||||
System.out.println(fullLine);
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(StringIndexOutOfBoundsException e){
|
||||
System.out.println(fullLine);
|
||||
e.printStackTrace();
|
||||
}
|
||||
//int idx1 = fullLine.indexOf("~~>");
|
||||
//int idx2 = fullLine.indexOf("<~~");
|
||||
//out = fullLine.substring(idx1+3, idx2-1);
|
||||
|
||||
JSONObject jop = new JSONObject();
|
||||
switch((String)jo.get("TYPE")){
|
||||
case "regression":
|
||||
double out = jo.getDouble("VALUE");
|
||||
double conf = (double)(((JSONObject)jo.getJSONArray("PROB").get(0)).getDouble("CONFIDENCE"));
|
||||
jop.put(onyxentity, out);
|
||||
jop.put("confidence", conf);
|
||||
break;
|
||||
case "classification":
|
||||
jop.put(onyxentity, jo.getJSONArray("PROB"));
|
||||
break;
|
||||
}
|
||||
return jop;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
/**
|
||||
* @author Crunchify.com
|
||||
*/
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/ctofservice")
|
||||
public class ctofservice {
|
||||
@GET
|
||||
@Produces("application/xml")
|
||||
public String convertCtoF() {
|
||||
|
||||
Double fahrenheit;
|
||||
Double celsius = 36.8;
|
||||
fahrenheit = ((celsius * 9) / 5) + 32;
|
||||
|
||||
String result = "@Produces(\"application/xml\") Output: \n\nC to F Converter Output: \n\n" + fahrenheit;
|
||||
return "<ctofservice>" + "<celsius>" + celsius + "</celsius>" + "<ctofoutput>" + result + "</ctofoutput>" + "</ctofservice>";
|
||||
}
|
||||
|
||||
@Path("{c}")
|
||||
@GET
|
||||
@Produces("application/xml")
|
||||
public String convertCtoFfromInput(@PathParam("c") Double c) {
|
||||
Double fahrenheit;
|
||||
Double celsius = c;
|
||||
fahrenheit = ((celsius * 9) / 5) + 32;
|
||||
|
||||
String result = "@Produces(\"application/xml\") Output: \n\nC to F Converter Output: \n\n" + fahrenheit;
|
||||
return "<ctofservice>" + "<celsius>" + celsius + "</celsius>" + "<ctofoutput>" + result + "</ctofoutput>" + "</ctofservice>";
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class logger {
|
||||
//private static volatile logger logger_instance;
|
||||
static PrintWriter F;
|
||||
int debug_priority = 1;
|
||||
static String filename;
|
||||
logger() {
|
||||
try {
|
||||
F = new PrintWriter(paths.logFolder + filename + ".txt");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
logger(String filename){
|
||||
try {
|
||||
logger.filename=filename;
|
||||
F = new PrintWriter(paths.logFolder + filename + ".txt");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*static logger getinstance(String filename){
|
||||
logger
|
||||
|
||||
|
||||
return logger_instance;
|
||||
}
|
||||
|
||||
/* static logger getinstance() {
|
||||
if (logger_instance == null) {
|
||||
synchronized (logger.class) {
|
||||
if (logger_instance == null)
|
||||
logger_instance = new logger();
|
||||
}
|
||||
}
|
||||
return logger_instance;
|
||||
}*/
|
||||
|
||||
void write(int priority, String s) {
|
||||
if (priority > debug_priority)
|
||||
return;
|
||||
synchronized (logger.class) {
|
||||
if (F == null)
|
||||
try {
|
||||
F = new PrintWriter(paths.logFolder + filename + ".txt");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
|
||||
|
||||
// Get the date today using Calendar object.
|
||||
Date today = Calendar.getInstance().getTime();
|
||||
// Using DateFormat format method we can create a string
|
||||
// representation of a date with the defined format.
|
||||
String reportDate = df.format(today);
|
||||
// Print what date is today!
|
||||
F.append(reportDate + " ---- " + s + "\n");
|
||||
F.flush();
|
||||
}
|
||||
// F.println(s);
|
||||
}
|
||||
|
||||
void close() {
|
||||
F.close();
|
||||
}
|
||||
|
||||
public String file_name() {
|
||||
return paths.logFolder + filename + ".txt";
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class openSMILEclassifier extends Classifier {
|
||||
|
||||
@Override
|
||||
public boolean configure(JSONObject jo) {
|
||||
configFile = jo.getString("config");
|
||||
onyxentity = jo.getString("onyxentity");
|
||||
intype = jo.getString("intype");
|
||||
return true;
|
||||
/*Process p;
|
||||
try {
|
||||
p = Runtime.getRuntime().exec("cp "+paths.SMILExtractDir+paths.SMILEconfig+ " "+
|
||||
paths.SMILExtractDir+paths.SMILEconfigAugmented);
|
||||
p.waitFor();
|
||||
String[] cmd={"sh","-c","echo model="+paths.SMILExtractDir+SVMModelName+".model"+
|
||||
" >> "+paths.SMILExtractDir+paths.SMILEconfigAugmented};
|
||||
p = Runtime.getRuntime().exec(cmd);
|
||||
p.waitFor();
|
||||
String[] cmd2={"sh","-c","echo scale="+paths.SMILExtractDir+SVMModelName+".scale"+
|
||||
" >> "+paths.SMILExtractDir+paths.SMILEconfigAugmented};
|
||||
p = Runtime.getRuntime().exec(cmd2);
|
||||
p.waitFor();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject classify(String audioFile) {
|
||||
//String out = "";
|
||||
String line="";
|
||||
String fullLine="";
|
||||
/*if(model.compareTo("Arousal")==0)
|
||||
prepareConfigFile("svmarousal");
|
||||
if(model.compareTo("Valence")==0)
|
||||
prepareConfigFile("svmvalence");
|
||||
*/
|
||||
try {
|
||||
String str = paths.SMILExtractDir+"SMILExtract "+
|
||||
" -C "+paths.SMILExtractDir+configFile+
|
||||
" -I "+audioFile+ " -l 1";
|
||||
Process p = Runtime.getRuntime().exec(str,null,new File(paths.SMILExtractDir));
|
||||
logger_instance.write(1,"opensmile command: " + str);
|
||||
p.waitFor();
|
||||
logger_instance.write(1,"opensmile command performed");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine=fullLine+line;
|
||||
in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
||||
while((line=in.readLine())!=null)
|
||||
fullLine=fullLine+line;
|
||||
logger_instance.write(1,"opensmile output:"+ fullLine);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject jo = new JSONObject(fullLine);
|
||||
//int idx1 = fullLine.indexOf("~~>");
|
||||
//int idx2 = fullLine.indexOf("<~~");
|
||||
//out = fullLine.substring(idx1+3, idx2-1);
|
||||
|
||||
JSONObject jop = new JSONObject();
|
||||
switch((String)jo.get("TYPE")){
|
||||
case "regression":
|
||||
double out = jo.getDouble("VALUE");
|
||||
double conf = (double)((JSONObject)jo.getJSONArray("PROB").get(0)).get("CONFIDENCE");
|
||||
jop.put(onyxentity, out);
|
||||
jop.put("confidence", conf);
|
||||
break;
|
||||
case "classification":
|
||||
jop.put(onyxentity, jo.getJSONArray("PROB"));
|
||||
break;
|
||||
}
|
||||
return jop;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package com.opensmile.maven;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class paths {
|
||||
static String FileDirectory = getVar("REST_FILES");
|
||||
static String SMILExtractDir = getVar("REST_OPENSMILE");
|
||||
static String logFile = getVar("REST_OPENSMILE") + "/log.txt";
|
||||
static String logFolder = getVar("REST_OPENSMILE") + "/logs/";
|
||||
static String SMILEconfig = "IS09_emotion_Mine_AR_res_4corpus_0_FE.conf";
|
||||
static String SMILEconfigAugmented = "IS09_emotion_Mine_AR_res_4corpus_0_FE_Augmented.conf";
|
||||
static String var_file = "/var/rest_vars";
|
||||
|
||||
static String getVar(String varname) {
|
||||
// return "done";
|
||||
BufferedReader bufferedReader = null;
|
||||
File f = null;
|
||||
var_file = "/var/rest_vars";
|
||||
try {
|
||||
// return var_file;
|
||||
f = new File(var_file);
|
||||
// return "done"+f.getAbsolutePath();
|
||||
System.out.println(f.getAbsolutePath());
|
||||
if (!f.exists()) {
|
||||
System.out.println(f.getAbsolutePath() + " does not exist!");
|
||||
FileNotFoundException e = new FileNotFoundException();
|
||||
throw e;
|
||||
}
|
||||
bufferedReader = new BufferedReader(new FileReader(var_file));
|
||||
String line;
|
||||
String[] ls;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.length() < 2) {
|
||||
bufferedReader.close();
|
||||
return "";
|
||||
}
|
||||
ls = line.split("=");
|
||||
if (ls[0].compareTo(varname) == 0) {
|
||||
bufferedReader.close();
|
||||
return ls[1];
|
||||
}
|
||||
}
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
// System.out.println();
|
||||
e.printStackTrace();
|
||||
return f.getAbsolutePath() + " " + e.getMessage();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
/*
|
||||
* static String getBashVar(String varname){ Process p; String line; String
|
||||
* fullLine=""; String ls[]; try { String[]
|
||||
* cmd={"sh","-c","echo &"+varname};// | grep "+varname+" |
|
||||
* tee"};//echo $"+varname}; p = Runtime.getRuntime().exec(cmd);//
|
||||
* p.waitFor(); BufferedReader in = new BufferedReader(new
|
||||
* InputStreamReader(p.getInputStream()));
|
||||
* while((line=in.readLine())!=null){ ls = line.split("=");
|
||||
* if(ls[0].compareTo(varname)==0) return ls[1]; } } catch (IOException |
|
||||
* InterruptedException e) { e.printStackTrace(); } return fullLine; }
|
||||
*/
|
||||
}
|
||||
Referência em uma Nova Issue
Bloquear um usuário