Remove defunct Haven processing
This commit is contained in:
@@ -101,9 +101,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
SourceDataLine play = null;
|
SourceDataLine play = null;
|
||||||
|
|
||||||
public HavenQueue havenQueue = new HavenQueue();
|
|
||||||
|
|
||||||
|
|
||||||
public TargetDataLine microphone = null;
|
public TargetDataLine microphone = null;
|
||||||
public AudioInputStream microphoneStream = null;
|
public AudioInputStream microphoneStream = null;
|
||||||
|
|
||||||
@@ -113,7 +110,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
toolBar = new MainToolBar(this);
|
toolBar = new MainToolBar(this);
|
||||||
toolBar.addSeparator();
|
toolBar.addSeparator();
|
||||||
toolBar.add(Box.createHorizontalGlue());
|
toolBar.add(Box.createHorizontalGlue());
|
||||||
toolBar.add(havenQueue);
|
|
||||||
ob.add(toolBar, BorderLayout.NORTH);
|
ob.add(toolBar, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -815,7 +811,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Sentence s = (Sentence)o.getObject();
|
Sentence s = (Sentence)o.getObject();
|
||||||
if (!s.isLocked()) {
|
if (!s.isLocked()) {
|
||||||
havenQueue.submit(s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1128,7 +1123,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
if (snt.getId().equals(snt.getText())) {
|
if (snt.getId().equals(snt.getText())) {
|
||||||
havenQueue.submit(snt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Timer;
|
|
||||||
|
|
||||||
public class HavenQueue extends JPanel {
|
|
||||||
ConcurrentLinkedQueue<Sentence> sentenceList = new ConcurrentLinkedQueue<Sentence>();
|
|
||||||
|
|
||||||
Timer timer = new Timer();
|
|
||||||
|
|
||||||
Sentence currentSentence = null;
|
|
||||||
|
|
||||||
JLabel count;
|
|
||||||
|
|
||||||
public HavenQueue() {
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
count = new JLabel("Haven queue: 0");
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
add(count, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
count.setOpaque(false);
|
|
||||||
setOpaque(false);
|
|
||||||
count.setForeground(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processQueue() {
|
|
||||||
|
|
||||||
count.setText("Haven queue: " + sentenceList.size());
|
|
||||||
|
|
||||||
if (currentSentence == null) {
|
|
||||||
// Grab a new sentence to process.
|
|
||||||
currentSentence = sentenceList.poll();
|
|
||||||
|
|
||||||
if (currentSentence != null) {
|
|
||||||
if (!currentSentence.postHavenData()) { // Failed. Add to the end of the queue and wait a bit
|
|
||||||
submit(currentSentence);
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSentence != null) {
|
|
||||||
currentSentence.processPendingHaven();
|
|
||||||
int status = currentSentence.getHavenStatus();
|
|
||||||
switch (status) {
|
|
||||||
case 0: // Um... not running...?
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
case 1: // Still processing...
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
case 2: // Finished
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
case 3: // Failed
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void submit(Sentence s) {
|
|
||||||
s.setOverrideText("[queued...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(s);
|
|
||||||
sentenceList.add(s);
|
|
||||||
count.setText("Haven queue: " + sentenceList.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,8 +44,6 @@ public class Options extends JDialog {
|
|||||||
JSpinner etherealAttenuation;
|
JSpinner etherealAttenuation;
|
||||||
JSpinner etherealOffset;
|
JSpinner etherealOffset;
|
||||||
|
|
||||||
JTextField havenApiKey;
|
|
||||||
|
|
||||||
JTextField externalEditor;
|
JTextField externalEditor;
|
||||||
|
|
||||||
JTextArea startupScript;
|
JTextArea startupScript;
|
||||||
@@ -325,11 +323,6 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text submission", getBoolean("process.haven.auto"));
|
|
||||||
havenApiKey = addTextField(optionsPanel, "Haven OnDemand API Key", get("process.haven.apikey"));
|
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
|
||||||
|
|
||||||
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"));
|
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"));
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
@@ -585,9 +578,6 @@ public class Options extends JDialog {
|
|||||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||||
|
|
||||||
defaultPrefs.put("process.sphinx", "false");
|
|
||||||
defaultPrefs.put("process.haven.apikey", "");
|
|
||||||
|
|
||||||
defaultPrefs.put("editor.external", "");
|
defaultPrefs.put("editor.external", "");
|
||||||
|
|
||||||
defaultPrefs.put("cache.size", "100");
|
defaultPrefs.put("cache.size", "100");
|
||||||
@@ -709,8 +699,6 @@ public class Options extends JDialog {
|
|||||||
set("catenation.post-section", postSectionGap.getValue());
|
set("catenation.post-section", postSectionGap.getValue());
|
||||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||||
set("process.sphinx", enableParsing.isSelected());
|
|
||||||
set("process.haven.apikey", havenApiKey.getText());
|
|
||||||
set("editor.external", externalEditor.getText());
|
set("editor.external", externalEditor.getText());
|
||||||
set("cache.size", cacheSize.getValue());
|
set("cache.size", cacheSize.getValue());
|
||||||
set("audio.recording.trim.fft", fftThreshold.getValue());
|
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||||
|
|||||||
@@ -49,14 +49,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
double gain = 1.0d;
|
double gain = 1.0d;
|
||||||
|
|
||||||
String havenJobId = "";
|
|
||||||
|
|
||||||
// 0: Not processed
|
|
||||||
// 1: Submitted
|
|
||||||
// 2: Procesisng finished
|
|
||||||
// 3: Processing failed
|
|
||||||
int havenStatus = 0;
|
|
||||||
|
|
||||||
String overrideText = null;
|
String overrideText = null;
|
||||||
|
|
||||||
public void setOverrideText(String s) { overrideText = s; }
|
public void setOverrideText(String s) { overrideText = s; }
|
||||||
@@ -190,9 +182,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT();
|
autoTrimSampleFFT();
|
||||||
}
|
}
|
||||||
if (Options.getBoolean("process.haven.auto")) {
|
|
||||||
recognise();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -495,7 +484,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void recognise() {
|
public void recognise() {
|
||||||
AudiobookRecorder.window.havenQueue.submit(Sentence.this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked(boolean l) {
|
public void setLocked(boolean l) {
|
||||||
@@ -596,137 +584,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return attention;
|
return attention;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHavenJobId() {
|
|
||||||
return havenJobId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHavenJobId(String i) {
|
|
||||||
havenJobId = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHavenStatus() {
|
|
||||||
return havenStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHavenStatus(int i) {
|
|
||||||
havenStatus = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public boolean postHavenData() {
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return false;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
setOverrideText("[submitting...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/api/async/recognizespeech/v2?apikey=" + apiKey);
|
|
||||||
|
|
||||||
FileBody bin = new FileBody(getFile());
|
|
||||||
StringBody language = new StringBody("en-GB");
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create()
|
|
||||||
.addPart("language_model", language)
|
|
||||||
.addPart("file", bin)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
System.err.println("Error posting data: " + response.getStatusLine().getStatusCode());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
havenJobId = obj.getString("jobID");
|
|
||||||
System.err.println("Submitted new Haven OnDemand job #" + havenJobId);
|
|
||||||
havenStatus = 1;
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
// eddec91c-6018-4dcd-bd8d-5e96b23e334c --form "language_model=en-US" --form "file=@3e67460c-f298-4e2c-a412-d375d489e1b3.wav"
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processPendingHaven() {
|
|
||||||
if (havenStatus != 1) return;
|
|
||||||
|
|
||||||
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/job/status/" + havenJobId + "?apikey=" + apiKey);
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create().build();
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
|
|
||||||
System.err.println(havenJobId + ": " + obj.getString("status"));
|
|
||||||
|
|
||||||
if (obj.getString("status").equals("finished")) {
|
|
||||||
havenStatus = 2;
|
|
||||||
JSONArray textItems = obj.getJSONArray("actions").getJSONObject(0).getJSONObject("result").getJSONArray("items");
|
|
||||||
|
|
||||||
StringBuilder out = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < textItems.length(); i++) {
|
|
||||||
out.append(textItems.getJSONObject(i).getString("text"));
|
|
||||||
out.append(" ");
|
|
||||||
}
|
|
||||||
String result = out.toString();
|
|
||||||
setText(result.trim());
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
System.err.println(result);
|
|
||||||
} else if (obj.getString("status").equals("queued")) {
|
|
||||||
havenStatus = 1;
|
|
||||||
setOverrideText("[processing...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
} else {
|
|
||||||
text = id;
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getPeakValue() {
|
public double getPeakValue() {
|
||||||
double oldGain = gain;
|
double oldGain = gain;
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
|
|||||||
Reference in New Issue
Block a user