Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21d7d9d597 | |||
| 746f47a5fa | |||
| c67e6d6abc | |||
| 1f722f5df3 | |||
| df4eae1d66 | |||
| 4d435b4fc1 | |||
| f95ae10d03 | |||
| 423d840d83 | |||
| 1997b0bf9b | |||
| b206fb33aa | |||
| 11b26e396c | |||
| 94139e6ac6 | |||
| c0cc2432ff | |||
| f86aaa3782 | |||
| 690a8f0c3b | |||
| 1de0ca8d60 | |||
| de149c5d85 | |||
| 7d2b11473b | |||
| 4c25fccc86 | |||
| 5e310b0224 | |||
| 169802ccaf |
38
README.md
38
README.md
@@ -29,12 +29,13 @@ From here on much is controlled by key presses.
|
|||||||
appended to the currently selected chapter, or to the last chapter if none is selected.
|
appended to the currently selected chapter, or to the last chapter if none is selected.
|
||||||
* Press and hold "T" to record a new phrase that is the start of a new paragraph. This adds the "post paragraph" gap to the previous sentence. Otherwise it does the same as "R".
|
* Press and hold "T" to record a new phrase that is the start of a new paragraph. This adds the "post paragraph" gap to the previous sentence. Otherwise it does the same as "R".
|
||||||
* Press and hold "F" to record a "continuation" phrase. This sets the previous phrase's post-gap to be the "short" gap instead of the normal length gap.
|
* Press and hold "F" to record a "continuation" phrase. This sets the previous phrase's post-gap to be the "short" gap instead of the normal length gap.
|
||||||
|
* Press and hold "Y" to record a new phrase that is the start of a new section. This add the "post section" gap to the previous sentence. Otherwise it does the same as "R".
|
||||||
* Press "D" to delete the last phrase you recorded.
|
* Press "D" to delete the last phrase you recorded.
|
||||||
* Press "E" to re-record the currently selected phrase.
|
* Press "E" to re-record the currently selected phrase.
|
||||||
|
|
||||||
Each phrase you record will be briefly analysed using FFT to find the start and end of the audio and set
|
Each phrase you record can be automatically analysed to find the start and end of the audio and set
|
||||||
crop marks appropriately. These can be adjusted in the waveform display when a phrase is selected. You can also
|
crop marks appropriately. These can be adjusted in the waveform display when a phrase is selected. You can also
|
||||||
re-run the analysis using either the default FFT method or using a peak detector method (finding the first and last points
|
re-run the analysis using either FFT or a peak detector method (finding the first and last points
|
||||||
where the audio amplitude rises above the backround noise).
|
where the audio amplitude rises above the backround noise).
|
||||||
|
|
||||||
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
||||||
@@ -53,18 +54,14 @@ edit the text of this ID to identify the recordings. You
|
|||||||
may, for instance, change it to have the same text as the
|
may, for instance, change it to have the same text as the
|
||||||
audio contains.
|
audio contains.
|
||||||
|
|
||||||
To help with this the Haven On-Demand online speech recognition
|
The audio can also be automatically converted to text if you have an suitable command-line
|
||||||
service is integrated with the system and can be used to try and convert the
|
executable that will work. One example is (on Linux) [DeepSpeech](https://github.com/mozilla/DeepSpeech) by Mozilla.
|
||||||
audio into text. Right clicking on a recording brings
|
|
||||||
up a menu which includes the option to try and convert
|
|
||||||
the audio into text. The detected text is then used to
|
|
||||||
replace the current recording ID / text.
|
|
||||||
|
|
||||||
File layout
|
File layout
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
All data is stored in your "storage" directory (specified in Options). Each book (which is a directory named after the
|
All data is stored in your "storage" directory (specified in Options). Each book (which is a directory named after the
|
||||||
title of the book) has an associated XML file (audiobook.abk) and a directory "files" where all the audio (stored as WAV
|
title of the book) has an associated XML file (audiobook.abx) and a directory "files" where all the audio (stored as WAV
|
||||||
files) is placed.
|
files) is placed.
|
||||||
|
|
||||||
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
||||||
@@ -81,3 +78,26 @@ Building
|
|||||||
5. Build with `ant build`
|
5. Build with `ant build`
|
||||||
6. Run with `java -jar ./AudiobookRecorder.jar`
|
6. Run with `java -jar ./AudiobookRecorder.jar`
|
||||||
|
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Extra Resources
|
||||||
|
===============
|
||||||
|
|
||||||
|
* DeepSpeech wrapper script
|
||||||
|
|
||||||
|
This is a small script that will convert the audio into a format DeepSpeech likes and call the `deepspeech` executable, removing any extra rubbish from the output. It
|
||||||
|
also requires `sox` to be installed for the audio conversion.
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ID=$$
|
||||||
|
FILE=$1
|
||||||
|
BINPATH=${HOME}/local/bin
|
||||||
|
MODELS=${HOME}/ds/deepspeech-0.6.1-models
|
||||||
|
|
||||||
|
sox "$FILE" -r 16000 -c 1 -b 16 "/tmp/ds-${ID}.wav"
|
||||||
|
${BINPATH}/deepspeech --model ${MODELS}/output_graph.pbmm --lm ${MODELS}/lm.binary --trie ${MODELS}/trie --audio "/tmp/ds-${ID}.wav" 2>/dev/null
|
||||||
|
rm /tmp/ds-${ID}.wav
|
||||||
|
```
|
||||||
|
|||||||
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/commons-text.jar
LFS
vendored
Normal file
BIN
deps/commons-text.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
@@ -1 +1 @@
|
|||||||
version=0.3.5
|
version=0.3.9
|
||||||
|
|||||||
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 489 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 717 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -10,6 +10,7 @@ public class AGC implements Effect {
|
|||||||
double attack;
|
double attack;
|
||||||
|
|
||||||
public AGC(double c, double a, double d, double l) {
|
public AGC(double c, double a, double d, double l) {
|
||||||
|
Debug.trace();
|
||||||
ceiling = c;
|
ceiling = c;
|
||||||
attack = a;
|
attack = a;
|
||||||
decay = d;
|
decay = d;
|
||||||
@@ -18,14 +19,17 @@ public class AGC implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
|
Debug.trace();
|
||||||
gain = 1d;
|
gain = 1d;
|
||||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
||||||
@@ -55,14 +59,17 @@ public class AGC implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sr) {
|
public void init(double sr) {
|
||||||
|
Debug.trace();
|
||||||
gain = 1d;
|
gain = 1d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.*;
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class AboutPanel extends JPanel {
|
public class AboutPanel extends JPanel {
|
||||||
|
|
||||||
public AboutPanel() {
|
public AboutPanel() {
|
||||||
|
Debug.trace();
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
JLabel icon = new JLabel(Icons.appIcon);
|
JLabel icon = new JLabel(Icons.appIcon);
|
||||||
add(icon, BorderLayout.WEST);
|
add(icon, BorderLayout.WEST);
|
||||||
@@ -17,7 +22,7 @@ public class AboutPanel extends JPanel {
|
|||||||
|
|
||||||
JLabel l1 = new JLabel("AudiobookRecorder");
|
JLabel l1 = new JLabel("AudiobookRecorder");
|
||||||
JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version"));
|
JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version"));
|
||||||
JLabel l3 = new JLabel("(c) 2018 Majenko Technologies");
|
JLabel l3 = new JLabel("(c) 2020 Majenko Technologies");
|
||||||
|
|
||||||
l1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
l1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||||
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||||
|
|||||||
@@ -5,21 +5,26 @@ import java.util.ArrayList;
|
|||||||
public class Amplifier implements Effect {
|
public class Amplifier implements Effect {
|
||||||
double gain;
|
double gain;
|
||||||
public Amplifier() {
|
public Amplifier() {
|
||||||
|
Debug.trace();
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
}
|
}
|
||||||
public Amplifier(double g) {
|
public Amplifier(double g) {
|
||||||
|
Debug.trace();
|
||||||
gain = g;
|
gain = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return "Amplifier (" + gain + ")";
|
return "Amplifier (" + gain + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
|
Debug.trace();
|
||||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
samples[Sentence.LEFT][i] *= gain;
|
samples[Sentence.LEFT][i] *= gain;
|
||||||
samples[Sentence.RIGHT][i] *= gain;
|
samples[Sentence.RIGHT][i] *= gain;
|
||||||
@@ -27,21 +32,26 @@ public class Amplifier implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getGain() {
|
public double getGain() {
|
||||||
|
Debug.trace();
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGain(double g) {
|
public void setGain(double g) {
|
||||||
|
Debug.trace();
|
||||||
gain = g;
|
gain = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
|
Debug.trace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,84 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import java.io.File;
|
||||||
import javax.swing.*;
|
import java.io.FileInputStream;
|
||||||
import javax.swing.event.*;
|
import java.io.FileOutputStream;
|
||||||
import javax.swing.text.*;
|
import java.io.IOException;
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import java.nio.file.*;
|
|
||||||
import javax.swing.tree.*;
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.prefs.*;
|
|
||||||
import java.io.*;
|
|
||||||
import it.sauronsoftware.jave.*;
|
|
||||||
import com.mpatric.mp3agic.*;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.zip.*;
|
import java.util.ArrayList;
|
||||||
import javax.swing.filechooser.*;
|
import java.util.ArrayDeque;
|
||||||
import javax.imageio.*;
|
import java.util.Enumeration;
|
||||||
import org.w3c.dom.*;
|
import java.util.Properties;
|
||||||
import javax.xml.parsers.*;
|
import java.util.Queue;
|
||||||
import java.io.*;
|
import java.util.Random;
|
||||||
import edu.cmu.sphinx.api.*;
|
import java.util.Timer;
|
||||||
import edu.cmu.sphinx.decoder.adaptation.*;
|
import java.util.TimerTask;
|
||||||
import edu.cmu.sphinx.result.*;
|
import java.util.TreeMap;
|
||||||
import org.w3c.dom.Node;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.*;
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Container;
|
||||||
|
import java.awt.Desktop;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.event.AdjustmentListener;
|
||||||
|
import java.awt.event.AdjustmentEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseWheelListener;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.Box;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.InputMap;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JMenu;
|
||||||
|
import javax.swing.JMenuBar;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JScrollBar;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.JSplitPane;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.tree.TreeCellRenderer;
|
||||||
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
|
import javax.swing.event.TreeSelectionListener;
|
||||||
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.transform.Transformer;
|
import javax.xml.transform.Transformer;
|
||||||
@@ -34,10 +86,17 @@ import javax.xml.transform.TransformerFactory;
|
|||||||
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.dom.DOMSource;
|
||||||
import javax.xml.transform.stream.StreamResult;
|
import javax.xml.transform.stream.StreamResult;
|
||||||
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
|
import javax.sound.sampled.SourceDataLine;
|
||||||
|
import javax.sound.sampled.TargetDataLine;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
import org.w3c.dom.Attr;
|
import org.w3c.dom.Attr;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
|
|
||||||
@@ -45,8 +104,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
// Settings - tweakable
|
// Settings - tweakable
|
||||||
|
|
||||||
public static final String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us";
|
|
||||||
|
|
||||||
static Properties config = new Properties();
|
static Properties config = new Properties();
|
||||||
TreeMap<String, EffectGroup> effects;
|
TreeMap<String, EffectGroup> effects;
|
||||||
|
|
||||||
@@ -83,6 +140,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
JMenuItem toolsArchive;
|
JMenuItem toolsArchive;
|
||||||
JMenuItem toolsCoverArt;
|
JMenuItem toolsCoverArt;
|
||||||
JMenuItem toolsManuscript;
|
JMenuItem toolsManuscript;
|
||||||
|
JMenuItem toolsReloadEffects;
|
||||||
JMenuItem toolsOptions;
|
JMenuItem toolsOptions;
|
||||||
|
|
||||||
JMenuItem helpAbout;
|
JMenuItem helpAbout;
|
||||||
@@ -91,7 +149,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
JPanel statusBar;
|
JPanel statusBar;
|
||||||
|
|
||||||
JLabel statusLabel;
|
NoiseFloor noiseFloorLabel;
|
||||||
|
|
||||||
JScrollPane mainScroll;
|
JScrollPane mainScroll;
|
||||||
|
|
||||||
@@ -123,6 +181,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
JSpinner postSentenceGap;
|
JSpinner postSentenceGap;
|
||||||
JSpinner gainPercent;
|
JSpinner gainPercent;
|
||||||
|
Timer waveformUpdater = new Timer();
|
||||||
JCheckBox locked;
|
JCheckBox locked;
|
||||||
JCheckBox attention;
|
JCheckBox attention;
|
||||||
JCheckBox rawAudio;
|
JCheckBox rawAudio;
|
||||||
@@ -147,25 +206,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public TargetDataLine microphone = null;
|
public TargetDataLine microphone = null;
|
||||||
public AudioInputStream microphoneStream = null;
|
public AudioInputStream microphoneStream = null;
|
||||||
|
|
||||||
public Configuration sphinxConfig;
|
|
||||||
public StreamSpeechRecognizer recognizer;
|
|
||||||
|
|
||||||
public static AudiobookRecorder window;
|
public static AudiobookRecorder window;
|
||||||
|
|
||||||
void initSphinx() {
|
public Queue<Runnable>processQueue = null;
|
||||||
Debug.trace();
|
public QueueMonitor queueMonitor = null;
|
||||||
sphinxConfig = new Configuration();
|
|
||||||
|
|
||||||
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
|
|
||||||
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
|
||||||
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
|
||||||
|
|
||||||
try {
|
|
||||||
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void buildToolbar(Container ob) {
|
void buildToolbar(Container ob) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
@@ -330,6 +374,18 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
loadManuscript();
|
loadManuscript();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toolsReloadEffects = new JMenuItem("Reload effects");
|
||||||
|
toolsReloadEffects.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Debug.trace();
|
||||||
|
queueJob(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
loadEffects();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
toolsOptions = new JMenuItem("Options");
|
toolsOptions = new JMenuItem("Options");
|
||||||
toolsOptions.addActionListener(new ActionListener() {
|
toolsOptions.addActionListener(new ActionListener() {
|
||||||
@@ -343,6 +399,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
toolsMenu.add(toolsArchive);
|
toolsMenu.add(toolsArchive);
|
||||||
toolsMenu.add(toolsCoverArt);
|
toolsMenu.add(toolsCoverArt);
|
||||||
toolsMenu.add(toolsManuscript);
|
toolsMenu.add(toolsManuscript);
|
||||||
|
toolsMenu.add(toolsReloadEffects);
|
||||||
toolsMenu.addSeparator();
|
toolsMenu.addSeparator();
|
||||||
toolsMenu.add(toolsOptions);
|
toolsMenu.add(toolsOptions);
|
||||||
|
|
||||||
@@ -381,6 +438,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Debug.debugEnabled = CLI.isSet("debug");
|
Debug.debugEnabled = CLI.isSet("debug");
|
||||||
Debug.traceEnabled = CLI.isSet("trace");
|
Debug.traceEnabled = CLI.isSet("trace");
|
||||||
|
|
||||||
|
processQueue = new ArrayDeque<Runnable>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
|
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
|
||||||
@@ -404,6 +463,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
Options.loadPreferences();
|
Options.loadPreferences();
|
||||||
|
|
||||||
|
queueMonitor = new QueueMonitor(processQueue);
|
||||||
|
|
||||||
|
for (int i = 0; i < Options.getInteger("process.threads"); i++) {
|
||||||
|
WorkerThread worker = new WorkerThread(processQueue, queueMonitor);
|
||||||
|
queueMonitor.addThread(worker);
|
||||||
|
worker.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
execScript(Options.get("scripts.startup"));
|
execScript(Options.get("scripts.startup"));
|
||||||
|
|
||||||
CacheManager.setCacheSize(Options.getInteger("cache.size"));
|
CacheManager.setCacheSize(Options.getInteger("cache.size"));
|
||||||
@@ -483,11 +551,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (selectedSentence != null) {
|
if (selectedSentence != null) {
|
||||||
selectedSentence.autoTrimSampleFFT();
|
queueJob(new SentenceJob(selectedSentence) {
|
||||||
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset());
|
public void run() {
|
||||||
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing());
|
sentence.autoTrimSampleFFT();
|
||||||
postSentenceGap.setValue(selectedSentence.getPostGap());
|
updateWaveformMarkers();
|
||||||
gainPercent.setValue((int)(selectedSentence.getGain() * 100d));
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -496,11 +565,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (selectedSentence != null) {
|
if (selectedSentence != null) {
|
||||||
selectedSentence.autoTrimSamplePeak();
|
queueJob(new SentenceJob(selectedSentence) {
|
||||||
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset());
|
public void run() {
|
||||||
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing());
|
sentence.autoTrimSamplePeak();
|
||||||
postSentenceGap.setValue(selectedSentence.getPostGap());
|
updateWaveformMarkers();
|
||||||
gainPercent.setValue((int)(selectedSentence.getGain() * 100d));
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -608,8 +678,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
doCutSplit.setEnabled(false);
|
doCutSplit.setEnabled(false);
|
||||||
selectCutMode.setSelected(false);
|
selectCutMode.setSelected(false);
|
||||||
selectSplitMode.setSelected(false);
|
selectSplitMode.setSelected(false);
|
||||||
|
selectedSentence.reloadTree();
|
||||||
bookTreeModel.reload(selectedSentence);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
controlsTop.add(locked);
|
controlsTop.add(locked);
|
||||||
@@ -630,7 +699,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
selectedSentence.setAttentionFlag(false);
|
selectedSentence.setAttentionFlag(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bookTreeModel.reload(selectedSentence);
|
selectedSentence.reloadTree();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -698,10 +767,14 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
centralPanel.add(sampleControl, BorderLayout.SOUTH);
|
centralPanel.add(sampleControl, BorderLayout.SOUTH);
|
||||||
|
|
||||||
statusBar = new JPanel();
|
statusBar = new JPanel();
|
||||||
|
statusBar.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
add(statusBar, BorderLayout.SOUTH);
|
add(statusBar, BorderLayout.SOUTH);
|
||||||
|
|
||||||
statusLabel = new JLabel("Noise floor: " + getNoiseFloorDB() + "dB");
|
noiseFloorLabel = new NoiseFloor();
|
||||||
statusBar.add(statusLabel);
|
|
||||||
|
statusBar.add(noiseFloorLabel);
|
||||||
|
// statusBar.add(Box.createHorizontalStrut(2));
|
||||||
|
statusBar.add(queueMonitor);
|
||||||
|
|
||||||
buildToolbar(centralPanel);
|
buildToolbar(centralPanel);
|
||||||
|
|
||||||
@@ -885,12 +958,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (ev.getPropertyName().equals("dividerLocation")) {
|
if (ev.getPropertyName().equals("dividerLocation")) {
|
||||||
if ((bookTreeModel != null) && (book != null)) {
|
if ((bookTreeModel != null) && (book != null)) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
Debug.trace();
|
||||||
public void run() {
|
book.reloadTree();
|
||||||
Debug.trace();
|
|
||||||
bookTreeModel.reload(book);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -943,6 +1012,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Options.savePreferences();
|
Options.savePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queueJob(new VersionChecker());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bindKeys(JComponent component) {
|
void bindKeys(JComponent component) {
|
||||||
@@ -993,6 +1064,8 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
Properties props = System.getProperties();
|
||||||
|
props.setProperty("sun.java2d.opengl", "true");
|
||||||
try {
|
try {
|
||||||
config.load(AudiobookRecorder.class.getResourceAsStream("config.txt"));
|
config.load(AudiobookRecorder.class.getResourceAsStream("config.txt"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -1025,16 +1098,17 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
newbook.setComment(info.getComment().trim());
|
newbook.setComment(info.getComment().trim());
|
||||||
newbook.setACX(info.getACX().trim());
|
newbook.setACX(info.getACX().trim());
|
||||||
|
|
||||||
Chapter caud = new Chapter("audition", "Audition");
|
Chapter caud = new Chapter(UUID.randomUUID().toString(), "Audition");
|
||||||
Chapter copen = new Chapter("open", "Opening Credits");
|
Chapter copen = new Chapter(UUID.randomUUID().toString(), "Opening Credits");
|
||||||
Chapter cone = new Chapter("0001", "Chapter 1");
|
Chapter cclose = new Chapter(UUID.randomUUID().toString(), "Closing Credits");
|
||||||
Chapter cclose = new Chapter("close", "Closing Credits");
|
Chapter cone = new Chapter(UUID.randomUUID().toString(), "Chapter 1");
|
||||||
|
|
||||||
newbook.add(caud);
|
newbook.add(caud);
|
||||||
newbook.add(copen);
|
newbook.add(copen);
|
||||||
newbook.add(cone);
|
|
||||||
newbook.add(cclose);
|
newbook.add(cclose);
|
||||||
|
|
||||||
|
newbook.add(cone);
|
||||||
|
|
||||||
File bookRoot = new File(Options.get("path.storage"), newbook.getName());
|
File bookRoot = new File(Options.get("path.storage"), newbook.getName());
|
||||||
if (!bookRoot.exists()) {
|
if (!bookRoot.exists()) {
|
||||||
bookRoot.mkdirs();
|
bookRoot.mkdirs();
|
||||||
@@ -1043,6 +1117,10 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
File xml = new File(bookRoot, "audiobook.abx");
|
File xml = new File(bookRoot, "audiobook.abx");
|
||||||
Document doc = newbook.buildDocument();
|
Document doc = newbook.buildDocument();
|
||||||
|
|
||||||
|
File backup = new File(bookRoot, "audiobook.bak");
|
||||||
|
if (xml.exists()) {
|
||||||
|
xml.renameTo(backup);
|
||||||
|
}
|
||||||
|
|
||||||
// write the content into xml file
|
// write the content into xml file
|
||||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
@@ -1136,24 +1214,15 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
try {
|
try {
|
||||||
Configuration sphinxConfig = new Configuration();
|
|
||||||
|
|
||||||
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
|
|
||||||
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
|
||||||
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
|
||||||
|
|
||||||
sphinxConfig.setSampleRate((int)(book.getAudioFormat().getSampleRate() / 4f));
|
|
||||||
|
|
||||||
StreamSpeechRecognizer recognizer;
|
|
||||||
|
|
||||||
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
|
||||||
|
|
||||||
|
|
||||||
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
if (!snt.isLocked()) {
|
if (!snt.isLocked()) {
|
||||||
if (snt.getId().equals(snt.getText())) {
|
if (snt.getId().equals(snt.getText())) {
|
||||||
snt.doRecognition(recognizer);
|
queueJob(new SentenceJob(snt) {
|
||||||
|
public void run() {
|
||||||
|
sentence.doRecognition();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1186,7 +1255,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
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()) {
|
||||||
s.recognise();
|
queueJob(new SentenceJob(s) {
|
||||||
|
public void run() {
|
||||||
|
sentence.doRecognition();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1263,7 +1336,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
String type = (String)o.getObject2();
|
String type = (String)o.getObject2();
|
||||||
sent.setPostGapType(type);
|
sent.setPostGapType(type);
|
||||||
sent.setPostGap(Options.getInteger("catenation.post-sentence"));
|
sent.setPostGap(Options.getInteger("catenation.post-sentence"));
|
||||||
bookTreeModel.reload(sent);
|
sent.reloadTree();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setGapType.add(gapTypeSentence);
|
setGapType.add(gapTypeSentence);
|
||||||
@@ -1276,7 +1349,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
String type = (String)o.getObject2();
|
String type = (String)o.getObject2();
|
||||||
sent.setPostGapType(type);
|
sent.setPostGapType(type);
|
||||||
sent.setPostGap(Options.getInteger("catenation.short-sentence"));
|
sent.setPostGap(Options.getInteger("catenation.short-sentence"));
|
||||||
bookTreeModel.reload(sent);
|
sent.reloadTree();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setGapType.add(gapTypeContinuation);
|
setGapType.add(gapTypeContinuation);
|
||||||
@@ -1289,7 +1362,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
String type = (String)o.getObject2();
|
String type = (String)o.getObject2();
|
||||||
sent.setPostGapType(type);
|
sent.setPostGapType(type);
|
||||||
sent.setPostGap(Options.getInteger("catenation.post-paragraph"));
|
sent.setPostGap(Options.getInteger("catenation.post-paragraph"));
|
||||||
bookTreeModel.reload(sent);
|
sent.reloadTree();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setGapType.add(gapTypeParagraph);
|
setGapType.add(gapTypeParagraph);
|
||||||
@@ -1302,7 +1375,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
String type = (String)o.getObject2();
|
String type = (String)o.getObject2();
|
||||||
sent.setPostGapType(type);
|
sent.setPostGapType(type);
|
||||||
sent.setPostGap(Options.getInteger("catenation.post-section"));
|
sent.setPostGap(Options.getInteger("catenation.post-section"));
|
||||||
bookTreeModel.reload(sent);
|
sent.reloadTree();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setGapType.add(gapTypeSection);
|
setGapType.add(gapTypeSection);
|
||||||
@@ -1375,7 +1448,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Sentence s = (Sentence)o.getObject();
|
Sentence s = (Sentence)o.getObject();
|
||||||
s.runExternalProcessor(Utils.s2i(o.getActionCommand()));
|
queueJob(new SentenceExternalJob(s, Utils.s2i(o.getActionCommand())));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ob.setActionCommand(Integer.toString(i));
|
ob.setActionCommand(Integer.toString(i));
|
||||||
@@ -1431,14 +1504,19 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (!snt.isProcessed()) {
|
||||||
|
queueJob(new SentenceJob(snt) {
|
||||||
|
public void run() {
|
||||||
|
sentence.autoTrimSampleFFT();
|
||||||
|
updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
|
||||||
|
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak, AutoTrimThread.NewOnly);
|
|
||||||
Thread nt = new Thread(t);
|
|
||||||
nt.start();
|
|
||||||
ed.setVisible(true);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1446,14 +1524,18 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (!snt.isProcessed()) {
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.NewOnly);
|
queueJob(new SentenceJob(snt) {
|
||||||
Thread nt = new Thread(t);
|
public void run() {
|
||||||
nt.start();
|
sentence.autoTrimSampleFFT();
|
||||||
ed.setVisible(true);
|
updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1461,14 +1543,16 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
queueJob(new SentenceJob(snt) {
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak, AutoTrimThread.All);
|
public void run() {
|
||||||
Thread nt = new Thread(t);
|
sentence.autoTrimSamplePeak();
|
||||||
nt.start();
|
updateWaveformMarkers();
|
||||||
ed.setVisible(true);
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1476,14 +1560,16 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
queueJob(new SentenceJob(snt) {
|
||||||
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT, AutoTrimThread.All);
|
public void run() {
|
||||||
Thread nt = new Thread(t);
|
sentence.autoTrimSampleFFT();
|
||||||
nt.start();
|
updateWaveformMarkers();
|
||||||
ed.setVisible(true);
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1503,20 +1589,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
int pos = bookTreeModel.getIndexOfChild(book, chap);
|
int pos = bookTreeModel.getIndexOfChild(book, chap);
|
||||||
if (pos > 0) pos--;
|
if (pos > 0) pos--;
|
||||||
|
Chapter prevChap = (Chapter)bookTreeModel.getChild(book, pos);
|
||||||
int id = Utils.s2i(chap.getId());
|
bookTreeModel.removeNodeFromParent(chap);
|
||||||
if (id > 0) {
|
bookTreeModel.insertNodeInto(chap, book, pos);
|
||||||
Chapter prevChap = (Chapter)bookTreeModel.getChild(book, pos);
|
|
||||||
id = Utils.s2i(prevChap.getId());
|
|
||||||
if (id > 0) {
|
|
||||||
bookTreeModel.removeNodeFromParent(chap);
|
|
||||||
bookTreeModel.insertNodeInto(chap, book, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
book.renumberChapters();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
moveUp.setEnabled(idNumber > 0);
|
|
||||||
|
|
||||||
JMenuObject moveDown = new JMenuObject("Move Down", c, new ActionListener() {
|
JMenuObject moveDown = new JMenuObject("Move Down", c, new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -1525,21 +1602,13 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
int pos = bookTreeModel.getIndexOfChild(book, chap);
|
int pos = bookTreeModel.getIndexOfChild(book, chap);
|
||||||
pos++;
|
pos++;
|
||||||
int id = Utils.s2i(chap.getId());
|
Chapter nextChap = (Chapter)bookTreeModel.getChild(book, pos);
|
||||||
if (id > 0) {
|
if (nextChap != null) {
|
||||||
Chapter nextChap = (Chapter)bookTreeModel.getChild(book, pos);
|
bookTreeModel.removeNodeFromParent(chap);
|
||||||
if (nextChap != null) {
|
bookTreeModel.insertNodeInto(chap, book, pos);
|
||||||
id = Utils.s2i(nextChap.getId());
|
|
||||||
if (id > 0) {
|
|
||||||
bookTreeModel.removeNodeFromParent(chap);
|
|
||||||
bookTreeModel.insertNodeInto(chap, book, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
book.renumberChapters();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
moveDown.setEnabled(idNumber > 0);
|
|
||||||
|
|
||||||
JMenu mergeWith = new JMenu("Merge chapter with");
|
JMenu mergeWith = new JMenu("Merge chapter with");
|
||||||
for (Enumeration bc = book.children(); bc.hasMoreElements();) {
|
for (Enumeration bc = book.children(); bc.hasMoreElements();) {
|
||||||
@@ -1573,7 +1642,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
snt.setLocked(true);
|
snt.setLocked(true);
|
||||||
bookTreeModel.reload(snt);
|
snt.reloadTree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1586,7 +1655,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
snt.setLocked(false);
|
snt.setLocked(false);
|
||||||
bookTreeModel.reload(snt);
|
snt.reloadTree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1629,9 +1698,19 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter c = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
BatchConversionThread r = new BatchConversionThread(c);
|
|
||||||
Thread t = new Thread(r);
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
t.start();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (!snt.isLocked()) {
|
||||||
|
if (!snt.beenDetected()) {
|
||||||
|
queueJob(new SentenceJob(snt) {
|
||||||
|
public void run() {
|
||||||
|
sentence.doRecognition();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1665,7 +1744,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
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.isLocked()) {
|
if (!snt.isLocked()) {
|
||||||
snt.runExternalProcessor(Utils.s2i(o.getActionCommand()));
|
queueJob(new SentenceExternalJob(snt, Utils.s2i(o.getActionCommand())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2037,7 +2116,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
if (recording == null) return;
|
if (recording == null) return;
|
||||||
recording.stopRecording();
|
recording.stopRecording();
|
||||||
|
|
||||||
bookTreeModel.reload(book);
|
// book.reloadTree();
|
||||||
|
|
||||||
bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath()));
|
bookTree.expandPath(new TreePath(((DefaultMutableTreeNode)recording.getParent()).getPath()));
|
||||||
bookTree.setSelectionPath(new TreePath(recording.getPath()));
|
bookTree.setSelectionPath(new TreePath(recording.getPath()));
|
||||||
@@ -2095,9 +2174,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
public void addChapter() {
|
public void addChapter() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
Chapter c = book.addChapter();
|
Chapter c = book.addChapter();
|
||||||
Chapter lc = book.getLastChapter();
|
bookTreeModel.insertNodeInto(c, book, book.getChildCount());
|
||||||
int i = bookTreeModel.getIndexOfChild(book, lc);
|
|
||||||
bookTreeModel.insertNodeInto(c, book, i+1);
|
|
||||||
bookTree.scrollPathToVisible(new TreePath(c.getPath()));
|
bookTree.scrollPathToVisible(new TreePath(c.getPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2152,8 +2229,12 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
bookTree.setEditable(true);
|
bookTree.setEditable(true);
|
||||||
bookTree.setUI(new CustomTreeUI(mainScroll));
|
bookTree.setUI(new CustomTreeUI(mainScroll));
|
||||||
|
|
||||||
bookTree.setCellRenderer(new BookTreeRenderer());
|
TreeCellRenderer renderer = new BookTreeRenderer();
|
||||||
|
try {
|
||||||
|
bookTree.setCellRenderer(renderer);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
bookTree.setCellRenderer(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
|
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
|
||||||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback");
|
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback");
|
||||||
@@ -2244,17 +2325,20 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
|
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
|
||||||
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
||||||
book.setIcon(new ImageIcon(ri));
|
book.setIcon(new ImageIcon(ri));
|
||||||
bookTreeModel.reload(book);
|
} else {
|
||||||
|
book.setIcon(Icons.book);
|
||||||
}
|
}
|
||||||
|
book.reloadTree();
|
||||||
|
|
||||||
bookTree.expandPath(new TreePath(book.getPath()));
|
bookTree.expandPath(new TreePath(book.getPath()));
|
||||||
|
|
||||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||||
book.setIcon(Icons.book);
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gatherOrphans();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBookStructure(File f) {
|
public void loadBookStructure(File f) {
|
||||||
@@ -2280,7 +2364,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
|
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
|
||||||
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
||||||
book.setIcon(new ImageIcon(ri));
|
book.setIcon(new ImageIcon(ri));
|
||||||
bookTreeModel.reload(book);
|
book.reloadTree();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -2506,7 +2590,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
bookTree.expandPath(new TreePath(book.getPath()));
|
bookTree.expandPath(new TreePath(book.getPath()));
|
||||||
|
|
||||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||||
book.setIcon(Icons.book);
|
book.setIcon(Icons.book);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2579,7 +2663,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
roomNoise.stopRecording();
|
roomNoise.stopRecording();
|
||||||
centralPanel.setFlash(false);
|
centralPanel.setFlash(false);
|
||||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||||
}
|
}
|
||||||
}, 5000); // 5 seconds of recording
|
}, 5000); // 5 seconds of recording
|
||||||
}
|
}
|
||||||
@@ -2680,55 +2764,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AutoTrimThread implements Runnable {
|
|
||||||
ProgressDialog dialog;
|
|
||||||
Chapter chapter;
|
|
||||||
int type;
|
|
||||||
int scope;
|
|
||||||
|
|
||||||
public final static int FFT = 0;
|
|
||||||
public final static int Peak = 1;
|
|
||||||
public final static int NewOnly = 0;
|
|
||||||
public final static int All = 1;
|
|
||||||
|
|
||||||
public AutoTrimThread(Chapter c, ProgressDialog e, int t, int sc) {
|
|
||||||
super();
|
|
||||||
Debug.trace();
|
|
||||||
dialog = e;
|
|
||||||
chapter = c;
|
|
||||||
type = t;
|
|
||||||
scope = sc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void run() {
|
|
||||||
Debug.trace();
|
|
||||||
|
|
||||||
int numKids = chapter.getChildCount();
|
|
||||||
int kidCount = 0;
|
|
||||||
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
|
||||||
kidCount++;
|
|
||||||
dialog.setProgress(kidCount * 2000 / numKids);
|
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
|
||||||
if (scope == NewOnly) {
|
|
||||||
if (snt.isProcessed()) continue;
|
|
||||||
}
|
|
||||||
switch (type) {
|
|
||||||
case FFT:
|
|
||||||
snt.autoTrimSampleFFT();
|
|
||||||
break;
|
|
||||||
case Peak:
|
|
||||||
snt.autoTrimSamplePeak();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.closeDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExportThread implements Runnable {
|
class ExportThread implements Runnable {
|
||||||
ProgressDialog exportDialog;
|
ProgressDialog exportDialog;
|
||||||
Chapter chapter;
|
Chapter chapter;
|
||||||
@@ -3464,7 +3499,7 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
ImageIcon i = new ImageIcon(dest.getAbsolutePath());
|
ImageIcon i = new ImageIcon(dest.getAbsolutePath());
|
||||||
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
||||||
book.setIcon(new ImageIcon(ri));
|
book.setIcon(new ImageIcon(ri));
|
||||||
bookTreeModel.reload(book);
|
book.reloadTree();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -3477,16 +3512,42 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
updateWaveform(false);
|
updateWaveform(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateWaveform(boolean force) {
|
TimerTask waveformUpdaterTask = null;
|
||||||
|
|
||||||
|
synchronized public void updateWaveform(boolean force) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (selectedSentence != null) {
|
if (selectedSentence != null) {
|
||||||
if ((!force) && (sampleWaveform.getId() != null) && (sampleWaveform.getId().equals(selectedSentence.getId()))) return;
|
if ((!force) && (sampleWaveform.getId() != null) && (sampleWaveform.getId().equals(selectedSentence.getId()))) return;
|
||||||
sampleWaveform.setId(selectedSentence.getId());
|
|
||||||
if (rawAudio.isSelected()) {
|
synchronized (waveformUpdater) {
|
||||||
sampleWaveform.setData(selectedSentence.getRawAudioData());
|
try {
|
||||||
} else {
|
if (waveformUpdaterTask != null) {
|
||||||
sampleWaveform.setData(selectedSentence.getDoubleAudioData(effectsEnabled));
|
waveformUpdaterTask.cancel();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
waveformUpdaterTask = new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
sampleWaveform.setId(selectedSentence.getId());
|
||||||
|
if (rawAudio.isSelected()) {
|
||||||
|
sampleWaveform.setData(selectedSentence.getRawAudioData());
|
||||||
|
} else {
|
||||||
|
sampleWaveform.setData(selectedSentence.getDoubleAudioData(effectsEnabled));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
waveformUpdater.schedule(waveformUpdaterTask, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public void updateWaveformMarkers() {
|
||||||
|
if (selectedSentence != null) {
|
||||||
|
sampleWaveform.setMarkers(selectedSentence.getStartOffset(), selectedSentence.getEndOffset());
|
||||||
|
sampleWaveform.setAltMarkers(selectedSentence.getStartCrossing(), selectedSentence.getEndCrossing());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4103,4 +4164,63 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
|
|
||||||
// DocumentListener *//
|
// DocumentListener *//
|
||||||
|
|
||||||
|
public boolean sentenceIdExists(String id) {
|
||||||
|
for (Enumeration c = book.children(); c.hasMoreElements();) {
|
||||||
|
Chapter chp = (Chapter)c.nextElement();
|
||||||
|
for (Enumeration s = chp.children(); s.hasMoreElements();) {
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (snt.getId().equals(id)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void gatherOrphans() {
|
||||||
|
Chapter orphans = getChapterById("orphans");
|
||||||
|
if (orphans == null) {
|
||||||
|
orphans = new Chapter("orphans", "Orphan Files");
|
||||||
|
bookTreeModel.insertNodeInto(orphans, book, book.getChildCount());
|
||||||
|
}
|
||||||
|
File bookRoot = new File(Options.get("path.storage"), book.getName());
|
||||||
|
File[] files = new File(bookRoot, "files").listFiles();
|
||||||
|
for (File f : files) {
|
||||||
|
String filename = f.getName();
|
||||||
|
if (filename.startsWith(".")) continue;
|
||||||
|
if (filename.startsWith("backup")) continue;
|
||||||
|
if (filename.equals("room-noise.wav")) continue;
|
||||||
|
if (filename.endsWith(".wav")) {
|
||||||
|
String id = filename.substring(0, filename.length() - 4);
|
||||||
|
Debug.d("Testing orphanicity of", id);
|
||||||
|
if (!sentenceIdExists(id)) {
|
||||||
|
Sentence newSentence = new Sentence(id, id);
|
||||||
|
bookTreeModel.insertNodeInto(newSentence, orphans, orphans.getChildCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (orphans.getChildCount() == 0) {
|
||||||
|
try {
|
||||||
|
bookTreeModel.removeNodeFromParent(orphans);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter getChapterById(String id) {
|
||||||
|
for (Enumeration c = book.children(); c.hasMoreElements();) {
|
||||||
|
Chapter chp = (Chapter)c.nextElement();
|
||||||
|
if (chp.getId().equals(id)) return chp;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queueJob(Runnable r) {
|
||||||
|
synchronized(processQueue) {
|
||||||
|
processQueue.add(r);
|
||||||
|
if (r instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)r;
|
||||||
|
sj.setQueued();
|
||||||
|
}
|
||||||
|
processQueue.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,5 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
// Biquad.java
|
|
||||||
//
|
|
||||||
// Created by Nigel Redmon on 11/24/12
|
|
||||||
// EarLevel Engineering: earlevel.com
|
|
||||||
// Copyright 2012 Nigel Redmon
|
|
||||||
// Translated to Java 2019 Majenko Technologies
|
|
||||||
//
|
|
||||||
// For a complete explanation of the Biquad code:
|
|
||||||
// http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
|
|
||||||
//
|
|
||||||
// License:
|
|
||||||
//
|
|
||||||
// This source code is provided as is, without warranty.
|
|
||||||
// You may copy and distribute verbatim copies of this document.
|
|
||||||
// You may modify and use this source code to create binary code
|
|
||||||
// for your own purposes, free or commercial.
|
|
||||||
//
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Biquad implements Effect {
|
public class Biquad implements Effect {
|
||||||
@@ -37,6 +19,7 @@ public class Biquad implements Effect {
|
|||||||
double sampleFrequency;
|
double sampleFrequency;
|
||||||
|
|
||||||
public Biquad() {
|
public Biquad() {
|
||||||
|
Debug.trace();
|
||||||
type = Lowpass;
|
type = Lowpass;
|
||||||
a0 = 1.0d;
|
a0 = 1.0d;
|
||||||
a1 = 0.0d;
|
a1 = 0.0d;
|
||||||
@@ -54,6 +37,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
setBiquad(type, Fc, Q, peakGainDB);
|
setBiquad(type, Fc, Q, peakGainDB);
|
||||||
lz1 = 0.0;
|
lz1 = 0.0;
|
||||||
lz2 = 0.0;
|
lz2 = 0.0;
|
||||||
@@ -63,26 +47,31 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(int typei) {
|
public void setType(int typei) {
|
||||||
|
Debug.trace();
|
||||||
type = typei;
|
type = typei;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQ(double Qi) {
|
public void setQ(double Qi) {
|
||||||
|
Debug.trace();
|
||||||
Q = Qi;
|
Q = Qi;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFc(double Fci) {
|
public void setFc(double Fci) {
|
||||||
|
Debug.trace();
|
||||||
Fc = Fci;
|
Fc = Fci;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPeakGain(double peakGainDB) {
|
public void setPeakGain(double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
peakGain = peakGainDB;
|
peakGain = peakGainDB;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
type = typei;
|
type = typei;
|
||||||
Q = Qi;
|
Q = Qi;
|
||||||
Fc = Fci;
|
Fc = Fci;
|
||||||
@@ -90,6 +79,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
|
Debug.trace();
|
||||||
lz1 = 0d;
|
lz1 = 0d;
|
||||||
lz2 = 0d;
|
lz2 = 0d;
|
||||||
rz1 = 0d;
|
rz1 = 0d;
|
||||||
@@ -111,6 +101,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
|
Debug.trace();
|
||||||
sampleFrequency = sf;
|
sampleFrequency = sf;
|
||||||
lz1 = 0d;
|
lz1 = 0d;
|
||||||
lz2 = 0d;
|
lz2 = 0d;
|
||||||
@@ -120,6 +111,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void calcBiquad() {
|
void calcBiquad() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
double norm;
|
double norm;
|
||||||
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
||||||
@@ -221,6 +213,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
String n = "Biquad Filter (";
|
String n = "Biquad Filter (";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Lowpass: n += "Lowpass"; break;
|
case Lowpass: n += "Lowpass"; break;
|
||||||
@@ -242,14 +235,17 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.nio.file.Files;
|
||||||
import java.awt.*;
|
import java.util.ArrayList;
|
||||||
import java.awt.event.*;
|
import java.util.Enumeration;
|
||||||
import java.util.*;
|
import java.util.UUID;
|
||||||
import java.io.*;
|
import java.util.Properties;
|
||||||
import java.nio.file.*;
|
import javax.sound.sampled.AudioFormat;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.JOptionPane;
|
||||||
import javax.sound.sampled.*;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
@@ -24,7 +25,7 @@ import org.w3c.dom.NodeList;
|
|||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
public class Book extends DefaultMutableTreeNode {
|
public class Book extends BookTreeNode {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
String author;
|
String author;
|
||||||
@@ -39,13 +40,17 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
int channels;
|
int channels;
|
||||||
int resolution;
|
int resolution;
|
||||||
|
|
||||||
|
String notes = null;
|
||||||
|
|
||||||
ImageIcon icon;
|
ImageIcon icon;
|
||||||
|
|
||||||
Properties prefs;
|
Properties prefs;
|
||||||
|
|
||||||
|
File location;
|
||||||
|
|
||||||
public Book(Properties p, String bookname) {
|
public Book(Properties p, String bookname) {
|
||||||
super(bookname);
|
super(bookname);
|
||||||
|
Debug.trace();
|
||||||
prefs = p;
|
prefs = p;
|
||||||
name = bookname;
|
name = bookname;
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||||
@@ -53,12 +58,13 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
|
|
||||||
public Book(Element root) {
|
public Book(Element root) {
|
||||||
super(getTextNode(root, "title"));
|
super(getTextNode(root, "title"));
|
||||||
|
Debug.trace();
|
||||||
name = getTextNode(root, "title");
|
name = getTextNode(root, "title");
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadBookXML(Element root, DefaultTreeModel model) {
|
public void loadBookXML(Element root, DefaultTreeModel model) {
|
||||||
|
Debug.trace();
|
||||||
name = getTextNode(root, "title");
|
name = getTextNode(root, "title");
|
||||||
author = getTextNode(root, "author");
|
author = getTextNode(root, "author");
|
||||||
genre = getTextNode(root, "genre");
|
genre = getTextNode(root, "genre");
|
||||||
@@ -67,6 +73,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
manuscript = getTextNode(root, "manuscript");
|
manuscript = getTextNode(root, "manuscript");
|
||||||
|
|
||||||
AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes"));
|
AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes"));
|
||||||
|
notes = getTextNode(root, "notes");
|
||||||
|
|
||||||
Element settings = getNode(root, "settings");
|
Element settings = getNode(root, "settings");
|
||||||
Element audioSettings = getNode(settings, "audio");
|
Element audioSettings = getNode(settings, "audio");
|
||||||
@@ -92,6 +99,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Element getNode(Element r, String n) {
|
public static Element getNode(Element r, String n) {
|
||||||
|
Debug.trace();
|
||||||
NodeList nl = r.getElementsByTagName(n);
|
NodeList nl = r.getElementsByTagName(n);
|
||||||
if (nl == null) return null;
|
if (nl == null) return null;
|
||||||
if (nl.getLength() == 0) return null;
|
if (nl.getLength() == 0) return null;
|
||||||
@@ -99,35 +107,40 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getTextNode(Element r, String n) {
|
public static String getTextNode(Element r, String n) {
|
||||||
|
Debug.trace();
|
||||||
return getTextNode(r, n, "");
|
return getTextNode(r, n, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTextNode(Element r, String n, String d) {
|
public static String getTextNode(Element r, String n, String d) {
|
||||||
|
Debug.trace();
|
||||||
Element node = getNode(r, n);
|
Element node = getNode(r, n);
|
||||||
if (node == null) return d;
|
if (node == null) return d;
|
||||||
return node.getTextContent();
|
return node.getTextContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthor(String a) { author = a; }
|
public void setAuthor(String a) { Debug.trace(); author = a; }
|
||||||
public void setGenre(String g) { genre = g; }
|
public void setGenre(String g) { Debug.trace(); genre = g; }
|
||||||
public void setComment(String c) { comment = c; }
|
public void setComment(String c) { Debug.trace(); comment = c; }
|
||||||
public void setACX(String c) { ACX = c; }
|
public void setACX(String c) { Debug.trace(); ACX = c; }
|
||||||
|
|
||||||
public String getAuthor() { return author; }
|
public String getAuthor() { Debug.trace(); return author; }
|
||||||
public String getGenre() { return genre; }
|
public String getGenre() { Debug.trace(); return genre; }
|
||||||
public String getComment() { return comment; }
|
public String getComment() { Debug.trace(); return comment; }
|
||||||
public String getACX() { if (ACX == null) return ""; return ACX; }
|
public String getACX() { Debug.trace(); if (ACX == null) return ""; return ACX; }
|
||||||
|
|
||||||
public Chapter getClosingCredits() {
|
public Chapter getClosingCredits() {
|
||||||
|
Debug.trace();
|
||||||
return getChapterById("close");
|
return getChapterById("close");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter getOpeningCredits() {
|
public Chapter getOpeningCredits() {
|
||||||
|
Debug.trace();
|
||||||
return getChapterById("open");
|
return getChapterById("open");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Chapter getChapterById(String id) {
|
public Chapter getChapterById(String id) {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
Object ob = (Object)o.nextElement();
|
Object ob = (Object)o.nextElement();
|
||||||
if (ob instanceof Chapter) {
|
if (ob instanceof Chapter) {
|
||||||
@@ -141,47 +154,39 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Chapter getLastChapter() {
|
public Chapter getLastChapter() {
|
||||||
Chapter cc = getClosingCredits();
|
Debug.trace();
|
||||||
if (cc == null) return null;
|
return (Chapter)getLastLeaf();
|
||||||
Chapter c = (Chapter)getChildBefore(cc);
|
|
||||||
if (c == null) return null;
|
|
||||||
if (c.getId().equals("open")) return null;
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter getChapter(int n) {
|
public Chapter getChapter(int n) {
|
||||||
|
Debug.trace();
|
||||||
if (n == 0) return null;
|
if (n == 0) return null;
|
||||||
return (Chapter)getChildAt(n);
|
return (Chapter)getChildAt(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter addChapter() {
|
public Chapter addChapter() {
|
||||||
Chapter lc = getLastChapter();
|
Debug.trace();
|
||||||
if (lc == null) return new Chapter("1", "Chapter 1");
|
String uuid = UUID.randomUUID().toString();
|
||||||
try {
|
return new Chapter(uuid, uuid);
|
||||||
int lcid = Integer.parseInt(lc.getId());
|
|
||||||
lcid++;
|
|
||||||
|
|
||||||
Chapter nc = new Chapter(String.format("%04d", lcid), "Chapter " + lcid);
|
|
||||||
return nc;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageIcon getIcon() {
|
public ImageIcon getIcon() {
|
||||||
|
Debug.trace();
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(ImageIcon i) {
|
public void setIcon(ImageIcon i) {
|
||||||
|
Debug.trace();
|
||||||
icon = i;
|
icon = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserObject(Object o) {
|
public void setUserObject(Object o) {
|
||||||
|
Debug.trace();
|
||||||
if (o instanceof String) {
|
if (o instanceof String) {
|
||||||
String newName = (String)o;
|
String newName = (String)o;
|
||||||
if (newName.equals(name)) return;
|
if (newName.equals(name)) return;
|
||||||
@@ -190,10 +195,12 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public File getBookPath() {
|
public File getBookPath() {
|
||||||
|
Debug.trace();
|
||||||
return new File(Options.get("path.storage"), name);
|
return new File(Options.get("path.storage"), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renameBook(String newName) {
|
public void renameBook(String newName) {
|
||||||
|
Debug.trace();
|
||||||
File oldDir = getBookPath();
|
File oldDir = getBookPath();
|
||||||
File newDir = new File(Options.get("path.storage"), newName);
|
File newDir = new File(Options.get("path.storage"), newName);
|
||||||
|
|
||||||
@@ -206,7 +213,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
oldDir.renameTo(newDir);
|
oldDir.renameTo(newDir);
|
||||||
name = newName;
|
name = newName;
|
||||||
AudiobookRecorder.window.saveBookStructure();
|
AudiobookRecorder.window.saveBookStructure();
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
reloadTree();
|
||||||
Options.set("path.last-book", name);
|
Options.set("path.last-book", name);
|
||||||
Options.savePreferences();
|
Options.savePreferences();
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||||
@@ -214,11 +221,13 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void renumberChapters() {
|
public void renumberChapters() {
|
||||||
|
Debug.trace();
|
||||||
int id = 1;
|
int id = 1;
|
||||||
|
|
||||||
for (Enumeration c = children(); c.hasMoreElements();) {
|
for (Enumeration c = children(); c.hasMoreElements();) {
|
||||||
@@ -230,41 +239,48 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSampleRate() { return sampleRate; }
|
public int getSampleRate() { Debug.trace(); return sampleRate; }
|
||||||
public void setSampleRate(int sr) { sampleRate = sr; }
|
public void setSampleRate(int sr) { Debug.trace(); sampleRate = sr; }
|
||||||
public int getChannels() { return channels; }
|
public int getChannels() { Debug.trace(); return channels; }
|
||||||
public void setChannels(int c) { channels = c; }
|
public void setChannels(int c) { Debug.trace(); channels = c; }
|
||||||
public int getResolution() { return resolution; }
|
public int getResolution() { Debug.trace(); return resolution; }
|
||||||
public void setResolution(int r) { resolution = r; }
|
public void setResolution(int r) { Debug.trace(); resolution = r; }
|
||||||
|
|
||||||
public AudioFormat getAudioFormat() {
|
public AudioFormat getAudioFormat() {
|
||||||
|
Debug.trace();
|
||||||
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
|
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get(String key) {
|
public String get(String key) {
|
||||||
|
Debug.trace();
|
||||||
if (prefs.getProperty(key) == null) { return Options.get(key); }
|
if (prefs.getProperty(key) == null) { return Options.get(key); }
|
||||||
return prefs.getProperty(key);
|
return prefs.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getInteger(String key) {
|
public Integer getInteger(String key) {
|
||||||
|
Debug.trace();
|
||||||
if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
|
if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
|
||||||
return Utils.s2i(prefs.getProperty(key));
|
return Utils.s2i(prefs.getProperty(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, String value) {
|
public void set(String key, String value) {
|
||||||
|
Debug.trace();
|
||||||
prefs.setProperty(key, value);
|
prefs.setProperty(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, Integer value) {
|
public void set(String key, Integer value) {
|
||||||
|
Debug.trace();
|
||||||
prefs.setProperty(key, "" + value);
|
prefs.setProperty(key, "" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getBookFolder() {
|
public File getBookFolder() {
|
||||||
|
Debug.trace();
|
||||||
File dir = new File(Options.get("path.storage"), name);
|
File dir = new File(Options.get("path.storage"), name);
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUsedEffects() {
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
ArrayList<String> out = new ArrayList<String>();
|
ArrayList<String> out = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -285,6 +301,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void purgeBackups() {
|
public void purgeBackups() {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
Object ob = (Object)o.nextElement();
|
Object ob = (Object)o.nextElement();
|
||||||
if (ob instanceof Chapter) {
|
if (ob instanceof Chapter) {
|
||||||
@@ -295,6 +312,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Document buildDocument() throws ParserConfigurationException {
|
public Document buildDocument() throws ParserConfigurationException {
|
||||||
|
Debug.trace();
|
||||||
DocumentBuilderFactory dbFactory =
|
DocumentBuilderFactory dbFactory =
|
||||||
DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory.newInstance();
|
||||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
@@ -343,6 +361,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Element makeTextNode(Document doc, String name, String text) {
|
public static Element makeTextNode(Document doc, String name, String text) {
|
||||||
|
Debug.trace();
|
||||||
Element node = doc.createElement(name);
|
Element node = doc.createElement(name);
|
||||||
Text tnode = doc.createTextNode(text == null ? "" : text);
|
Text tnode = doc.createTextNode(text == null ? "" : text);
|
||||||
node.appendChild(tnode);
|
node.appendChild(tnode);
|
||||||
@@ -350,6 +369,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Element makeTextNode(Document doc, String name, Integer text) {
|
public static Element makeTextNode(Document doc, String name, Integer text) {
|
||||||
|
Debug.trace();
|
||||||
Element node = doc.createElement(name);
|
Element node = doc.createElement(name);
|
||||||
Text tnode = doc.createTextNode(Integer.toString(text));
|
Text tnode = doc.createTextNode(Integer.toString(text));
|
||||||
node.appendChild(tnode);
|
node.appendChild(tnode);
|
||||||
@@ -357,6 +377,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Element makeTextNode(Document doc, String name, Double text) {
|
public static Element makeTextNode(Document doc, String name, Double text) {
|
||||||
|
Debug.trace();
|
||||||
Element node = doc.createElement(name);
|
Element node = doc.createElement(name);
|
||||||
Text tnode = doc.createTextNode(String.format("%.8f", text));
|
Text tnode = doc.createTextNode(String.format("%.8f", text));
|
||||||
node.appendChild(tnode);
|
node.appendChild(tnode);
|
||||||
@@ -364,6 +385,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Element makeTextNode(Document doc, String name, Boolean text) {
|
public static Element makeTextNode(Document doc, String name, Boolean text) {
|
||||||
|
Debug.trace();
|
||||||
Element node = doc.createElement(name);
|
Element node = doc.createElement(name);
|
||||||
Text tnode = doc.createTextNode(text ? "true" : "false");
|
Text tnode = doc.createTextNode(text ? "true" : "false");
|
||||||
node.appendChild(tnode);
|
node.appendChild(tnode);
|
||||||
@@ -371,14 +393,17 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getDefaultEffect() {
|
public String getDefaultEffect() {
|
||||||
|
Debug.trace();
|
||||||
return defaultEffect;
|
return defaultEffect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultEffect(String eff) {
|
public void setDefaultEffect(String eff) {
|
||||||
|
Debug.trace();
|
||||||
defaultEffect = eff;
|
defaultEffect = eff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setManuscript(File f) {
|
public void setManuscript(File f) {
|
||||||
|
Debug.trace();
|
||||||
manuscript = f.getName();
|
manuscript = f.getName();
|
||||||
File dst = new File(getBookPath(), manuscript);
|
File dst = new File(getBookPath(), manuscript);
|
||||||
|
|
||||||
@@ -390,6 +415,7 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public File getManuscript() {
|
public File getManuscript() {
|
||||||
|
Debug.trace();
|
||||||
if (manuscript == null) return null;
|
if (manuscript == null) return null;
|
||||||
if (manuscript.equals("")) return null;
|
if (manuscript.equals("")) return null;
|
||||||
File f = new File(getBookPath(), manuscript);
|
File f = new File(getBookPath(), manuscript);
|
||||||
@@ -398,4 +424,37 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSelect() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotes(String n) {
|
||||||
|
notes = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(File l) {
|
||||||
|
location = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadTree() {
|
||||||
|
Debug.trace();
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (AudiobookRecorder.window == null) return;
|
||||||
|
if (AudiobookRecorder.window.bookTreeModel == null) return;
|
||||||
|
try {
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.util.regex.Matcher;
|
||||||
import javax.swing.event.*;
|
import java.util.regex.Pattern;
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.util.regex.*;
|
import java.awt.GridBagConstraints;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class BookInfoPanel extends JPanel {
|
public class BookInfoPanel extends JPanel {
|
||||||
|
|
||||||
@@ -16,6 +19,7 @@ public class BookInfoPanel extends JPanel {
|
|||||||
|
|
||||||
public BookInfoPanel(String t, String a, String g, String c, String x) {
|
public BookInfoPanel(String t, String a, String g, String c, String x) {
|
||||||
super();
|
super();
|
||||||
|
Debug.trace();
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
GridBagConstraints con = new GridBagConstraints();
|
GridBagConstraints con = new GridBagConstraints();
|
||||||
|
|
||||||
@@ -69,12 +73,13 @@ public class BookInfoPanel extends JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() { return title.getText(); }
|
public String getTitle() { Debug.trace(); return title.getText(); }
|
||||||
public String getAuthor() { return author.getText(); }
|
public String getAuthor() { Debug.trace(); return author.getText(); }
|
||||||
public String getGenre() { return genre.getText(); }
|
public String getGenre() { Debug.trace(); return genre.getText(); }
|
||||||
public String getComment() { return comment.getText(); }
|
public String getComment() { Debug.trace(); return comment.getText(); }
|
||||||
|
|
||||||
public String getACX() {
|
public String getACX() {
|
||||||
|
Debug.trace();
|
||||||
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
||||||
Matcher m = p.matcher(acx.getText());
|
Matcher m = p.matcher(acx.getText());
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
@@ -84,10 +89,10 @@ public class BookInfoPanel extends JPanel {
|
|||||||
return acx.getText();
|
return acx.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String t) { title.setText(t); }
|
public void setTitle(String t) { Debug.trace(); title.setText(t); }
|
||||||
public void setAuthor(String a) { author.setText(a); }
|
public void setAuthor(String a) { Debug.trace(); author.setText(a); }
|
||||||
public void setGenre(String g) { genre.setText(g); }
|
public void setGenre(String g) { Debug.trace(); genre.setText(g); }
|
||||||
public void setComment(String c) { comment.setText(c); }
|
public void setComment(String c) { Debug.trace(); comment.setText(c); }
|
||||||
public void setACX(String a) { acx.setText(a); }
|
public void setACX(String a) { Debug.trace(); acx.setText(a); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.io.FileInputStream;
|
||||||
import java.awt.*;
|
import java.util.Properties;
|
||||||
import java.awt.event.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.image.*;
|
import java.awt.Color;
|
||||||
import javax.swing.border.*;
|
import java.awt.Dimension;
|
||||||
import java.util.*;
|
import java.awt.Image;
|
||||||
import java.io.*;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
|||||||
@@ -1,9 +1,18 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.Component;
|
||||||
import javax.swing.tree.*;
|
import java.awt.Color;
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import javax.swing.border.*;
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
||||||
|
|
||||||
@@ -77,43 +86,54 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JLabel time = new JLabel(Utils.secToTime(s.getLength(), "mm:ss.SSS") + " ");
|
JLabel time = new JLabelFixedWidth(75, " " + Utils.secToTime(s.getLength(), "ss.SSS") + " ");
|
||||||
|
time.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
|
|
||||||
ctx.gridx = 0;
|
ctx.gridx = 0;
|
||||||
ctx.gridy = 0;
|
ctx.gridy = 0;
|
||||||
|
ctx.weightx = 1.0d;
|
||||||
ctx.fill = GridBagConstraints.HORIZONTAL;
|
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||||
ctx.anchor = GridBagConstraints.LINE_START;
|
ctx.anchor = GridBagConstraints.LINE_START;
|
||||||
|
p.add(ret, ctx);
|
||||||
|
|
||||||
String effectChain = s.getEffectChain();
|
if (s.isProcessing()) {
|
||||||
if ((effectChain == null) || (effectChain.equals("none"))) {
|
JLabel eff = new JLabel();
|
||||||
ctx.weightx = 1.0d;
|
eff.setIcon(Icons.processing);
|
||||||
ctx.gridwidth = 2;
|
ctx.weightx = 0.0d;
|
||||||
p.add(ret, ctx);
|
ctx.gridx = 1;
|
||||||
} else {
|
p.add(eff);
|
||||||
ctx.weightx = 1.0d;
|
} else if (s.isQueued()) {
|
||||||
ctx.gridwidth = 1;
|
JLabel eff = new JLabel();
|
||||||
p.add(ret, ctx);
|
eff.setIcon(Icons.queued);
|
||||||
Effect e = AudiobookRecorder.window.effects.get(effectChain);
|
|
||||||
JLabel eff = new JLabel(e.toString() + " ");
|
|
||||||
ctx.weightx = 0.0d;
|
ctx.weightx = 0.0d;
|
||||||
ctx.gridwidth = 1;
|
|
||||||
ctx.gridx = 1;
|
ctx.gridx = 1;
|
||||||
p.add(eff);
|
p.add(eff);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.gridwidth = 1;
|
String effectChain = s.getEffectChain();
|
||||||
|
if ((effectChain != null) && (!effectChain.equals("none"))) {
|
||||||
|
Effect e = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
|
if (e != null) {
|
||||||
|
JLabel eff = new JLabel(e.toString() + " ");
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 2;
|
||||||
|
p.add(eff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.weightx = 0.0d;
|
ctx.weightx = 0.0d;
|
||||||
ctx.gridx = 2;
|
ctx.gridx = 3;
|
||||||
ctx.anchor = GridBagConstraints.LINE_END;
|
ctx.anchor = GridBagConstraints.LINE_END;
|
||||||
int peak = s.getPeakDB();
|
int peak = s.getPeakDB();
|
||||||
JLabel peakLabel = new JLabel(peak + "dB ");
|
JLabel peakLabel = new JLabelFixedWidth(50, peak + "dB ");
|
||||||
|
peakLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
if (peak > 0) {
|
if (peak > 0) {
|
||||||
peakLabel.setForeground(new Color(0xCC, 0x00, 0x00));
|
peakLabel.setForeground(new Color(0xCC, 0x00, 0x00));
|
||||||
}
|
}
|
||||||
p.add(peakLabel, ctx);
|
p.add(peakLabel, ctx);
|
||||||
|
|
||||||
ctx.weightx = 0.0d;
|
ctx.weightx = 0.0d;
|
||||||
ctx.gridx = 3;
|
ctx.gridx = 4;
|
||||||
ctx.anchor = GridBagConstraints.LINE_END;
|
ctx.anchor = GridBagConstraints.LINE_END;
|
||||||
p.add(time, ctx);
|
p.add(time, ctx);
|
||||||
|
|
||||||
@@ -145,7 +165,33 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
p.setOpaque(false);
|
p.setOpaque(false);
|
||||||
return p;
|
return p;
|
||||||
} else if (value instanceof Book) {
|
} else if (value instanceof Book) {
|
||||||
ret.setIcon(((Book)value).getIcon());
|
Book b = (Book)value;
|
||||||
|
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
p.setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints ctx = new GridBagConstraints();
|
||||||
|
|
||||||
|
ctx.gridx = 0;
|
||||||
|
ctx.gridy = 0;
|
||||||
|
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_START;
|
||||||
|
ctx.weightx = 1.0d;
|
||||||
|
|
||||||
|
ret.setIcon(b.getIcon());
|
||||||
|
p.add(ret, ctx);
|
||||||
|
|
||||||
|
JLabel author = new JLabel(b.getAuthor());
|
||||||
|
ctx.gridy++;
|
||||||
|
author.setBorder(new EmptyBorder(0, 27, 0, 0));
|
||||||
|
Font f = author.getFont();
|
||||||
|
Font nf = f.deriveFont(Font.ITALIC, (int)(f.getSize() * 0.75));
|
||||||
|
author.setFont(nf);
|
||||||
|
author.setForeground(author.getForeground().darker());
|
||||||
|
p.add(author, ctx);
|
||||||
|
|
||||||
|
p.setOpaque(false);
|
||||||
|
return p;
|
||||||
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class CacheManager {
|
public class CacheManager {
|
||||||
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
||||||
|
|||||||
@@ -1,16 +1,33 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.io.FileInputStream;
|
||||||
import java.awt.*;
|
import java.io.FileOutputStream;
|
||||||
import java.awt.event.*;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.*;
|
import java.io.IOException;
|
||||||
import java.io.*;
|
import java.util.ArrayList;
|
||||||
import java.nio.file.*;
|
import java.util.Enumeration;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import it.sauronsoftware.jave.*;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import com.mpatric.mp3agic.*;
|
|
||||||
import javax.sound.sampled.*;
|
import it.sauronsoftware.jave.FFMPEGLocator;
|
||||||
|
import it.sauronsoftware.jave.AudioAttributes;
|
||||||
|
import it.sauronsoftware.jave.EncodingAttributes;
|
||||||
|
import it.sauronsoftware.jave.Encoder;
|
||||||
|
import it.sauronsoftware.jave.EncoderException;
|
||||||
|
import it.sauronsoftware.jave.InputFormatException;
|
||||||
|
|
||||||
|
import com.mpatric.mp3agic.Mp3File;
|
||||||
|
import com.mpatric.mp3agic.ID3v2;
|
||||||
|
import com.mpatric.mp3agic.ID3v24Tag;
|
||||||
|
import com.mpatric.mp3agic.InvalidDataException;
|
||||||
|
import com.mpatric.mp3agic.NotSupportedException;
|
||||||
|
import com.mpatric.mp3agic.UnsupportedTagException;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
@@ -38,7 +55,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
|
|
||||||
public Chapter(String i, String chaptername) {
|
public Chapter(String i, String chaptername) {
|
||||||
super(chaptername);
|
super(chaptername);
|
||||||
|
Debug.trace();
|
||||||
id = i;
|
id = i;
|
||||||
name = chaptername;
|
name = chaptername;
|
||||||
preGap = Options.getInteger("catenation.pre-chapter");
|
preGap = Options.getInteger("catenation.pre-chapter");
|
||||||
@@ -46,7 +63,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Chapter(Element root, DefaultTreeModel model) {
|
public Chapter(Element root, DefaultTreeModel model) {
|
||||||
|
Debug.trace();
|
||||||
name = Book.getTextNode(root, "name");
|
name = Book.getTextNode(root, "name");
|
||||||
id = root.getAttribute("id");
|
id = root.getAttribute("id");
|
||||||
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
|
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
|
||||||
@@ -65,24 +82,29 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
Debug.trace();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String i) {
|
public void setId(String i) {
|
||||||
|
Debug.trace();
|
||||||
id = i;
|
id = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sentence getLastSentence() {
|
public Sentence getLastSentence() {
|
||||||
|
Debug.trace();
|
||||||
DefaultMutableTreeNode ls = getLastLeaf();
|
DefaultMutableTreeNode ls = getLastLeaf();
|
||||||
if (ls instanceof Sentence) return (Sentence)ls;
|
if (ls instanceof Sentence) return (Sentence)ls;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserObject(Object o) {
|
public void setUserObject(Object o) {
|
||||||
|
Debug.trace();
|
||||||
if (o instanceof String) {
|
if (o instanceof String) {
|
||||||
String so = (String)o;
|
String so = (String)o;
|
||||||
name = so;
|
name = so;
|
||||||
@@ -90,26 +112,32 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String n) {
|
public void setName(String n) {
|
||||||
|
Debug.trace();
|
||||||
name = n;
|
name = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreGap(int g) {
|
public void setPreGap(int g) {
|
||||||
|
Debug.trace();
|
||||||
preGap = g;
|
preGap = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreGap() {
|
public int getPreGap() {
|
||||||
|
Debug.trace();
|
||||||
return preGap;
|
return preGap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPostGap(int g) {
|
public void setPostGap(int g) {
|
||||||
|
Debug.trace();
|
||||||
postGap = g;
|
postGap = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPostGap() {
|
public int getPostGap() {
|
||||||
|
Debug.trace();
|
||||||
return postGap;
|
return postGap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +145,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
public void exportChapter(ProgressDialog exportDialog) throws
|
public void exportChapter(ProgressDialog exportDialog) throws
|
||||||
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
||||||
EncoderException, UnsupportedTagException, InvalidDataException {
|
EncoderException, UnsupportedTagException, InvalidDataException {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
if (getChildCount() == 0) return;
|
if (getChildCount() == 0) return;
|
||||||
|
|
||||||
@@ -235,6 +264,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getChapterLength() {
|
public double getChapterLength() {
|
||||||
|
Debug.trace();
|
||||||
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
||||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||||
Sentence sentence = (Sentence)s.nextElement();
|
Sentence sentence = (Sentence)s.nextElement();
|
||||||
@@ -249,6 +279,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUsedEffects() {
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
ArrayList<String> out = new ArrayList<String>();
|
ArrayList<String> out = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -266,6 +297,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void resetPostGaps() {
|
public void resetPostGaps() {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
snt.resetPostGap();
|
snt.resetPostGap();
|
||||||
@@ -273,6 +305,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void purgeBackups() {
|
public void purgeBackups() {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
Object ob = (Object)o.nextElement();
|
Object ob = (Object)o.nextElement();
|
||||||
if (ob instanceof Sentence) {
|
if (ob instanceof Sentence) {
|
||||||
@@ -283,6 +316,7 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Element getChapterXML(Document doc) {
|
public Element getChapterXML(Document doc) {
|
||||||
|
Debug.trace();
|
||||||
Element chapterNode = doc.createElement("chapter");
|
Element chapterNode = doc.createElement("chapter");
|
||||||
chapterNode.setAttribute("id", id);
|
chapterNode.setAttribute("id", id);
|
||||||
chapterNode.appendChild(Book.makeTextNode(doc, "name", name));
|
chapterNode.appendChild(Book.makeTextNode(doc, "name", name));
|
||||||
@@ -305,18 +339,22 @@ public class Chapter extends BookTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getNotes() {
|
public String getNotes() {
|
||||||
|
Debug.trace();
|
||||||
return notes;
|
return notes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNotes(String t) {
|
public void setNotes(String t) {
|
||||||
|
Debug.trace();
|
||||||
notes = t;
|
notes = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSelect() {
|
public void onSelect() {
|
||||||
|
Debug.trace();
|
||||||
AudiobookRecorder.window.setChapterNotes(notes);
|
AudiobookRecorder.window.setChapterNotes(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getLength() {
|
public double getLength() {
|
||||||
|
Debug.trace();
|
||||||
double len = 0;
|
double len = 0;
|
||||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
Object ob = (Object)o.nextElement();
|
Object ob = (Object)o.nextElement();
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.plaf.*;
|
import javax.swing.tree.AbstractLayoutCache;
|
||||||
import javax.swing.plaf.basic.*;
|
import javax.swing.tree.TreePath;
|
||||||
import java.awt.*;
|
import javax.swing.plaf.basic.BasicTreeUI;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
public class CustomTreeUI extends BasicTreeUI {
|
public class CustomTreeUI extends BasicTreeUI {
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JButton;
|
||||||
import java.awt.*;
|
import javax.swing.JPanel;
|
||||||
import java.awt.event.*;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.border.*;
|
import javax.swing.JTextArea;
|
||||||
import java.net.*;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class DonationPanel extends JPanel {
|
public class DonationPanel extends JPanel {
|
||||||
public DonationPanel() {
|
public DonationPanel() {
|
||||||
|
|||||||
@@ -1,130 +1,93 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Orlando Selenu
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FFT {
|
public class FFT {
|
||||||
/**
|
public static double[] fft(final double[] inputReal, double[] inputImag, boolean DIRECT) {
|
||||||
* The Fast Fourier Transform (generic version, with NO optimizations).
|
int n = inputReal.length;
|
||||||
*
|
|
||||||
* @param inputReal
|
|
||||||
* an array of length n, the real part
|
|
||||||
* @param inputImag
|
|
||||||
* an array of length n, the imaginary part
|
|
||||||
* @param DIRECT
|
|
||||||
* TRUE = direct transform, FALSE = inverse transform
|
|
||||||
* @return a new array of length 2n
|
|
||||||
*/
|
|
||||||
public static double[] fft(final double[] inputReal, double[] inputImag,
|
|
||||||
boolean DIRECT) {
|
|
||||||
// - n is the dimension of the problem
|
|
||||||
// - nu is its logarithm in base e
|
|
||||||
int n = inputReal.length;
|
|
||||||
|
|
||||||
// If n is a power of 2, then ld is an integer (_without_ decimals)
|
double ld = Math.log(n) / Math.log(2.0);
|
||||||
double ld = Math.log(n) / Math.log(2.0);
|
|
||||||
|
|
||||||
// Here I check if n is a power of 2. If exist decimals in ld, I quit
|
if (((int) ld) - ld != 0) {
|
||||||
// from the function returning null.
|
System.out.println("The number of elements is not a power of 2.");
|
||||||
if (((int) ld) - ld != 0) {
|
return null;
|
||||||
System.out.println("The number of elements is not a power of 2.");
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Declaration and initialization of the variables
|
int nu = (int) ld;
|
||||||
// ld should be an integer, actually, so I don't lose any information in
|
int n2 = n / 2;
|
||||||
// the cast
|
int nu1 = nu - 1;
|
||||||
int nu = (int) ld;
|
double[] xReal = new double[n];
|
||||||
int n2 = n / 2;
|
double[] xImag = new double[n];
|
||||||
int nu1 = nu - 1;
|
double tReal, tImag, p, arg, c, s;
|
||||||
double[] xReal = new double[n];
|
|
||||||
double[] xImag = new double[n];
|
double constant;
|
||||||
double tReal, tImag, p, arg, c, s;
|
if (DIRECT) {
|
||||||
|
constant = -2 * Math.PI;
|
||||||
|
} else {
|
||||||
|
constant = 2 * Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
// Here I check if I'm going to do the direct transform or the inverse
|
for (int i = 0; i < n; i++) {
|
||||||
// transform.
|
xReal[i] = inputReal[i];
|
||||||
double constant;
|
xImag[i] = inputImag[i];
|
||||||
if (DIRECT)
|
}
|
||||||
constant = -2 * Math.PI;
|
|
||||||
else
|
|
||||||
constant = 2 * Math.PI;
|
|
||||||
|
|
||||||
// I don't want to overwrite the input arrays, so here I copy them. This
|
int k = 0;
|
||||||
// choice adds \Theta(2n) to the complexity.
|
for (int l = 1; l <= nu; l++) {
|
||||||
for (int i = 0; i < n; i++) {
|
while (k < n) {
|
||||||
xReal[i] = inputReal[i];
|
for (int i = 1; i <= n2; i++) {
|
||||||
xImag[i] = inputImag[i];
|
p = bitreverseReference(k >> nu1, nu);
|
||||||
}
|
// direct FFT or inverse FFT
|
||||||
|
arg = constant * p / n;
|
||||||
// First phase - calculation
|
c = Math.cos(arg);
|
||||||
int k = 0;
|
s = Math.sin(arg);
|
||||||
for (int l = 1; l <= nu; l++) {
|
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||||
while (k < n) {
|
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||||
for (int i = 1; i <= n2; i++) {
|
xReal[k + n2] = xReal[k] - tReal;
|
||||||
p = bitreverseReference(k >> nu1, nu);
|
xImag[k + n2] = xImag[k] - tImag;
|
||||||
// direct FFT or inverse FFT
|
xReal[k] += tReal;
|
||||||
arg = constant * p / n;
|
xImag[k] += tImag;
|
||||||
c = Math.cos(arg);
|
k++;
|
||||||
s = Math.sin(arg);
|
}
|
||||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
k += n2;
|
||||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
|
||||||
xReal[k + n2] = xReal[k] - tReal;
|
|
||||||
xImag[k + n2] = xImag[k] - tImag;
|
|
||||||
xReal[k] += tReal;
|
|
||||||
xImag[k] += tImag;
|
|
||||||
k++;
|
|
||||||
}
|
}
|
||||||
k += n2;
|
k = 0;
|
||||||
|
nu1--;
|
||||||
|
n2 /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
nu1--;
|
int r;
|
||||||
n2 /= 2;
|
while (k < n) {
|
||||||
}
|
r = bitreverseReference(k, nu);
|
||||||
|
if (r > k) {
|
||||||
// Second phase - recombination
|
tReal = xReal[k];
|
||||||
k = 0;
|
tImag = xImag[k];
|
||||||
int r;
|
xReal[k] = xReal[r];
|
||||||
while (k < n) {
|
xImag[k] = xImag[r];
|
||||||
r = bitreverseReference(k, nu);
|
xReal[r] = tReal;
|
||||||
if (r > k) {
|
xImag[r] = tImag;
|
||||||
tReal = xReal[k];
|
}
|
||||||
tImag = xImag[k];
|
k++;
|
||||||
xReal[k] = xReal[r];
|
|
||||||
xImag[k] = xImag[r];
|
|
||||||
xReal[r] = tReal;
|
|
||||||
xImag[r] = tImag;
|
|
||||||
}
|
}
|
||||||
k++;
|
|
||||||
|
double[] newArray = new double[xReal.length * 2];
|
||||||
|
double radice = 1 / Math.sqrt(n);
|
||||||
|
for (int i = 0; i < newArray.length; i += 2) {
|
||||||
|
int i2 = i / 2;
|
||||||
|
newArray[i] = xReal[i2] * radice;
|
||||||
|
newArray[i + 1] = xImag[i2] * radice;
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here I have to mix xReal and xImag to have an array (yes, it should
|
private static int bitreverseReference(int j, int nu) {
|
||||||
// be possible to do this stuff in the earlier parts of the code, but
|
int j2;
|
||||||
// it's here to readibility).
|
int j1 = j;
|
||||||
double[] newArray = new double[xReal.length * 2];
|
int k = 0;
|
||||||
double radice = 1 / Math.sqrt(n);
|
for (int i = 1; i <= nu; i++) {
|
||||||
for (int i = 0; i < newArray.length; i += 2) {
|
j2 = j1 / 2;
|
||||||
int i2 = i / 2;
|
k = 2 * k + j1 - 2 * j2;
|
||||||
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
j1 = j2;
|
||||||
// to normalize the output while I'm copying the elements.
|
}
|
||||||
newArray[i] = xReal[i2] * radice;
|
return k;
|
||||||
newArray[i + 1] = xImag[i2] * radice;
|
|
||||||
}
|
}
|
||||||
return newArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The reference bitreverse function.
|
|
||||||
*/
|
|
||||||
private static int bitreverseReference(int j, int nu) {
|
|
||||||
int j2;
|
|
||||||
int j1 = j;
|
|
||||||
int k = 0;
|
|
||||||
for (int i = 1; i <= nu; i++) {
|
|
||||||
j2 = j1 / 2;
|
|
||||||
k = 2 * k + j1 - 2 * j2;
|
|
||||||
j1 = j2;
|
|
||||||
}
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.util.TimerTask;
|
||||||
import java.awt.*;
|
import java.util.Timer;
|
||||||
import java.util.*;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
public class FlashPanel extends JPanel {
|
public class FlashPanel extends JPanel {
|
||||||
|
|
||||||
boolean flash = false;
|
boolean flash = false;
|
||||||
boolean col = false;
|
boolean col = false;
|
||||||
|
|
||||||
java.util.Timer ticker;
|
Timer ticker;
|
||||||
|
|
||||||
public FlashPanel() {
|
public FlashPanel() {
|
||||||
super();
|
super();
|
||||||
ticker = new java.util.Timer(true);
|
ticker = new Timer(true);
|
||||||
ticker.scheduleAtFixedRate(new TimerTask() {
|
ticker.scheduleAtFixedRate(new TimerTask() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (flash) {
|
if (flash) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Icons {
|
public class Icons {
|
||||||
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
||||||
@@ -39,4 +39,8 @@ public class Icons {
|
|||||||
static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png"));
|
static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png"));
|
||||||
static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png"));
|
static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png"));
|
||||||
static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png"));
|
static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png"));
|
||||||
|
static public final ImageIcon tooltip = new ImageIcon(Icons.class.getResource("icons/tooltip.png"));
|
||||||
|
static public final ImageIcon queued = new ImageIcon(Icons.class.getResource("icons/queued.png"));
|
||||||
|
static public final ImageIcon processing = new ImageIcon(Icons.class.getResource("icons/processing.png"));
|
||||||
|
static public final ImageIcon close = new ImageIcon(Icons.class.getResource("icons/close.png"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JButton;
|
||||||
import javax.swing.event.*;
|
import javax.swing.ImageIcon;
|
||||||
import java.awt.*;
|
import javax.swing.JComponent;
|
||||||
import java.awt.event.*;
|
import javax.swing.KeyStroke;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class JButtonSpacePlay extends JButton {
|
public class JButtonSpacePlay extends JButton {
|
||||||
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
|||||||
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal file
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
|
public class JLabelFixedWidth extends JLabel {
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
Dimension size;
|
||||||
|
public JLabelFixedWidth(int w, String txt) {
|
||||||
|
super(txt);
|
||||||
|
JLabel t = new JLabel(txt);
|
||||||
|
size = t.getPreferredSize();
|
||||||
|
size.width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JLabelFixedWidth(int w) {
|
||||||
|
super();
|
||||||
|
JLabel t = new JLabel("nothing");
|
||||||
|
size = t.getPreferredSize();
|
||||||
|
size.width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JSlider;
|
||||||
|
|
||||||
public class JSliderOb extends JSlider {
|
public class JSliderOb extends JSlider {
|
||||||
Object object;
|
Object object;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
import javax.swing.*;
|
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
public class JTextFieldOb extends JTextField {
|
public class JTextFieldOb extends JTextField {
|
||||||
Object object;
|
Object object;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.event.*;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.*;
|
import javax.swing.JToggleButton;
|
||||||
import java.awt.event.*;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class JToggleButtonSpacePlay extends JToggleButton {
|
public class JToggleButtonSpacePlay extends JToggleButton {
|
||||||
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ public class KVPair<K,V> implements Comparable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
// if (o instanceof KVPair) {
|
|
||||||
// KVPair ko = (KVPair)o;
|
|
||||||
// return key.compareTo(ko.key);
|
|
||||||
// }
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionEvent;
|
||||||
import javax.swing.event.*;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
import java.awt.event.*;
|
import javax.swing.JToggleButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
public class MainToolBar extends JToolBar {
|
public class MainToolBar extends JToolBar {
|
||||||
|
|
||||||
@@ -16,7 +19,6 @@ public class MainToolBar extends JToolBar {
|
|||||||
JButtonSpacePlay playonSentence;
|
JButtonSpacePlay playonSentence;
|
||||||
JButtonSpacePlay playtoSentence;
|
JButtonSpacePlay playtoSentence;
|
||||||
JButtonSpacePlay stopPlaying;
|
JButtonSpacePlay stopPlaying;
|
||||||
JButtonSpacePlay eq;
|
|
||||||
JButtonSpacePlay openManuscript;
|
JButtonSpacePlay openManuscript;
|
||||||
JToggleButtonSpacePlay mic;
|
JToggleButtonSpacePlay mic;
|
||||||
|
|
||||||
@@ -99,16 +101,6 @@ public class MainToolBar extends JToolBar {
|
|||||||
});
|
});
|
||||||
add(stopPlaying);
|
add(stopPlaying);
|
||||||
|
|
||||||
addSeparator();
|
|
||||||
eq = new JButtonSpacePlay(Icons.eq, "Reload Effects", new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
root.loadEffects();
|
|
||||||
CacheManager.purgeCache();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
add(eq);
|
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
public class MarkerDragEvent {
|
public class MarkerDragEvent {
|
||||||
|
|
||||||
Object src;
|
Object src;
|
||||||
|
|||||||
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class NoiseFloor extends JPanel {
|
||||||
|
|
||||||
|
int noiseFloor = 0;
|
||||||
|
|
||||||
|
public NoiseFloor() {
|
||||||
|
super();
|
||||||
|
noiseFloor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNoiseFloor(int n) {
|
||||||
|
noiseFloor = n;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(128, 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Rectangle size = g.getClipBounds();
|
||||||
|
g.setColor(getBackground());
|
||||||
|
g.fillRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.drawRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setFont(getFont());
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
g.drawString("Noise Floor: " + noiseFloor + "dB", 6, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.table.*;
|
import javax.swing.table.TableCellRenderer;
|
||||||
import javax.swing.event.*;
|
import javax.swing.JTable;
|
||||||
import java.awt.*;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import java.awt.event.*;
|
import java.util.ArrayList;
|
||||||
import java.io.*;
|
import javax.swing.JScrollPane;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class OpenBookPanel extends JPanel {
|
public class OpenBookPanel extends JPanel {
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,42 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import java.io.File;
|
||||||
import javax.swing.*;
|
import java.util.TreeSet;
|
||||||
import javax.swing.event.*;
|
import java.util.ArrayList;
|
||||||
import java.awt.*;
|
import java.util.HashMap;
|
||||||
import java.awt.event.*;
|
import java.util.prefs.Preferences;
|
||||||
import java.util.*;
|
import java.awt.GridBagConstraints;
|
||||||
import java.util.prefs.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.io.*;
|
import java.awt.BorderLayout;
|
||||||
import javax.swing.tree.*;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Dialog;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.sound.sampled.DataLine;
|
||||||
|
import javax.sound.sampled.TargetDataLine;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.SourceDataLine;
|
||||||
|
|
||||||
public class Options extends JDialog {
|
public class Options extends JDialog {
|
||||||
|
|
||||||
@@ -16,8 +44,6 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
GridBagConstraints constraint;
|
GridBagConstraints constraint;
|
||||||
|
|
||||||
public static ArrayList<EffectGroup> effectChains;
|
|
||||||
|
|
||||||
JComboBox<KVPair> mixerList;
|
JComboBox<KVPair> mixerList;
|
||||||
JComboBox<KVPair> playbackList;
|
JComboBox<KVPair> playbackList;
|
||||||
JComboBox<KVPair> channelList;
|
JComboBox<KVPair> channelList;
|
||||||
@@ -50,6 +76,9 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
JTextField externalEditor;
|
JTextField externalEditor;
|
||||||
|
|
||||||
|
JTextField speechCommand;
|
||||||
|
JSpinner workerThreads;
|
||||||
|
|
||||||
JTextArea startupScript;
|
JTextArea startupScript;
|
||||||
|
|
||||||
ArrayList<JTextField[]> processorList;
|
ArrayList<JTextField[]> processorList;
|
||||||
@@ -69,7 +98,7 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def) {
|
JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -80,6 +109,9 @@ public class Options extends JDialog {
|
|||||||
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
||||||
constraint.gridx = 1;
|
constraint.gridx = 1;
|
||||||
panel.add(o, constraint);
|
panel.add(o, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
for (KVPair p : options) {
|
for (KVPair p : options) {
|
||||||
if (p.key.equals(def)) {
|
if (p.key.equals(def)) {
|
||||||
@@ -110,7 +142,7 @@ public class Options extends JDialog {
|
|||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField addTextField(JPanel panel, String label, String def) {
|
JTextField addTextField(JPanel panel, String label, String def, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -124,13 +156,18 @@ public class Options extends JDialog {
|
|||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(a, constraint);
|
panel.add(a, constraint);
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField[] addTwoField(JPanel panel, String def1, String def2) {
|
JTextField[] addTwoField(JPanel panel, String def1, String def2, String tip) {
|
||||||
JTextField a = new JTextField(def1);
|
JTextField a = new JTextField(def1);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
@@ -141,13 +178,18 @@ public class Options extends JDialog {
|
|||||||
panel.add(b, constraint);
|
panel.add(b, constraint);
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return new JTextField[] { a, b };
|
return new JTextField[] { a, b };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JTextField addFilePath(JPanel panel, String label, String path, boolean dironly) {
|
JTextField addFilePath(JPanel panel, String label, String path, boolean dironly, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -209,6 +251,10 @@ public class Options extends JDialog {
|
|||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(p, constraint);
|
panel.add(p, constraint);
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
@@ -235,7 +281,7 @@ public class Options extends JDialog {
|
|||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix) {
|
JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -255,6 +301,10 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(p, constraint);
|
panel.add(p, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
@@ -263,11 +313,16 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JCheckBox addCheckBox(JPanel panel, String label, boolean state) {
|
JCheckBox addCheckBox(JPanel panel, String label, boolean state, String tip) {
|
||||||
constraint.gridx = 1;
|
constraint.gridx = 1;
|
||||||
JCheckBox cb = new JCheckBox(label);
|
JCheckBox cb = new JCheckBox(label);
|
||||||
cb.setSelected(state);
|
cb.setSelected(state);
|
||||||
panel.add(cb, constraint);
|
panel.add(cb, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
@@ -295,93 +350,71 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"));
|
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"), "This is the system device to record through");
|
||||||
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"));
|
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"), "How many channels do you want to record - stereo or mono?");
|
||||||
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"), "The higher the sample rate the better the quality, but the bigger the files.");
|
||||||
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"), "The higher the resolution the better the quality, but the bigger the files.");
|
||||||
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"), "None: don't auto-trim. FFT: Compare the FFT profile of blocks to the room noise profile and trim silent blocks, Peak: Look for the start and end rise and fall points");
|
||||||
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "");
|
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "", "This specifies the difference (in hundredths) between the power of FFT buckets in a sample block compared to the overall power of the same FFT bucket in the room noise. Raising this number makes the FFT trimming less sensitive.");
|
||||||
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"));
|
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"), "How large an FFT block should be when processing. Larger values increase sensitivity but at the epxense of resolution.");
|
||||||
maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), "");
|
maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), "", "This is how much the gain is allowed to vary by from phrase to phrase when normalizing an entire chapter.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"));
|
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"), "Which device to play back through");
|
||||||
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"));
|
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"), "How big the playback buffer should be. Larger is smoother playback but the playback marker in the waveform becomes more out of sync");
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true);
|
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true, "This is where all your working audiobooks are stored.");
|
||||||
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true);
|
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true, "This is where audiobooks are archived to.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms");
|
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms", "How much room noise to add at the beginning of a chapter.");
|
||||||
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms");
|
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms", "How much room noise to add to the end of a chapter.");
|
||||||
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms", "How much room noise to add between normal sentences.");
|
||||||
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms", "How much room noise to add between 'continuations'.");
|
||||||
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
|
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms", "How much room noise to add between paragraphs.");
|
||||||
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms");
|
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms", "How much room noise to add between sections.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false);
|
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false, "Path to your ffmpeg executable.");
|
||||||
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"));
|
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"), "The MP3 bitrate to produce");
|
||||||
channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels"));
|
channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels"), "Mono or stereo MP3 production");
|
||||||
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"));
|
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"), "Sample frequency of the produced MP3");
|
||||||
|
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
|
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text (**SLOW**)", getBoolean("process.sphinx"), "This will automatically start recognising the speech in every sentence you record. This can really slow down recording though so it's recommended to leave it turned off and do your recognition afterwards as a batch operation.");
|
||||||
|
speechCommand = addTextField(optionsPanel, "Speech to text command (must take 1 filename parameter):", get("process.command"), "This specifies what command to run to recognize the speech. This command must take only one parameter, which is the full path of the WAV file. It should return (on standard output) the recognised speech.");
|
||||||
|
workerThreads = addSpinner(optionsPanel, "Worker threads:", 1, 100, 1, getInteger("process.threads"), "", "How many concurrent threads to run when processing speech. This should ideally be no more than the number of CPU cores you have in your computer minus one.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"));
|
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"), "The program to run when you select 'Open in external editor'.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "");
|
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "", "How many phrases to keep cached in memory at once. More gives a smoother editing experience, but you can easily run out of memory if you are not careful.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||||
|
|
||||||
JPanel effectChains = new JPanel();
|
|
||||||
effectChains.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JPanel effectDetails = new JPanel() {
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
return new Dimension(200, 400);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DefaultTreeModel m = new DefaultTreeModel(new DefaultMutableTreeNode("Effect Chains"));
|
|
||||||
|
|
||||||
JTree effectChainTree = new JTree(m);
|
|
||||||
effectChains.add(effectChainTree, BorderLayout.CENTER);
|
|
||||||
effectChains.add(effectDetails, BorderLayout.EAST);
|
|
||||||
|
|
||||||
tabs.add("Effects Chains", new JScrollPane(effectChains));
|
|
||||||
|
|
||||||
JPanel startScript = new JPanel();
|
JPanel startScript = new JPanel();
|
||||||
startScript.setLayout(new BorderLayout());
|
startScript.setLayout(new BorderLayout());
|
||||||
|
startScript.setBorder(new EmptyBorder(15, 15, 15, 15));
|
||||||
startupScript = new JTextArea(get("scripts.startup"));
|
startupScript = new JTextArea(get("scripts.startup"));
|
||||||
|
startupScript.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
startupScript.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
|
||||||
startScript.add(startupScript, BorderLayout.CENTER);
|
startScript.add(startupScript, BorderLayout.CENTER);
|
||||||
tabs.add("Startup Script", startScript);
|
tabs.add("Startup Script", startScript);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JPanel effects = new JPanel();
|
|
||||||
effects.setLayout(new GridBagLayout());
|
|
||||||
constraint.gridx = 0;
|
|
||||||
constraint.gridy = 0;
|
|
||||||
constraint.gridwidth = 1;
|
|
||||||
constraint.gridheight = 1;
|
|
||||||
|
|
||||||
etherealOffset = addSpinner(effects, "Ethereal Voice Offset", 0, 2000, 10, getInteger("effects.ethereal.offset"), "ms");
|
|
||||||
etherealIterations = addSpinner(effects, "Ethereal Voice Iterations", 1, 10, 1, getInteger("effects.ethereal.iterations"), "");
|
|
||||||
etherealAttenuation = addSpinner(effects, "Ethereal Voice Attenuation", 0, 100, 1, getInteger("effects.ethereal.attenuation"), "%");
|
|
||||||
|
|
||||||
tabs.add("Effects", effects);
|
|
||||||
|
|
||||||
|
|
||||||
JPanel processors = new JPanel();
|
JPanel processors = new JPanel();
|
||||||
processors.setLayout(new BorderLayout());
|
processors.setLayout(new BorderLayout());
|
||||||
@@ -406,19 +439,16 @@ public class Options extends JDialog {
|
|||||||
String command = get("editor.processor." + i + ".command");
|
String command = get("editor.processor." + i + ".command");
|
||||||
if (name == null || command == null) break;
|
if (name == null || command == null) break;
|
||||||
if (name.equals("") || command.equals("")) break;
|
if (name.equals("") || command.equals("")) break;
|
||||||
JTextField[] f = addTwoField(processorListPanel, name, command);
|
JTextField[] f = addTwoField(processorListPanel, name, command, "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
|
||||||
processorList.add(f);
|
processorList.add(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField[] f = addTwoField(processorListPanel, "", "");
|
JTextField[] f = addTwoField(processorListPanel, "", "", "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
|
||||||
processorList.add(f);
|
processorList.add(f);
|
||||||
|
|
||||||
tabs.add("Processors", processors);
|
tabs.add("Processors", processors);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add(tabs, BorderLayout.CENTER);
|
add(tabs, BorderLayout.CENTER);
|
||||||
|
|
||||||
setTitle("Options");
|
setTitle("Options");
|
||||||
@@ -594,6 +624,8 @@ public class Options extends JDialog {
|
|||||||
defaultPrefs.put("audio.export.channels", "2");
|
defaultPrefs.put("audio.export.channels", "2");
|
||||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||||
defaultPrefs.put("process.sphinx", "false");
|
defaultPrefs.put("process.sphinx", "false");
|
||||||
|
defaultPrefs.put("process.command", "speech-to-text \"%f\"");
|
||||||
|
defaultPrefs.put("process.threads", "10");
|
||||||
|
|
||||||
defaultPrefs.put("editor.external", "");
|
defaultPrefs.put("editor.external", "");
|
||||||
|
|
||||||
@@ -601,10 +633,6 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
defaultPrefs.put("scripts.startup", "");
|
defaultPrefs.put("scripts.startup", "");
|
||||||
|
|
||||||
defaultPrefs.put("effects.ethereal.offset", "50");
|
|
||||||
defaultPrefs.put("effects.ethereal.iterations", "3");
|
|
||||||
defaultPrefs.put("effects.ethereal.attenuation", "50");
|
|
||||||
|
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
||||||
}
|
}
|
||||||
@@ -718,6 +746,8 @@ public class Options extends JDialog {
|
|||||||
set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key);
|
set("audio.export.channels", ((KVPair)channels.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.sphinx", enableParsing.isSelected());
|
||||||
|
set("process.command", speechCommand.getText());
|
||||||
|
set("process.threads", workerThreads.getValue());
|
||||||
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());
|
||||||
@@ -725,10 +755,6 @@ public class Options extends JDialog {
|
|||||||
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
|
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
|
||||||
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
|
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
|
||||||
|
|
||||||
set("effects.ethereal.offset", etherealOffset.getValue());
|
|
||||||
set("effects.ethereal.iterations", etherealIterations.getValue());
|
|
||||||
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
|
|
||||||
|
|
||||||
set("scripts.startup", startupScript.getText());
|
set("scripts.startup", startupScript.getText());
|
||||||
|
|
||||||
int procNo = 0;
|
int procNo = 0;
|
||||||
@@ -823,51 +849,4 @@ public class Options extends JDialog {
|
|||||||
pairs[7] = new KVPair<String, String>("131072", "131072");
|
pairs[7] = new KVPair<String, String>("131072", "131072");
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createEffectChains() {
|
|
||||||
effectChains = new ArrayList<EffectGroup>();
|
|
||||||
|
|
||||||
for (int i = 0; i < 999999; i++) {
|
|
||||||
if (get("effects." + i + ".name") == null) {
|
|
||||||
EffectGroup e = new EffectGroup(get("effects." + i + ".name"));
|
|
||||||
for (int j = 0; i < 999999; j++) {
|
|
||||||
String type = get("effects." + i + ".children." + j + ".type");
|
|
||||||
if (type == null) break;
|
|
||||||
|
|
||||||
if (type.equals("biquad")) {
|
|
||||||
int bqt = getInteger("effects." + i + ".children." + j + ".filtertype");
|
|
||||||
double fc = getDouble("effects." + i + ".children." + j + ".fc");
|
|
||||||
double q = getDouble("effects." + i + ".children." + j + ".q");
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
|
||||||
Biquad b = new Biquad(bqt, fc, q, gain);
|
|
||||||
e.addEffect(b);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("amplifier")) {
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
|
||||||
Amplifier a = new Amplifier(gain);
|
|
||||||
e.addEffect(a);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("delayline")) {
|
|
||||||
DelayLine l = new DelayLine();
|
|
||||||
for (int c = 0; c < 999999; c++) {
|
|
||||||
if (get("effects." + i + ".children." + j + ".lines." + c + ".samples") == null) break;
|
|
||||||
int samples = getInteger("effects." + i + ".children." + j + ".lines." + c + ".samples");
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".lines." + c + ".gain");
|
|
||||||
l.addDelayLine(samples, gain);
|
|
||||||
}
|
|
||||||
e.addEffect(l);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
effectChains.add(e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, Majenko Technologies
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer in the documentation and/or
|
|
||||||
* other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of Majenko Technologies nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Overlays {
|
public class Overlays {
|
||||||
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.event.*;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.border.*;
|
import javax.swing.JProgressBar;
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import it.sauronsoftware.jave.MultimediaInfo;
|
||||||
import java.util.*;
|
import it.sauronsoftware.jave.EncoderProgressListener;
|
||||||
import it.sauronsoftware.jave.*;
|
import java.awt.Dialog;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
public class ProgressDialog extends JDialog implements EncoderProgressListener {
|
public class ProgressDialog extends JDialog implements EncoderProgressListener {
|
||||||
JLabel message;
|
JLabel message;
|
||||||
|
|||||||
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
|
public class QueueMonitor extends JPanel implements MouseListener {
|
||||||
|
|
||||||
|
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
|
||||||
|
Queue<Runnable> queue;
|
||||||
|
|
||||||
|
public QueueMonitor(Queue<Runnable> q) {
|
||||||
|
super();
|
||||||
|
queue = q;
|
||||||
|
addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addThread(WorkerThread t) {
|
||||||
|
threadList.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purgeQueue() {
|
||||||
|
Runnable work;
|
||||||
|
synchronized (queue) {
|
||||||
|
while (queue.size() > 0) {
|
||||||
|
work = queue.remove();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setDequeued();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(150 + (24 * threadList.size()), 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Rectangle size = g.getClipBounds();
|
||||||
|
g.setColor(getBackground());
|
||||||
|
g.fillRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.drawRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setFont(getFont());
|
||||||
|
|
||||||
|
for (int i = 0; i < threadList.size(); i++) {
|
||||||
|
WorkerThread t = threadList.get(i);
|
||||||
|
if (t.isRunning()) {
|
||||||
|
g.setColor(new Color(50, 200, 0));
|
||||||
|
} else {
|
||||||
|
g.setColor(new Color(80, 0, 0));
|
||||||
|
}
|
||||||
|
g.fillOval(i * 24 + 4, 4, 22 - 8, 22 - 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
g.drawString("Queued: " + queue.size(), threadList.size() * 24 + 4, 16);
|
||||||
|
|
||||||
|
if (queue.size() > 0) {
|
||||||
|
Icons.close.paintIcon(this, g, size.width - 23, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
if (queue.size() == 0) return; // No button - ignore it
|
||||||
|
Dimension size = getPreferredSize();
|
||||||
|
if (evt.getX() > (size.width - 24)) {
|
||||||
|
purgeQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,15 +1,5 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.event.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.file.*;
|
|
||||||
import javax.swing.tree.*;
|
|
||||||
import javax.sound.sampled.*;
|
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
@@ -20,15 +10,7 @@ import org.apache.http.entity.mime.content.StringBody;
|
|||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
import edu.cmu.sphinx.api.*;
|
|
||||||
import edu.cmu.sphinx.decoder.adaptation.*;
|
|
||||||
import edu.cmu.sphinx.result.*;
|
|
||||||
|
|
||||||
import org.json.*;
|
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
@@ -40,6 +22,26 @@ import org.w3c.dom.Attr;
|
|||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
import javax.sound.sampled.TargetDataLine;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
|
|
||||||
public class Sentence extends BookTreeNode implements Cacheable {
|
public class Sentence extends BookTreeNode implements Cacheable {
|
||||||
|
|
||||||
@@ -63,6 +65,12 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
boolean inSample;
|
boolean inSample;
|
||||||
boolean attention = false;
|
boolean attention = false;
|
||||||
boolean processed = false;
|
boolean processed = false;
|
||||||
|
boolean isDetected = false;
|
||||||
|
|
||||||
|
int state = IDLE;
|
||||||
|
static final int IDLE = 0;
|
||||||
|
static final int QUEUED = 1;
|
||||||
|
static final int PROCESSING = 2;
|
||||||
|
|
||||||
String effectChain = null;
|
String effectChain = null;
|
||||||
|
|
||||||
@@ -208,9 +216,13 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
processed = Utils.s2b(Book.getTextNode(root, "processed"));
|
processed = Utils.s2b(Book.getTextNode(root, "processed"));
|
||||||
runtime = Utils.s2d(Book.getTextNode(root, "time", "-1.000"));
|
runtime = Utils.s2d(Book.getTextNode(root, "time", "-1.000"));
|
||||||
peak = Utils.s2d(Book.getTextNode(root, "peak", "-1.000"));
|
peak = Utils.s2d(Book.getTextNode(root, "peak", "-1.000"));
|
||||||
|
isDetected = Utils.s2b(Book.getTextNode(root, "detected"));
|
||||||
|
|
||||||
|
if (text == null) text = id;
|
||||||
|
if (text.equals("")) text = id;
|
||||||
|
|
||||||
if ((crossStartOffset == -1) || (crossEndOffset == -1)) {
|
if ((crossStartOffset == -1) || (crossEndOffset == -1)) {
|
||||||
updateCrossings(true);
|
updateCrossings();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtime <= 0.01d) getLength();
|
if (runtime <= 0.01d) getLength();
|
||||||
@@ -248,26 +260,40 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
|
|
||||||
if (!id.equals("room-noise")) {
|
if (!id.equals("room-noise")) {
|
||||||
autoTrimSample(true);
|
autoTrimSample();
|
||||||
if (Options.getBoolean("process.sphinx")) {
|
if (Options.getBoolean("process.sphinx")) {
|
||||||
recognise();
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.doRecognition();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSample() {
|
public void autoTrimSample(boolean ignored) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
autoTrimSample(false);
|
autoTrimSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSample(boolean useRaw) {
|
public void autoTrimSample() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
String tm = Options.get("audio.recording.trim");
|
String tm = Options.get("audio.recording.trim");
|
||||||
if (tm.equals("peak")) {
|
if (tm.equals("peak")) {
|
||||||
autoTrimSamplePeak(useRaw);
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.autoTrimSamplePeak();
|
||||||
|
AudiobookRecorder.window.updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT(useRaw);
|
AudiobookRecorder.window.queueJob(new SentenceJob(this) {
|
||||||
|
public void run() {
|
||||||
|
sentence.autoTrimSampleFFT();
|
||||||
|
AudiobookRecorder.window.updateWaveformMarkers();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
startOffset = 0;
|
startOffset = 0;
|
||||||
crossStartOffset = 0;
|
crossStartOffset = 0;
|
||||||
@@ -276,13 +302,13 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
processed = false;
|
processed = false;
|
||||||
// peak = -1d;
|
// peak = -1d;
|
||||||
}
|
}
|
||||||
|
AudiobookRecorder.window.updateWaveform(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int FFTBuckets = 1024;
|
public static final int FFTBuckets = 1024;
|
||||||
|
|
||||||
public void autoTrimSampleFFT() {
|
public void autoTrimSampleFFT(boolean ignored) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
autoTrimSampleFFT(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double bucketDifference(double[] a, double[] b) {
|
public double bucketDifference(double[] a, double[] b) {
|
||||||
@@ -296,16 +322,12 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSampleFFT(boolean useRaw) {
|
public void autoTrimSampleFFT() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[][] samples;
|
double[][] samples;
|
||||||
if (useRaw) {
|
samples = getProcessedAudioData();
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData();
|
|
||||||
}
|
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -377,7 +399,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
if (endOffset <= startOffset) endOffset = startOffset + fftSize;
|
if (endOffset <= startOffset) endOffset = startOffset + fftSize;
|
||||||
if (endOffset < 0) endOffset = 0;
|
if (endOffset < 0) endOffset = 0;
|
||||||
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length;
|
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length;
|
||||||
updateCrossings(useRaw);
|
updateCrossings();
|
||||||
intens = null;
|
intens = null;
|
||||||
samples = null;
|
samples = null;
|
||||||
processed = true;
|
processed = true;
|
||||||
@@ -428,21 +450,17 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void autoTrimSamplePeak() {
|
public void autoTrimSamplePeak(boolean ignored) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
autoTrimSamplePeak(false);
|
autoTrimSamplePeak();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSamplePeak(boolean useRaw) {
|
public void autoTrimSamplePeak() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[][] samples;
|
double[][] samples;
|
||||||
if (useRaw) {
|
samples = getProcessedAudioData();
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData();
|
|
||||||
}
|
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
||||||
noiseFloor *= 1.1;
|
noiseFloor *= 1.1;
|
||||||
@@ -482,7 +500,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
if (startOffset < 0) startOffset = 0;
|
if (startOffset < 0) startOffset = 0;
|
||||||
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length-1;
|
if (endOffset >= samples[LEFT].length) endOffset = samples[LEFT].length-1;
|
||||||
updateCrossings(useRaw);
|
updateCrossings();
|
||||||
processed = true;
|
processed = true;
|
||||||
reloadTree();
|
reloadTree();
|
||||||
}
|
}
|
||||||
@@ -501,6 +519,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public String getText() {
|
public String getText() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (text == null) return id;
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,38 +607,23 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void updateCrossings() {
|
public void updateCrossings() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
updateCrossings(false);
|
updateStartCrossing();
|
||||||
}
|
updateEndCrossing();
|
||||||
|
|
||||||
public void updateCrossings(boolean useRaw) {
|
|
||||||
Debug.trace();
|
|
||||||
updateStartCrossing(useRaw);
|
|
||||||
updateEndCrossing(useRaw);
|
|
||||||
runtime = -1d;
|
runtime = -1d;
|
||||||
getLength();
|
getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateStartCrossing() {
|
public void updateStartCrossing() {
|
||||||
Debug.trace();
|
|
||||||
updateStartCrossing(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateStartCrossing(boolean useRaw) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (crossStartOffset == -1) {
|
if (crossStartOffset == -1) {
|
||||||
crossStartOffset = findNearestZeroCrossing(useRaw, startOffset, 4096);
|
crossStartOffset = findNearestZeroCrossing(startOffset, 4096);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEndCrossing() {
|
public void updateEndCrossing() {
|
||||||
Debug.trace();
|
|
||||||
updateEndCrossing(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateEndCrossing(boolean useRaw) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (crossEndOffset == -1) {
|
if (crossEndOffset == -1) {
|
||||||
crossEndOffset = findNearestZeroCrossing(useRaw, endOffset, 4096);
|
crossEndOffset = findNearestZeroCrossing(endOffset, 4096);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -685,62 +689,33 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doRecognition(StreamSpeechRecognizer recognizer) {
|
public void doRecognition() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
try {
|
try {
|
||||||
setText("[recognising...]");
|
|
||||||
reloadTree();
|
reloadTree();
|
||||||
|
|
||||||
byte[] inData = getPCMData();
|
String command = Options.get("process.command");
|
||||||
|
Debug.d("Recognizing with command", command);
|
||||||
|
|
||||||
|
ProcessBuilder builder = new ProcessBuilder(command, getFile().getCanonicalPath());
|
||||||
|
Process process = builder.start();
|
||||||
|
InputStream is = process.getInputStream();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||||
|
|
||||||
ByteArrayInputStream bas = new ByteArrayInputStream(inData);
|
|
||||||
recognizer.startRecognition(bas);
|
|
||||||
SpeechResult result;
|
|
||||||
String res = "";
|
String res = "";
|
||||||
while ((result = recognizer.getResult()) != null) {
|
String line = null;
|
||||||
res += result.getHypothesis();
|
while ((line = reader.readLine()) != null) {
|
||||||
res += " ";
|
res += line;
|
||||||
}
|
}
|
||||||
recognizer.stopRecognition();
|
|
||||||
|
|
||||||
setText(res);
|
setText(res);
|
||||||
|
isDetected = true;
|
||||||
reloadTree();
|
reloadTree();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recognise() {
|
|
||||||
Debug.trace();
|
|
||||||
Thread t = new Thread(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
Debug.trace();
|
|
||||||
try {
|
|
||||||
Configuration sphinxConfig = new Configuration();
|
|
||||||
|
|
||||||
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
|
|
||||||
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
|
||||||
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
|
||||||
|
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
|
|
||||||
sphinxConfig.setSampleRate((int)(format.getSampleRate()));
|
|
||||||
|
|
||||||
StreamSpeechRecognizer recognizer;
|
|
||||||
|
|
||||||
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
|
||||||
|
|
||||||
doRecognition(recognizer);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
t.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocked(boolean l) {
|
public void setLocked(boolean l) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked == l) return;
|
if (locked == l) return;
|
||||||
@@ -776,18 +751,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
Debug.trace();
|
|
||||||
return findNearestZeroCrossing(false, pos, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int findNearestZeroCrossing(boolean useRaw, int pos, int range) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
double[][] data = null;
|
double[][] data = null;
|
||||||
if (useRaw) {
|
data = getProcessedAudioData();
|
||||||
data = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
data = getProcessedAudioData();
|
|
||||||
}
|
|
||||||
if (data == null) return 0;
|
if (data == null) return 0;
|
||||||
if (data[LEFT].length == 0) return 0;
|
if (data[LEFT].length == 0) return 0;
|
||||||
|
|
||||||
@@ -855,7 +821,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
File to = sentence.getFile();
|
File to = sentence.getFile();
|
||||||
Files.copy(from.toPath(), to.toPath());
|
Files.copy(from.toPath(), to.toPath());
|
||||||
|
|
||||||
// sentence.updateCrossings();
|
|
||||||
return sentence;
|
return sentence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -873,24 +838,15 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public double getPeakValue() {
|
public double getPeakValue() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
return getPeakValue(false, true);
|
return getPeakValue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPeakValue(boolean useRaw) {
|
public double getPeakValue(boolean applyGain) {
|
||||||
Debug.trace();
|
|
||||||
return getPeakValue(useRaw, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getPeakValue(boolean useRaw, boolean applyGain) {
|
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
double oldGain = gain;
|
double oldGain = gain;
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
double[][] samples = null;
|
double[][] samples = null;
|
||||||
if (useRaw) {
|
samples = getProcessedAudioData(true, applyGain);
|
||||||
samples = getRawAudioData();
|
|
||||||
} else {
|
|
||||||
samples = getProcessedAudioData(true, applyGain);
|
|
||||||
}
|
|
||||||
gain = oldGain;
|
gain = oldGain;
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -937,7 +893,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
public double normalize(double low, double high) {
|
public double normalize(double low, double high) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked) return gain;
|
if (locked) return gain;
|
||||||
double max = getPeakValue(true, false);
|
double max = getPeakValue(false);
|
||||||
double d = 0.708 / max;
|
double d = 0.708 / max;
|
||||||
if (d > 1d) d = 1d;
|
if (d > 1d) d = 1d;
|
||||||
if (d < low) d = low;
|
if (d < low) d = low;
|
||||||
@@ -952,7 +908,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
public double normalize() {
|
public double normalize() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (locked) return gain;
|
if (locked) return gain;
|
||||||
double max = getPeakValue(true, false);
|
double max = getPeakValue(false);
|
||||||
double d = 0.708 / max;
|
double d = 0.708 / max;
|
||||||
if (d > 1d) d = 1d;
|
if (d > 1d) d = 1d;
|
||||||
setGain(d);
|
setGain(d);
|
||||||
@@ -1000,8 +956,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
public void openInExternalEditor() {
|
public void openInExternalEditor() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
ExternalEditor ed = new ExternalEditor(this);
|
ExternalEditor ed = new ExternalEditor(this);
|
||||||
Thread t = new Thread(ed);
|
ed.run();
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backup() throws IOException {
|
public void backup() throws IOException {
|
||||||
@@ -1095,8 +1050,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (isLocked()) return;
|
if (isLocked()) return;
|
||||||
ExternalProcessor ed = new ExternalProcessor(this, num);
|
ExternalProcessor ed = new ExternalProcessor(this, num);
|
||||||
Thread t = new Thread(ed);
|
ed.run();
|
||||||
t.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undo() {
|
public void undo() {
|
||||||
@@ -1427,21 +1381,23 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
|
|
||||||
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
||||||
Effect eff = AudiobookRecorder.window.effects.get(def);
|
if ((def != null) && (AudiobookRecorder.window.effects != null)) {
|
||||||
|
Effect eff = AudiobookRecorder.window.effects.get(def);
|
||||||
if (effectsEnabled) {
|
|
||||||
if (eff != null) {
|
if (effectsEnabled) {
|
||||||
eff.init(getAudioFormat().getFrameRate());
|
if (eff != null) {
|
||||||
eff.process(processedAudio);
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
}
|
eff.process(processedAudio);
|
||||||
|
}
|
||||||
|
|
||||||
if (effectChain != null) {
|
if (effectChain != null) {
|
||||||
// Don't double up the default chain
|
// Don't double up the default chain
|
||||||
if (!effectChain.equals(def)) {
|
if (!effectChain.equals(def)) {
|
||||||
eff = AudiobookRecorder.window.effects.get(effectChain);
|
eff = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
eff.init(getAudioFormat().getFrameRate());
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
eff.process(processedAudio);
|
eff.process(processedAudio);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1519,6 +1475,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void setEffectChain(String key) {
|
public void setEffectChain(String key) {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
|
if (key == null) key = "none";
|
||||||
if ((effectChain != null) && (effectChain.equals(key))) {
|
if ((effectChain != null) && (effectChain.equals(key))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1635,6 +1592,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "notes", getNotes()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "notes", getNotes()));
|
||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "time", getLength()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "time", getLength()));
|
||||||
sentenceNode.appendChild(Book.makeTextNode(doc, "peak", getPeak()));
|
sentenceNode.appendChild(Book.makeTextNode(doc, "peak", getPeak()));
|
||||||
|
sentenceNode.appendChild(Book.makeTextNode(doc, "detected", beenDetected()));
|
||||||
return sentenceNode;
|
return sentenceNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1668,7 +1626,11 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
Debug.trace();
|
Debug.trace();
|
||||||
if (id.equals("room-noise")) return;
|
if (id.equals("room-noise")) return;
|
||||||
if (getParent() == null) return;
|
if (getParent() == null) return;
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getPeak() {
|
public double getPeak() {
|
||||||
@@ -1703,5 +1665,31 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
return (int)db;
|
return (int)db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean beenDetected() {
|
||||||
|
return isDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isProcessing() {
|
||||||
|
return state == PROCESSING;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isQueued() {
|
||||||
|
return state == QUEUED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcessing() {
|
||||||
|
state = PROCESSING;
|
||||||
|
reloadTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueued() {
|
||||||
|
state = QUEUED;
|
||||||
|
reloadTree();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDequeued() {
|
||||||
|
state = IDLE;
|
||||||
|
reloadTree();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
|
||||||
|
public class SentenceExternalJob extends SentenceJob {
|
||||||
|
protected int command;
|
||||||
|
|
||||||
|
public SentenceExternalJob(Sentence s, int c) {
|
||||||
|
super(s);
|
||||||
|
command = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sentence.runExternalProcessor(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal file
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
|
||||||
|
public abstract class SentenceJob implements Runnable {
|
||||||
|
protected Sentence sentence;
|
||||||
|
|
||||||
|
public SentenceJob(Sentence s) {
|
||||||
|
sentence = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueued() {
|
||||||
|
sentence.setQueued();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDequeued() {
|
||||||
|
sentence.setDequeued();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcessing() {
|
||||||
|
sentence.setProcessing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run();
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.util.*;
|
import javax.swing.SpinnerModel;
|
||||||
import javax.swing.*;
|
import java.util.ArrayList;
|
||||||
import javax.swing.event.*;
|
import javax.swing.event.ChangeListener;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
|
||||||
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
||||||
int min;
|
int min;
|
||||||
|
|||||||
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal file
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JToolTip;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.font.FontRenderContext;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import org.apache.commons.text.WordUtils;
|
||||||
|
|
||||||
|
public class Tip extends JLabel implements MouseListener {
|
||||||
|
String tip = null;
|
||||||
|
|
||||||
|
public Tip(String text) {
|
||||||
|
tip = WordUtils.wrap(text, 50);
|
||||||
|
|
||||||
|
setToolTipText(text);
|
||||||
|
setIcon(Icons.tooltip);
|
||||||
|
addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JToolTip createToolTip() {
|
||||||
|
JToolTip tt = new JToolTip() {
|
||||||
|
public String getTipText() {
|
||||||
|
return "*" + tip + "*";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
|
||||||
|
Rectangle r = g.getClipBounds();
|
||||||
|
|
||||||
|
JLabel l = new JLabel();
|
||||||
|
|
||||||
|
AffineTransform affinetransform = new AffineTransform();
|
||||||
|
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
|
||||||
|
Font f = l.getFont().deriveFont(14f);
|
||||||
|
|
||||||
|
g.setColor(new Color(200, 200, 180));
|
||||||
|
g.fillRect(0, 0, r.width, r.height);
|
||||||
|
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.setFont(f);
|
||||||
|
int y = 3;
|
||||||
|
String[] lines = tip.split("\n");
|
||||||
|
for (String line : lines) {
|
||||||
|
Rectangle2D bounds = f.getStringBounds(line, frc);
|
||||||
|
y += bounds.getHeight();
|
||||||
|
g.drawString(line, 5, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
|
||||||
|
JLabel l = new JLabel();
|
||||||
|
AffineTransform affinetransform = new AffineTransform();
|
||||||
|
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
|
||||||
|
Font f = l.getFont().deriveFont(14f);
|
||||||
|
|
||||||
|
String[] lines = tip.split("\n");
|
||||||
|
int w = 0;
|
||||||
|
int h = 0;
|
||||||
|
for (String line : lines) {
|
||||||
|
Rectangle2D bounds = f.getStringBounds(line, frc);
|
||||||
|
double fw = bounds.getWidth();
|
||||||
|
if (fw > w) w = (int)fw;
|
||||||
|
h += bounds.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dimension s = new Dimension(w + 10, h + 10);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
tt.removeAll();
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
tt.add(p);
|
||||||
|
JLabel l = new JLabel(tip);
|
||||||
|
l.setBackground(new Color(200, 200, 180));
|
||||||
|
l.setForeground(new Color(0, 0, 0));
|
||||||
|
p.add(l);
|
||||||
|
return tt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseEntered(MouseEvent evt) {
|
||||||
|
// showTipWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseExited(MouseEvent evt) {
|
||||||
|
// hideTipWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.event.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import javax.swing.border.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Desktop;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static Image getScaledImage(Image srcImg, int w, int h){
|
public static Image getScaledImage(Image srcImg, int w, int h){
|
||||||
|
|||||||
77
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
77
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
import java.net.URL;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class VersionChecker implements Runnable {
|
||||||
|
public VersionChecker() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://api.github.com/repos/MajenkoProjects/AudiobookRecorder/releases/latest");
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||||
|
InputStream is = conn.getInputStream();
|
||||||
|
InputStreamReader isr = new InputStreamReader(is);
|
||||||
|
BufferedReader br = new BufferedReader(isr);
|
||||||
|
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder jsonData = new StringBuilder();
|
||||||
|
|
||||||
|
while ((inputLine = br.readLine()) != null) {
|
||||||
|
jsonData.append(inputLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
JSONObject job = new JSONObject(jsonData.toString());
|
||||||
|
|
||||||
|
String installed = AudiobookRecorder.config.getProperty("version");
|
||||||
|
String available = job.getString("tag_name");
|
||||||
|
if (available.startsWith("v")) {
|
||||||
|
available = available.substring(1);
|
||||||
|
}
|
||||||
|
String website = job.getString("html_url");
|
||||||
|
|
||||||
|
|
||||||
|
String[] installedParts = installed.split("\\.");
|
||||||
|
String[] availableParts = available.split("\\.");
|
||||||
|
// Must be x.y.z
|
||||||
|
|
||||||
|
if (installedParts.length != 3) return;
|
||||||
|
if (availableParts.length != 3) return;
|
||||||
|
|
||||||
|
// Convert to xxxyyyzzz
|
||||||
|
String installedVersion = String.format("%03d%03d%03d", Utils.s2i(installedParts[0]), Utils.s2i(installedParts[1]), Utils.s2i(installedParts[2]));
|
||||||
|
String availableVersion = String.format("%03d%03d%03d", Utils.s2i(availableParts[0]), Utils.s2i(availableParts[1]), Utils.s2i(availableParts[2]));
|
||||||
|
|
||||||
|
if (Utils.s2i(installedVersion) >= Utils.s2i(availableVersion)) return;
|
||||||
|
|
||||||
|
System.err.println("Version installed: " + installed);
|
||||||
|
System.err.println("Version available: " + available);
|
||||||
|
System.err.println("URL: " + website);
|
||||||
|
|
||||||
|
JButton upgrade = new JButton("A new version is available.");
|
||||||
|
upgrade.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
Utils.browse(website);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AudiobookRecorder.window.statusBar.add(upgrade);
|
||||||
|
AudiobookRecorder.window.statusBar.revalidate();
|
||||||
|
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.*;
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.awt.event.*;
|
import javax.swing.JPanel;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.io.*;
|
import java.awt.Graphics;
|
||||||
import javax.sound.sampled.*;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Cursor;
|
||||||
|
|
||||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
|
|||||||
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal file
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
public class WorkerThread extends Thread {
|
||||||
|
private static int instance = 0;
|
||||||
|
private final Queue<Runnable> queue;
|
||||||
|
private final QueueMonitor monitor;
|
||||||
|
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
|
public WorkerThread(Queue<Runnable> queue, QueueMonitor mon) {
|
||||||
|
this.queue = queue;
|
||||||
|
monitor = mon;
|
||||||
|
setName("Worker Thread " + (instance++));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Debug.d(getName(), "started");
|
||||||
|
while ( true ) {
|
||||||
|
try {
|
||||||
|
Runnable work = null;
|
||||||
|
|
||||||
|
synchronized ( queue ) {
|
||||||
|
while ( queue.isEmpty() ) {
|
||||||
|
Debug.d(getName(), "waiting on work");
|
||||||
|
queue.wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.d(getName(), "got work");
|
||||||
|
|
||||||
|
// Get the next work item off of the queue
|
||||||
|
work = queue.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
running = true;
|
||||||
|
monitor.repaint();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setProcessing();
|
||||||
|
}
|
||||||
|
work.run();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setDequeued();
|
||||||
|
}
|
||||||
|
running = false;
|
||||||
|
monitor.repaint();
|
||||||
|
}
|
||||||
|
catch ( InterruptedException ie ) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
break; // Terminate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.d(getName(), "died");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user