Compare commits

..

21 Commits

Author SHA1 Message Date
4a4d7f2a38 Checkpoint release 2018-10-02 14:37:23 +01:00
f7848228a2 Added cover art import #6 2018-10-02 14:36:37 +01:00
8c22315b15 Added import archive #4 2018-10-02 14:21:12 +01:00
718c982578 Added batch conversion of text #8 2018-10-02 12:00:11 +01:00
be0f6a9f56 Checkpoint release 2018-10-02 00:45:31 +01:00
35874f5ca2 Only display begging panel every 10 launches 2018-10-02 00:43:30 +01:00
a7fdfce094 Added donation panel 2018-10-02 00:38:35 +01:00
5947c9a020 Added JEQ license file 2018-10-02 00:17:22 +01:00
05408915b1 Improved 96000 coefficients 2018-10-02 00:13:22 +01:00
4635b5af0f Added archive creation 2018-10-01 20:56:11 +01:00
b362217d75 Renamed ExportDialog to ProgressDialog 2018-10-01 20:05:24 +01:00
cc48d49b5c Added duplicate sentence and moved all playing out of Sentence and into main program 2018-10-01 19:41:27 +01:00
391e54b993 Added playback marker #20 2018-10-01 16:21:44 +01:00
49b6a92865 Added space to stop #10 2018-10-01 15:57:57 +01:00
fbe05367fa Added continuation recording on F key 2018-10-01 12:00:23 +01:00
eaf3080859 Added jpg and gif coverart to book panel 2018-10-01 11:11:10 +01:00
6ceec9ef85 Filtered empty lines on script execution 2018-09-30 22:58:07 +01:00
ac73711122 Updated buttons to be focusless and added red to background of mic toggle button 2018-09-30 17:22:54 +01:00
3cb0471027 Custom buttons with no focus 2018-09-30 13:51:15 +01:00
38e7434730 Added playback marker for single phrase play 2018-09-30 02:00:16 +01:00
d8cd72809c Added trim method option in preferences 2018-09-30 01:21:13 +01:00
21 changed files with 2026 additions and 778 deletions

View File

@@ -27,6 +27,7 @@ From here on much is controlled by key presses.
* Press and hold "R" to record a new phrase - the screen flashes red while it's recording. The phrase is
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 "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 "D" to delete the last phrase you recorded.
* Press "E" to re-record the currently selected phrase.

View File

@@ -1,76 +0,0 @@
#!/usr/bin/perl
use Math::Trig;
my $fs = 96000;
printCo(0, 20, 25, $fs);
printCo(20, 25, 31.5, $fs);
printCo(25, 31.5, 40, $fs);
printCo(31.5, 40, 50, $fs);
printCo(40, 50, 63, $fs);
printCo(50, 63, 80, $fs);
printCo(63, 80, 100, $fs);
printCo(80, 100, 125, $fs);
printCo(100, 125, 160, $fs);
printCo(125, 160, 200, $fs);
printCo(160, 200, 250, $fs);
printCo(200, 250, 315, $fs);
printCo(250, 315, 400, $fs);
printCo(315, 400, 500, $fs);
printCo(400, 500, 630, $fs);
printCo(500, 630, 800, $fs);
printCo(630, 800, 1000, $fs);
printCo(800, 1000, 1250, $fs);
printCo(1000, 1250, 1600, $fs);
printCo(1250, 1600, 2000, $fs);
printCo(1600, 2000, 2500, $fs);
printCo(2000, 2500, 3150, $fs);
printCo(2500, 3150, 4000, $fs);
printCo(3150, 4000, 5000, $fs);
printCo(4000, 5000, 6300, $fs);
printCo(5000, 6300, 8000, $fs);
printCo(6300, 8000, 10000, $fs);
printCo(8000, 10000, 12500, $fs);
printCo(10000, 12500, 16000, $fs);
printCo(12500, 16000, 20000, $fs);
printCo(16000, 20000, $fs / 2, $fs);
sub printCo($$$$) {
my $fl = shift;
my $f0 = shift;
my $fh = shift;
my $fs = shift;
my $f1 = $f0 - (($f0 - $fl) / 2);
my $f2 = $f0 + (($fh - $f0) / 2);
@coeff = coefficient($f0, $fs, $f1, $f2);
print "/* $f0 Hz */\n";
printf("new IIRCoefficients(%.10e, %.10e, %.10e),\n" , $coeff[1] * 2, $coeff[0] * 2, $coeff[2] * 2);
}
sub coefficient($$$$) {
my $f0 = shift;
my $fs = shift;
my $f1 = shift;
my $f2 = shift;
my $q = $f0 / ($f2 - $f1);
my $pi = 3.141592653;
my $theta0 = 2 * $pi * ($f0 / $fs);
my $thetaOverTwoQ = $theta0 / (2 * $q);
my $beta = 0.5 * ((1 - tan($thetaOverTwoQ)) / (1 + tan($thetaOverTwoQ)));
my $gamma = (0.5 + $beta) * cos($theta0);
my $alpha = (0.5 - $beta) / 2;
return ($alpha, $beta, $gamma);
}

133
iircoeff.c Normal file
View File

@@ -0,0 +1,133 @@
/*
* Copyright (C) 2002-2006 Felipe Rivera <liebremx at users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* Coefficient stuff
*
* $Id: iir_cfs.c,v 1.2 2006/01/15 00:17:46 liebremx Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static const double band_f031[] =
{ 20,25,31.5,40,50,63,80,100,125,160,200,250,315,400,500,630,800,
1000,1250,1600,2000,2500,3150,4000,5000,6300,8000,10000,12500,16000,20000
};
#define GAIN_F0 1.0
#define GAIN_F1 GAIN_F0 / M_SQRT2
#define SAMPLING_FREQ 44100.0
#define TETA(f) (2*M_PI*(double)f/sample_frequency)
#define TWOPOWER(value) (value * value)
#define BETA2(tf0, tf) \
(TWOPOWER(GAIN_F1)*TWOPOWER(cos(tf0)) \
- 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
+ TWOPOWER(GAIN_F1) \
- TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
#define BETA1(tf0, tf) \
(2.0 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf)) \
+ TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
- 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
- TWOPOWER(GAIN_F1) + TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
#define BETA0(tf0, tf) \
(0.25 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
- 0.5 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
+ 0.25 * TWOPOWER(GAIN_F1) \
- 0.25 * TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
#define GAMMA(beta, tf0) ((0.5 + beta) * cos(tf0))
#define ALPHA(beta) ((0.5 - beta)/2.0)
/*************
* Functions *
*************/
/* Get the band_f031 at both sides of F0. These will be cut at -3dB */
static void find_f1_and_f2(double f0, double octave_percent, double *f1, double *f2)
{
double octave_factor = pow(2.0, octave_percent/2.0);
*f1 = f0/octave_factor;
*f2 = f0*octave_factor;
}
/* Find the quadratic root
* Always return the smallest root */
static int find_root(double a, double b, double c, double *x0) {
double k = c-((b*b)/(4.*a));
double h = -(b/(2.*a));
double x1 = 0.;
if (-(k/a) < 0.)
return -1;
*x0 = h - sqrt(-(k/a));
x1 = h + sqrt(-(k/a));
if (x1 < *x0)
*x0 = x1;
return 0;
}
void calc_coeffs(double sample_frequency)
{
int i, n;
double f1, f2;
double x0;
printf(" public final static IIRCoefficients iir_cf31_%d[] = {\n", (int)sample_frequency);
for (i = 0; i < 31; i++) {
/* Find -3dB frequencies for the center freq */
find_f1_and_f2(band_f031[i], 1.0/3.0, &f1, &f2);
/* Find Beta */
if ( find_root(
BETA2(TETA(band_f031[i]), TETA(f1)),
BETA1(TETA(band_f031[i]), TETA(f1)),
BETA0(TETA(band_f031[i]), TETA(f1)),
&x0) == 0)
{
/* Got a solution, now calculate the rest of the factors */
/* Take the smallest root always (find_root returns the smallest one)
*
* NOTE: The IIR equation is
* y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2])
* Now the 2 factor has been distributed in the coefficients
*/
/* Now store the coefficients */
printf(" /* %.1f Hz */\n", band_f031[i]);
printf(" new IIRCoefficients(%.10e, %010e, %.10e),\n",
(double)(2.0 * x0),
(double)(2.0 * ALPHA(x0)),
(double)(2.0 * GAMMA(x0, TETA(band_f031[i])))
);
} else {
printf(" **** Where are the roots?\n");
}
}// for i
printf(" };\n");
}
int main(int argc, char **argv) {
if (argc != 2) {
printf("Usage: iircoeff <sample frequency>\n");
return -1;
}
double f = strtod(argv[1], NULL);
calc_coeffs(f);
}

76
iircoeff.pl Executable file
View File

@@ -0,0 +1,76 @@
#!/usr/bin/perl
use Math::Trig;
my $fs = 48000;
my $q = 1.414;
printCo(20, $fs, $q);
printCo(25, $fs, $q);
printCo(31.5, $fs, $q);
printCo(40, $fs, $q);
printCo(50, $fs, $q);
printCo(63, $fs, $q);
printCo(80, $fs, $q);
printCo(100, $fs, $q);
printCo(125, $fs, $q);
printCo(160, $fs, $q);
printCo(200, $fs, $q);
printCo(250, $fs, $q);
printCo(315, $fs, $q);
printCo(400, $fs, $q);
printCo(500, $fs, $q);
printCo(630, $fs, $q);
printCo(800, $fs, $q);
printCo(1000, $fs, $q);
printCo(1250, $fs, $q);
printCo(1600, $fs, $q);
printCo(2000, $fs, $q);
printCo(2500, $fs, $q);
printCo(3150, $fs, $q);
printCo(4000, $fs, $q);
printCo(5000, $fs, $q);
printCo(6300, $fs, $q);
printCo(8000, $fs, $q);
printCo(10000, $fs, $q);
printCo(12500, $fs, $q);
printCo(16000, $fs, $q);
printCo(20000, $fs, $q);
sub printCo($$$$) {
my $f0 = shift;
my $fs = shift;
my $q = shift;
@coeff = coefficient($f0, $fs, $q);
print "/* $f0 Hz */\n";
printf("new IIRCoefficients(%.10e, %.10e, %.10e),\n" , $coeff[1] * 2, $coeff[0] * 2, $coeff[2] * 2);
}
sub coefficient($$$$) {
my $f0 = shift;
my $fs = shift;
my $q = shift;
my $q2 = $q * $q;
my $f1 = $f0 * (sqrt(1 + (1 / (4 * $q2))) - (1 / (2 * $q)));
my $f2 = $f0 * (sqrt(1 + (1 / (4 * $q2))) + (1 / (2 * $q)));
my $pi = 3.141592653;
my $theta0 = 2 * $pi * ($f0 / $fs);
my $thetaOverTwoQ = $theta0 / (2 * $q);
my $beta = 0.5 * ((1 - tan($thetaOverTwoQ)) / (1 + tan($thetaOverTwoQ)));
my $gamma = (0.5 + $beta) * cos($theta0);
my $alpha = (0.5 - $beta) / 2;
return ($alpha, $beta, $gamma);
}

504
licenses/jeq/lgpl.txt Normal file
View File

@@ -0,0 +1,504 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@@ -1 +1 @@
version=0.0.9
version=0.1.1

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -70,6 +70,7 @@ public class IIRBase {
/* 11k Hz*/
new IIRCoefficients(3.3453245058e-01, 3.3273377471e-01, -1.3344985880e+00)
};
public final static IIRCoefficients iir_cf10_44100[] = {
/* 31 Hz*/
new IIRCoefficients(9.9688176273e-01, 1.5591186337e-03, 1.9968622855e+00),
@@ -92,6 +93,7 @@ public class IIRBase {
/* 16k Hz*/
new IIRCoefficients(2.4198119087e-01, 3.7900940457e-01, -8.0845085113e-01)
};
public final static IIRCoefficients iir_cf10_48000[] = {
/* 31 Hz*/
new IIRCoefficients(9.9713475915e-01, 1.4326204244e-03, 1.9971183163e+00),
@@ -114,6 +116,7 @@ public class IIRBase {
/* 16k Hz*/
new IIRCoefficients(2.5620076154e-01, 3.7189961923e-01, -6.2810038077e-01)
};
public final static IIRCoefficients iir_cf15_44100[] = {
/* 25 Hz*/
new IIRCoefficients(9.9834072702e-01, 8.2963648917e-04, 1.9983280505e+00),
@@ -146,6 +149,7 @@ public class IIRBase {
/* 16k Hz*/
new IIRCoefficients(4.0179628792e-01, 2.9910185604e-01, -9.1248032613e-01)
};
public final static IIRCoefficients iir_cf15_48000[] = {
/* 25 Hz*/
new IIRCoefficients(9.9847546664e-01, 7.6226668143e-04, 1.9984647656e+00),
@@ -178,6 +182,7 @@ public class IIRBase {
/* 16k Hz*/
new IIRCoefficients(4.1811888447e-01, 2.9094055777e-01, -7.0905944223e-01)
};
public final static IIRCoefficients iir_cf25_44100[] = {
/* 20 Hz*/
new IIRCoefficients(9.9934037157e-01, 3.2981421662e-04, 1.9993322545e+00),
@@ -230,6 +235,7 @@ public class IIRBase {
/* 20k Hz*/
new IIRCoefficients(6.1776148240e-01, 1.9111925880e-01, -1.5492465594e+00)
};
public final static IIRCoefficients iir_cf25_48000[] = {
/* 20 Hz*/
new IIRCoefficients(9.9939388451e-01, 3.0305774630e-04, 1.9993870327e+00),
@@ -282,6 +288,7 @@ public class IIRBase {
/* 20k Hz*/
new IIRCoefficients(6.0884213704e-01, 1.9557893148e-01, -1.3932981614e+00)
};
public final static IIRCoefficients iir_cf31_44100[] = {
/* 20 Hz*/
new IIRCoefficients(9.9934037157e-01, 3.2981421662e-04, 1.9993322545e+00),
@@ -346,6 +353,7 @@ public class IIRBase {
/* 20k Hz*/
new IIRCoefficients(6.1776148240e-01, 1.9111925880e-01, -1.5492465594e+00)
};
public final static IIRCoefficients iir_cf31_48000[] = {
/* 20 Hz*/
new IIRCoefficients(9.9939388451e-01, 3.0305774630e-04, 1.9993870327e+00),
@@ -410,69 +418,69 @@ public class IIRBase {
/* 20k Hz*/
new IIRCoefficients(6.0884213704e-01, 1.9557893148e-01, -1.3932981614e+00),
};
public final static IIRCoefficients iir_cf31_96000[] = {
/* 20 Hz */
new IIRCoefficients(9.9918221139e-01, 4.0889430323e-04, 1.9991804986e+00),
/* 25 Hz */
new IIRCoefficients(9.9962373418e-01, 1.8813291151e-04, 1.9996210574e+00),
/* 31.5 Hz */
new IIRCoefficients(9.9950924659e-01, 2.4537670644e-04, 1.9995049971e+00),
/* 40 Hz */
new IIRCoefficients(9.9939477210e-01, 3.0261394841e-04, 1.9993879203e+00),
/* 50 Hz */
new IIRCoefficients(9.9924760988e-01, 3.7619506167e-04, 1.9992369047e+00),
/* 63 Hz */
new IIRCoefficients(9.9901873389e-01, 4.9063305250e-04, 1.9990017403e+00),
/* 80 Hz */
new IIRCoefficients(9.9878991029e-01, 6.0504485723e-04, 1.9987625114e+00),
/* 100 Hz */
new IIRCoefficients(9.9852846169e-01, 7.3576915625e-04, 1.9984856565e+00),
/* 125 Hz */
new IIRCoefficients(9.9803842973e-01, 9.8078513561e-04, 1.9979715632e+00),
/* 160 Hz */
new IIRCoefficients(9.9754863778e-01, 1.2256811083e-03, 1.9974391109e+00),
/* 200 Hz */
new IIRCoefficients(9.9705908562e-01, 1.4704571921e-03, 1.9968879927e+00),
/* 250 Hz */
new IIRCoefficients(9.9624369754e-01, 1.8781512307e-03, 1.9959764762e+00),
/* 315 Hz */
new IIRCoefficients(9.9510327003e-01, 2.4483649847e-03, 1.9946792773e+00),
/* 400 Hz */
new IIRCoefficients(9.9396414160e-01, 3.0179291997e-03, 1.9932808599e+00),
/* 500 Hz */
new IIRCoefficients(9.9250145198e-01, 3.7492740081e-03, 1.9914346418e+00),
/* 630 Hz */
new IIRCoefficients(9.9023040090e-01, 4.8847995509e-03, 1.9885387521e+00),
/* 800 Hz */
new IIRCoefficients(9.8796449555e-01, 6.0177522243e-03, 1.9852400593e+00),
/* 1000 Hz */
new IIRCoefficients(9.8538116034e-01, 7.3094198292e-03, 1.9811303069e+00),
/* 1250 Hz */
new IIRCoefficients(9.8055531891e-01, 9.7223405432e-03, 1.9739308353e+00),
/* 1600 Hz */
new IIRCoefficients(9.7575264994e-01, 1.2123675032e-02, 1.9649292702e+00),
/* 2000 Hz */
new IIRCoefficients(9.7097292946e-01, 1.4513535269e-02, 1.9541109828e+00),
/* 2500 Hz */
new IIRCoefficients(9.6305712557e-01, 1.8471437214e-02, 1.9368372235e+00),
/* 3150 Hz */
new IIRCoefficients(9.5207914671e-01, 2.3960426645e-02, 1.9107394812e+00),
/* 4000 Hz */
new IIRCoefficients(9.4122023318e-01, 2.9389883411e-02, 1.8750747578e+00),
/* 5000 Hz */
new IIRCoefficients(9.2742950588e-01, 3.6285247058e-02, 1.8251410716e+00),
/* 6300 Hz */
new IIRCoefficients(9.0634716904e-01, 4.6826415482e-02, 1.7465723184e+00),
/* 8000 Hz */
new IIRCoefficients(8.8569806727e-01, 5.7150966366e-02, 1.6330624302e+00),
/* 10000 Hz */
new IIRCoefficients(8.6260593228e-01, 6.8697033860e-02, 1.4777046382e+00),
/* 12500 Hz */
new IIRCoefficients(8.2067879086e-01, 8.9660604570e-02, 1.2446020061e+00),
/* 16000 Hz */
new IIRCoefficients(7.8040765969e-01, 1.0979617015e-01, 8.9020383015e-01),
/* 20000 Hz */
new IIRCoefficients(2.6794919254e-01, 3.6602540373e-01, 3.2816939955e-01),
public final static IIRCoefficients iir_cf31_96000[] = {
/* 20.0 Hz */
new IIRCoefficients(9.9969659208e-01, 1.517040e-04, 1.9996948789e+00),
/* 25.0 Hz */
new IIRCoefficients(9.9962116126e-01, 1.894194e-04, 1.9996184845e+00),
/* 31.5 Hz */
new IIRCoefficients(9.9952283343e-01, 2.385833e-04, 1.9995185840e+00),
/* 40.0 Hz */
new IIRCoefficients(9.9939398196e-01, 3.030090e-04, 1.9993871301e+00),
/* 50.0 Hz */
new IIRCoefficients(9.9924251688e-01, 3.787416e-04, 1.9992318117e+00),
/* 63.0 Hz */
new IIRCoefficients(9.9904565182e-01, 4.771741e-04, 1.9990286580e+00),
/* 80.0 Hz */
new IIRCoefficients(9.9878828573e-01, 6.058571e-04, 1.9987608868e+00),
/* 100.0 Hz */
new IIRCoefficients(9.9848557077e-01, 7.572146e-04, 1.9984427665e+00),
/* 125.0 Hz */
new IIRCoefficients(9.9810732562e-01, 9.463372e-04, 1.9980404568e+00),
/* 160.0 Hz */
new IIRCoefficients(9.9757801618e-01, 1.210992e-03, 1.9974684877e+00),
/* 200.0 Hz */
new IIRCoefficients(9.9697343858e-01, 1.513281e-03, 1.9968023530e+00),
/* 250.0 Hz */
new IIRCoefficients(9.9621823615e-01, 1.890882e-03, 1.9959510182e+00),
/* 315.0 Hz */
new IIRCoefficients(9.9523733132e-01, 2.381334e-03, 1.9948133101e+00),
/* 400.0 Hz */
new IIRCoefficients(9.9395607744e-01, 3.021961e-03, 1.9932727985e+00),
/* 500.0 Hz */
new IIRCoefficients(9.9245084999e-01, 3.774575e-03, 1.9913840669e+00),
/* 630.0 Hz */
new IIRCoefficients(9.9049749915e-01, 4.751250e-03, 1.9888056234e+00),
/* 800.0 Hz */
new IIRCoefficients(9.8794899744e-01, 6.025501e-03, 1.9852245824e+00),
/* 1000.0 Hz */
new IIRCoefficients(9.8495930024e-01, 7.520350e-03, 1.9807093500e+00),
/* 1250.0 Hz */
new IIRCoefficients(9.8123517675e-01, 9.382412e-03, 1.9746084192e+00),
/* 1600.0 Hz */
new IIRCoefficients(9.7604570090e-01, 1.197715e-02, 1.9652207158e+00),
/* 2000.0 Hz */
new IIRCoefficients(9.7014963927e-01, 1.492518e-02, 1.9532947360e+00),
/* 2500.0 Hz */
new IIRCoefficients(9.6283181641e-01, 1.858409e-02, 1.9366149237e+00),
/* 3150.0 Hz */
new IIRCoefficients(9.5340564248e-01, 2.329718e-02, 1.9120378855e+00),
/* 4000.0 Hz */
new IIRCoefficients(9.4122788957e-01, 2.938606e-02, 1.8750821533e+00),
/* 5000.0 Hz */
new IIRCoefficients(9.2711765003e-01, 3.644117e-02, 1.8248457659e+00),
/* 6300.0 Hz */
new IIRCoefficients(9.0912548757e-01, 4.543726e-02, 1.7491177803e+00),
/* 8000.0 Hz */
new IIRCoefficients(8.8619860800e-01, 5.690070e-02, 1.6334959111e+00),
/* 10000.0 Hz */
new IIRCoefficients(8.6010264114e-01, 6.994868e-02, 1.4757186436e+00),
/* 12500.0 Hz */
new IIRCoefficients(8.2882509035e-01, 8.558745e-02, 1.2501707535e+00),
/* 16000.0 Hz */
new IIRCoefficients(7.8757448309e-01, 1.062128e-01, 8.9378724155e-01),
/* 20000.0 Hz */
new IIRCoefficients(7.4415362476e-01, 1.279232e-01, 4.5142017567e-01),
};
}

View File

@@ -17,6 +17,9 @@ import edu.cmu.sphinx.api.*;
import edu.cmu.sphinx.decoder.adaptation.*;
import edu.cmu.sphinx.result.*;
import java.nio.file.Files;
import java.util.zip.*;
import javax.swing.filechooser.*;
import javax.imageio.*;
public class AudiobookRecorder extends JFrame {
@@ -34,12 +37,14 @@ public class AudiobookRecorder extends JFrame {
JMenuItem fileOpenBook;
JMenuItem fileSave;
JMenuItem fileExit;
JMenuItem fileOpenArchive;
JMenuItem bookNewChapter;
JMenuItem bookExportAudio;
JMenuItem toolsMerge;
JMenuItem toolsArchive;
JMenuItem toolsCoverArt;
JMenuItem toolsOptions;
JMenuItem helpAbout;
@@ -65,14 +70,14 @@ public class AudiobookRecorder extends JFrame {
Sentence selectedSentence = null;
JPanel sampleControl;
Waveform sampleWaveform;
public Waveform sampleWaveform;
JScrollBar sampleScroll;
JSpinner postSentenceGap;
JCheckBox locked;
JButton reprocessAudioFFT;
JButton reprocessAudioPeak;
JButtonSpacePlay reprocessAudioFFT;
JButtonSpacePlay reprocessAudioPeak;
Thread playingThread = null;
@@ -136,6 +141,13 @@ public class AudiobookRecorder extends JFrame {
}
});
fileOpenArchive = new JMenuItem("Open Archive...");
fileOpenArchive.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openArchive();
}
});
fileExit = new JMenuItem("Exit");
fileExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -148,6 +160,8 @@ public class AudiobookRecorder extends JFrame {
fileMenu.add(fileOpenBook);
fileMenu.add(fileSave);
fileMenu.addSeparator();
fileMenu.add(fileOpenArchive);
fileMenu.addSeparator();
fileMenu.add(fileExit);
menuBar.add(fileMenu);
@@ -192,6 +206,13 @@ public class AudiobookRecorder extends JFrame {
}
});
toolsCoverArt = new JMenuItem("Import Cover Art...");
toolsCoverArt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loadCoverArt();
}
});
toolsOptions = new JMenuItem("Options");
toolsOptions.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -201,6 +222,7 @@ public class AudiobookRecorder extends JFrame {
toolsMenu.add(toolsMerge);
toolsMenu.add(toolsArchive);
toolsMenu.add(toolsCoverArt);
toolsMenu.addSeparator();
toolsMenu.add(toolsOptions);
@@ -317,9 +339,7 @@ public class AudiobookRecorder extends JFrame {
sampleControl.add(sampleWaveform, BorderLayout.CENTER);
reprocessAudioFFT = new JButton(Icons.fft);
reprocessAudioFFT.setToolTipText("Autotrim Audio (FFT)");
reprocessAudioFFT.addActionListener(new ActionListener() {
reprocessAudioFFT = new JButtonSpacePlay(Icons.fft, "Autotrim Audio (FFT)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedSentence != null) {
selectedSentence.autoTrimSampleFFT();
@@ -331,9 +351,7 @@ public class AudiobookRecorder extends JFrame {
}
});
reprocessAudioPeak = new JButton(Icons.peak);
reprocessAudioPeak.setToolTipText("Autotrim Audio (Peak)");
reprocessAudioPeak.addActionListener(new ActionListener() {
reprocessAudioPeak = new JButtonSpacePlay(Icons.peak, "Autotrim Audio (Peak)", new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (selectedSentence != null) {
selectedSentence.autoTrimSamplePeak();
@@ -362,13 +380,15 @@ public class AudiobookRecorder extends JFrame {
JToolBar controlsLeft = new JToolBar(JToolBar.VERTICAL);
JToolBar controlsRight = new JToolBar(JToolBar.VERTICAL);
controlsTop.setFloatable(false);
controlsLeft.setFloatable(false);
controlsRight.setFloatable(false);
controlsLeft.add(reprocessAudioFFT);
controlsLeft.add(reprocessAudioPeak);
locked = new JCheckBox("Sentence locked");
locked = new JCheckBox("Phrase locked");
locked.setFocusable(false);
locked.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -388,22 +408,21 @@ public class AudiobookRecorder extends JFrame {
controlsTop.add(locked);
controlsTop.add(Box.createHorizontalGlue());
controlsTop.add(new JLabel("Post gap:"));
controlsTop.add(postSentenceGap);
controlsTop.add(new JLabel("ms"));
controlsTop.add(Box.createHorizontalGlue());
JButton zoomIn = new JButton(Icons.zoomIn);
zoomIn.setToolTipText("Zoom In");
zoomIn.addActionListener(new ActionListener() {
JButtonSpacePlay zoomIn = new JButtonSpacePlay(Icons.zoomIn, "Zoom In", new ActionListener() {
public void actionPerformed(ActionEvent e) {
sampleWaveform.increaseZoom();
}
});
controlsRight.add(zoomIn);
JButton zoomOut = new JButton(Icons.zoomOut);
zoomOut.setToolTipText("Zoom Out");
zoomOut.addActionListener(new ActionListener() {
JButtonSpacePlay zoomOut = new JButtonSpacePlay(Icons.zoomOut, "Zoom Out", new ActionListener() {
public void actionPerformed(ActionEvent e) {
sampleWaveform.decreaseZoom();
}
@@ -424,6 +443,9 @@ public class AudiobookRecorder extends JFrame {
buildToolbar(centralPanel);
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("F"), "startRecordShort");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released F"), "stopRecord");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("R"), "startRecord");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released R"), "stopRecord");
@@ -432,7 +454,7 @@ public class AudiobookRecorder extends JFrame {
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released D"), "deleteLast");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("SPACE"), "startPlayback");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("SPACE"), "startStopPlayback");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("E"), "startRerecord");
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released E"), "stopRecord");
@@ -447,6 +469,16 @@ public class AudiobookRecorder extends JFrame {
startRecording();
}
});
centralPanel.getActionMap().put("startRecordShort", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (bookTree.isEditing()) return;
if (getNoiseFloor() == 0) {
alertNoRoomNoise();
return;
}
startRecordingShort();
}
});
centralPanel.getActionMap().put("startRecordNewPara", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (bookTree.isEditing()) return;
@@ -480,10 +512,14 @@ public class AudiobookRecorder extends JFrame {
}
});
centralPanel.getActionMap().put("startPlayback", new AbstractAction() {
centralPanel.getActionMap().put("startStopPlayback", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (bookTree.isEditing()) return;
if (playing == null) {
playSelectedSentence();
} else {
stopPlaying();
}
}
});
@@ -509,6 +545,18 @@ public class AudiobookRecorder extends JFrame {
}
}
}
if (!Options.getBoolean("interface.donations.hide")) {
int numruns = Options.getInteger("interface.donations.count");
numruns++;
if (numruns == 10) {
numruns = 0;
JOptionPane.showMessageDialog(this, new DonationPanel(), "Thank you", JOptionPane.PLAIN_MESSAGE);
}
Options.set("interface.donations.count", numruns);
Options.savePreferences();
}
}
public static void main(String args[]) {
@@ -568,9 +616,10 @@ public class AudiobookRecorder extends JFrame {
ob = null;
}
public JMenuObject(String p, Object o) {
public JMenuObject(String p, Object o, ActionListener l) {
super(p);
ob = o;
addActionListener(l);
}
public void setObject(Object o) {
@@ -592,10 +641,11 @@ public class AudiobookRecorder extends JFrame {
ob2 = null;
}
public JMenuObject2(String p, Object o1, Object o2) {
public JMenuObject2(String p, Object o1, Object o2, ActionListener l) {
super(p);
ob1 = o1;
ob2 = o2;
addActionListener(l);
}
public void setObject1(Object o) {
@@ -615,6 +665,41 @@ public class AudiobookRecorder extends JFrame {
}
}
class BatchConversionThread implements Runnable {
Chapter chapter;
public BatchConversionThread(Chapter c) {
chapter = c;
}
public void run() {
try {
Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
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() / 3f));
StreamSpeechRecognizer recognizer;
recognizer = new StreamSpeechRecognizer(sphinxConfig);
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
if (snt.getId().equals(snt.getText())) {
snt.doRecognition(recognizer);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("unchecked")
void treePopup(MouseEvent e) {
@@ -630,13 +715,25 @@ public class AudiobookRecorder extends JFrame {
bookTree.setSelectionPath(new TreePath(s.getPath()));
JPopupMenu menu = new JPopupMenu();
JMenuObject rec = new JMenuObject("Recognise text from audio", s);
JMenu moveMenu = new JMenu("Move sentence to...");
JMenuObject rec = new JMenuObject("Recognise text from audio", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject();
if (!s.isLocked()) {
s.recognise();
}
}
});
JMenu moveMenu = new JMenu("Move phrase to...");
for (Enumeration c = book.children(); c.hasMoreElements();) {
Chapter chp = (Chapter)c.nextElement();
JMenuObject2 m = new JMenuObject2(chp.getName(), s, chp);
m.addActionListener(new ActionListener() {
JMenuObject2 m = new JMenuObject2(chp.getName(), s, chp, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject2 ob = (JMenuObject2)e.getSource();
Sentence sentence = (Sentence)ob.getObject1();
@@ -649,10 +746,7 @@ public class AudiobookRecorder extends JFrame {
moveMenu.add(m);
}
JMenuObject moveUp = new JMenuObject("Move Up", s);
JMenuObject moveDown = new JMenuObject("Move Down", s);
moveUp.addActionListener(new ActionListener() {
JMenuObject moveUp = new JMenuObject("Move Up", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Sentence sent = (Sentence)o.getObject();
@@ -664,7 +758,7 @@ public class AudiobookRecorder extends JFrame {
}
});
moveDown.addActionListener(new ActionListener() {
JMenuObject moveDown = new JMenuObject("Move Down", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Sentence sent = (Sentence)o.getObject();
@@ -677,11 +771,7 @@ public class AudiobookRecorder extends JFrame {
});
JMenuObject ins = new JMenuObject("Insert sentence above", s);
JMenuObject del = new JMenuObject("Delete sentence", s);
ins.addActionListener(new ActionListener() {
JMenuObject ins = new JMenuObject("Insert phrase above", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject();
@@ -693,7 +783,7 @@ public class AudiobookRecorder extends JFrame {
});
del.addActionListener(new ActionListener() {
JMenuObject del = new JMenuObject("Delete phrase", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject();
@@ -704,14 +794,17 @@ public class AudiobookRecorder extends JFrame {
}
});
rec.addActionListener(new ActionListener() {
JMenuObject dup = new JMenuObject("Duplicate phrase", s, new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
JMenuObject o = (JMenuObject)e.getSource();
Sentence s = (Sentence)o.getObject();
if (!s.isLocked()) {
s.setText("[recognising...]");
bookTreeModel.reload(s);
s.recognise();
Sentence newSentence = s.cloneSentence();
Chapter c = (Chapter)s.getParent();
int idx = bookTreeModel.getIndexOfChild(c, s);
bookTreeModel.insertNodeInto(newSentence, c, idx);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
@@ -726,67 +819,44 @@ public class AudiobookRecorder extends JFrame {
menu.addSeparator();
menu.add(ins);
menu.add(del);
menu.addSeparator();
menu.add(dup);
menu.show(bookTree, e.getX(), e.getY());
} else if (node instanceof Chapter) {
Chapter c = (Chapter)node;
int idNumber = Utils.s2i(c.getId());
bookTree.setSelectionPath(new TreePath(c.getPath()));
JPopupMenu menu = new JPopupMenu();
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c);
JMenuObject moveUp = new JMenuObject("Move Up", c);
JMenuObject moveDown = new JMenuObject("Move Down", c);
JMenu mergeWith = new JMenu("Merge chapter with");
JMenuObject lockAll = new JMenuObject("Lock all sentences", c);
JMenuObject unlockAll = new JMenuObject("Unlock all sentences", c);
JMenuObject exportChapter = new JMenuObject("Export chapter", c);
JMenuObject deleteChapter = new JMenuObject("Delete chapter", c);
exportChapter.addActionListener(new ActionListener() {
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject();
ExportDialog ed = new ExportDialog("Exporting " + chap.getName());
ExportThread t = new ExportThread(chap, ed);
Thread nt = new Thread(t);
nt.start();
ed.setVisible(true);
Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
snt.autoTrimSamplePeak();
}
}
}
});
for (Enumeration bc = book.children(); bc.hasMoreElements();) {
Chapter chp = (Chapter)bc.nextElement();
if (chp.getId().equals(c.getId())) {
continue;
}
JMenuObject2 m = new JMenuObject2(chp.getName(), c, chp);
m.addActionListener(new ActionListener() {
JMenuObject fft = new JMenuObject("Auto-trim all (FFT)", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject2 ob = (JMenuObject2)e.getSource();
Chapter source = (Chapter)ob.getObject1();
Chapter target = (Chapter)ob.getObject2();
DefaultMutableTreeNode n = source.getFirstLeaf();
while (n instanceof Sentence) {
bookTreeModel.removeNodeFromParent(n);
bookTreeModel.insertNodeInto(n, target, target.getChildCount());
n = source.getFirstLeaf();
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
snt.autoTrimSampleFFT();
}
}
}
});
mergeWith.add(m);
}
int idNumber = Utils.s2i(c.getId());
moveUp.setEnabled(idNumber > 0);
moveDown.setEnabled(idNumber > 0);
moveUp.addActionListener(new ActionListener() {
JMenuObject moveUp = new JMenuObject("Move Up", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject();
@@ -805,7 +875,9 @@ public class AudiobookRecorder extends JFrame {
book.renumberChapters();
}
});
moveDown.addActionListener(new ActionListener() {
moveUp.setEnabled(idNumber > 0);
JMenuObject moveDown = new JMenuObject("Move Down", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject();
@@ -825,21 +897,32 @@ public class AudiobookRecorder extends JFrame {
book.renumberChapters();
}
});
moveDown.setEnabled(idNumber > 0);
peak.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
for (Enumeration s = c.children(); s.hasMoreElements();) {
Sentence snt = (Sentence)s.nextElement();
if (!snt.isLocked()) {
snt.autoTrimSamplePeak();
JMenu mergeWith = new JMenu("Merge chapter with");
for (Enumeration bc = book.children(); bc.hasMoreElements();) {
Chapter chp = (Chapter)bc.nextElement();
if (chp.getId().equals(c.getId())) {
continue;
}
JMenuObject2 m = new JMenuObject2(chp.getName(), c, chp, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject2 ob = (JMenuObject2)e.getSource();
Chapter source = (Chapter)ob.getObject1();
Chapter target = (Chapter)ob.getObject2();
DefaultMutableTreeNode n = source.getFirstLeaf();
while (n instanceof Sentence) {
bookTreeModel.removeNodeFromParent(n);
bookTreeModel.insertNodeInto(n, target, target.getChildCount());
n = source.getFirstLeaf();
}
}
});
mergeWith.add(m);
}
lockAll.addActionListener(new ActionListener() {
JMenuObject lockAll = new JMenuObject("Lock all phrases", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
@@ -850,7 +933,8 @@ public class AudiobookRecorder extends JFrame {
}
}
});
unlockAll.addActionListener(new ActionListener() {
JMenuObject unlockAll = new JMenuObject("Unlock all phrases", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
@@ -862,7 +946,21 @@ public class AudiobookRecorder extends JFrame {
}
});
deleteChapter.addActionListener(new ActionListener() {
JMenuObject exportChapter = new JMenuObject("Export chapter", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter chap = (Chapter)o.getObject();
ProgressDialog ed = new ProgressDialog("Exporting " + chap.getName());
ExportThread t = new ExportThread(chap, ed);
Thread nt = new Thread(t);
nt.start();
ed.setVisible(true);
}
});
JMenuObject deleteChapter = new JMenuObject("Delete chapter", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
@@ -879,13 +977,25 @@ public class AudiobookRecorder extends JFrame {
}
});
JMenuObject convertAll = new JMenuObject("Detect all text", c, new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuObject o = (JMenuObject)e.getSource();
Chapter c = (Chapter)o.getObject();
BatchConversionThread r = new BatchConversionThread(c);
Thread t = new Thread(r);
t.start();
}
});
menu.add(convertAll);
menu.addSeparator();
menu.add(moveUp);
menu.add(moveDown);
menu.addSeparator();
menu.add(mergeWith);
menu.addSeparator();
menu.add(peak);
menu.add(fft);
menu.addSeparator();
menu.add(lockAll);
menu.add(unlockAll);
@@ -933,6 +1043,59 @@ public class AudiobookRecorder extends JFrame {
}
}
public void startRecordingShort() {
if (recording != null) return;
if (book == null) return;
if (microphone == null) {
JOptionPane.showMessageDialog(this, "Microphone not started. Start microphone first.", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
toolBar.disableBook();
toolBar.disableSentence();
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)bookTree.getLastSelectedPathComponent();
if (selectedNode == null) {
selectedNode = book.getLastChapter();
bookTree.setSelectionPath(new TreePath(selectedNode.getPath()));
}
if (selectedNode instanceof Book) {
selectedNode = book.getLastChapter();
bookTree.setSelectionPath(new TreePath(selectedNode.getPath()));
}
if (selectedNode instanceof Sentence) {
selectedNode = (DefaultMutableTreeNode)selectedNode.getParent();
bookTree.setSelectionPath(new TreePath(selectedNode.getPath()));
}
Chapter c = (Chapter)selectedNode;
DefaultMutableTreeNode lastLeaf = c.getLastLeaf();
if (lastLeaf instanceof Sentence) {
Sentence lastSentence = (Sentence)lastLeaf;
lastSentence.setPostGap(Options.getInteger("catenation.short-sentence"));
}
Sentence s = new Sentence();
bookTreeModel.insertNodeInto(s, c, c.getChildCount());
bookTree.expandPath(new TreePath(c.getPath()));
bookTree.setSelectionPath(new TreePath(s.getPath()));
bookTree.scrollPathToVisible(new TreePath(s.getPath()));
if (s.startRecording()) {
recording = s;
centralPanel.setFlash(true);
}
}
public void startRecordingNewParagraph() {
if (recording != null) return;
@@ -1384,6 +1547,7 @@ public class AudiobookRecorder extends JFrame {
int r = JOptionPane.showConfirmDialog(this, info, "Open Book", JOptionPane.OK_CANCEL_OPTION);
if (r == JOptionPane.OK_OPTION) {
File f = info.getSelectedFile();
if (f == null) return;
if (!f.exists()) {
JOptionPane.showMessageDialog(this, "File not found.", "Error", JOptionPane.ERROR_MESSAGE);
return;
@@ -1431,7 +1595,7 @@ public class AudiobookRecorder extends JFrame {
}
ms *= 10;
ms /= 9;
ms /= 7;
return ms;
}
@@ -1460,21 +1624,52 @@ public class AudiobookRecorder extends JFrame {
}
}
public void playSelectedSentence() {
if (selectedSentence == null) return;
if (playing != null) return;
if (getNoiseFloor() == 0) {
alertNoRoomNoise();
return;
}
playing = selectedSentence;
toolBar.disableSentence();
toolBar.enableStop();
playingThread = new Thread(new Runnable() {
public void run() {
playing.play();
Sentence s = playing;
byte[] data;
try {
AudioFormat format = s.getAudioFormat();
play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
play.open(format);
play.start();
bookTree.scrollPathToVisible(new TreePath(s.getPath()));
data = s.getRawAudioData();
for (int pos = 0; pos < data.length; pos += 1024) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos;
if (l > 1024) l = 1024;
play.write(data, pos, l);
}
play.drain();
play.stop();
play.close();
play = null;
} catch (Exception e) {
playing = null;
if (play != null) {
play.drain();
play.stop();
play.close();
}
play = null;
}
toolBar.enableSentence();
toolBar.disableStop();
}
@@ -1482,14 +1677,13 @@ public class AudiobookRecorder extends JFrame {
playingThread.setDaemon(true);
playingThread.start();
}
class ExportThread implements Runnable {
ExportDialog exportDialog;
ProgressDialog exportDialog;
Chapter chapter;
public ExportThread(Chapter c, ExportDialog e) {
public ExportThread(Chapter c, ProgressDialog e) {
super();
exportDialog = e;
chapter = c;
@@ -1514,7 +1708,7 @@ public class AudiobookRecorder extends JFrame {
for (Enumeration o = book.children(); o.hasMoreElements();) {
Chapter c = (Chapter)o.nextElement();
ExportDialog ed = new ExportDialog("Exporting " + c.getName());
ProgressDialog ed = new ProgressDialog("Exporting " + c.getName());
ExportThread t = new ExportThread(c, ed);
Thread nt = new Thread(t);
@@ -1563,7 +1757,12 @@ public class AudiobookRecorder extends JFrame {
play.write(data, 0, data.length);
}
data = s.getRawAudioData();
play.write(data, 0, data.length);
for (int pos = 0; pos < data.length; pos += 1024) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos;
if (l > 1024) l = 1024;
play.write(data, pos, l);
}
DefaultMutableTreeNode next = s.getNextSibling();
boolean last = false;
@@ -1653,6 +1852,7 @@ public class AudiobookRecorder extends JFrame {
equaliserWindow.pack();
}
equaliserWindow.setVisible(true);
equaliserWindow.setLocationRelativeTo(this);
}
public boolean enableMicrophone() {
@@ -1706,9 +1906,12 @@ public class AudiobookRecorder extends JFrame {
String[] lines = s.split("\n");
for (String line : lines) {
line = line.trim();
try {
if (!line.equals("")) {
Process p = Runtime.getRuntime().exec(line);
p.waitFor();
}
} catch (Exception e) {
e.printStackTrace();
}
@@ -1778,7 +1981,6 @@ public class AudiobookRecorder extends JFrame {
public void mergeChapter(Properties prefs, String chid) {
Chapter c = book.addChapter();
System.err.println("Added chapter " + c.getId());
c.setName("Merged-" + prefs.getProperty("chapter." + chid + ".name"));
c.setPostGap(Utils.s2i(prefs.getProperty("chapter." + chid + ".post-gap")));
c.setPreGap(Utils.s2i(prefs.getProperty("chapter." + chid + ".pre-gap")));
@@ -1820,6 +2022,241 @@ System.err.println("Added chapter " + c.getId());
}
ArrayList<File> gatherFiles(File root) {
ArrayList<File> fileList = new ArrayList<File>();
File[] files = root.listFiles();
for (File f : files) {
if (f.getName().startsWith(".")) continue;
if (!f.isDirectory()) {
fileList.add(f);
}
}
for (File f : files) {
if (f.getName().startsWith(".")) continue;
if (f.isDirectory()) {
fileList.add(f);
fileList.addAll(gatherFiles(f));
}
}
return fileList;
}
public class ArchiveBookThread implements Runnable {
ProgressDialog pd;
public ArchiveBookThread(ProgressDialog p) {
pd = p;
}
public void run() {
try {
String name = AudiobookRecorder.this.book.getName();
File storageDir = new File(Options.get("path.storage"));
File bookDir = new File(storageDir, name);
File archiveDir = new File(storageDir, "archive");
ArrayList<File> fileList = gatherFiles(bookDir);
if (!archiveDir.exists()) {
archiveDir.mkdirs();
}
File archiveFile = new File(archiveDir, name + ".abz");
System.err.println("Archiving to " + archiveFile.getAbsolutePath());
if (archiveFile.exists()) {
archiveFile.delete();
}
FileOutputStream fos = new FileOutputStream(archiveFile);
ZipOutputStream zos = new ZipOutputStream(fos);
zos.putNextEntry(new ZipEntry(name + "/"));
zos.closeEntry();
int numFiles = fileList.size();
int fileNo = 0;
String prefix = storageDir.getAbsolutePath();
for (File f : fileList) {
fileNo++;
int pct = fileNo * 2000 / numFiles;
pd.setProgress(pct);
String path = f.getAbsolutePath().substring(prefix.length() + 1);
if (f.isDirectory()) {
ZipEntry entry = new ZipEntry(path + "/");
zos.putNextEntry(entry);
zos.closeEntry();
} else {
ZipEntry entry = new ZipEntry(path);
entry.setSize(f.length());
entry.setTime(f.lastModified());
zos.putNextEntry(entry);
FileInputStream fis = new FileInputStream(f);
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = fis.read(buffer, 0, 1024)) != -1) {
zos.write(buffer, 0, bytesRead);
}
fis.close();
zos.closeEntry();
}
}
zos.flush();
zos.close();
while (fileList.size() > 0) {
File f = fileList.remove(fileList.size() - 1);
f.delete();
}
} catch (Exception e) {
}
pd.closeDialog();
}
}
public void archiveBook() {
int r = JOptionPane.showConfirmDialog(this, "This will stash the current book away\nin the archives folder in a compressed\nform. The existing book files will be deleted\nand the book closed.\n\nAre you sure you want to do this?", "Archive Book", JOptionPane.OK_CANCEL_OPTION);
if (r == JOptionPane.OK_OPTION) {
ProgressDialog pd = new ProgressDialog("Archiving book...");
saveBookStructure();
ArchiveBookThread runnable = new ArchiveBookThread(pd);
Thread t = new Thread(runnable);
t.start();
pd.setVisible(true);
book = null;
bookTree = null;
mainScroll.setViewportView(null);
}
}
public void openArchive() {
JFileChooser jc = new JFileChooser(new File(Options.get("path.storage"), "archive"));
FileNameExtensionFilter filter = new FileNameExtensionFilter("Audiobook Archives", "abz");
jc.addChoosableFileFilter(filter);
jc.setFileFilter(filter);
jc.setDialogTitle("Select Audiobook Archive");
int r = jc.showOpenDialog(this);
if (r == JFileChooser.APPROVE_OPTION) {
File f = jc.getSelectedFile();
if (f.exists()) {
try {
ZipInputStream zis = new ZipInputStream(new FileInputStream(f)) {
public void close() throws IOException {
return;
}
};
ZipEntry entry = null;
ImageIcon cover = null;
Properties props = new Properties();
boolean gotMeta = false;
boolean gotCover = false;
while ((entry = zis.getNextEntry()) != null) {
if (gotMeta && gotCover) break;
if (entry.getName().endsWith("/audiobook.abk")) {
props.loadFromXML(zis);
gotMeta = true;
}
if (
entry.getName().endsWith("/coverart.png") ||
entry.getName().endsWith("/coverart.jpg") ||
entry.getName().endsWith("/coverart.gif")
) {
cover = new ImageIcon(ImageIO.read(zis));
gotCover = true;
}
}
zis.close();
BookPanel pan = new BookPanel(props, cover);
int okToImport = JOptionPane.showConfirmDialog(this, pan, "Import this book?", JOptionPane.OK_CANCEL_OPTION);
if (okToImport == JOptionPane.OK_OPTION) {
zis = new ZipInputStream(new FileInputStream(f));
while ((entry = zis.getNextEntry()) != null) {
File out = new File(Options.get("path.storage"), entry.getName());
if (entry.isDirectory()) {
out.mkdirs();
} else {
byte[] buffer = new byte[1024];
int nr;
FileOutputStream fos = new FileOutputStream(out);
while ((nr = zis.read(buffer, 0, 1024)) > 0) {
fos.write(buffer, 0, nr);
}
fos.close();
}
}
zis.close();
File bookdir = new File(Options.get("path.storage"), props.getProperty("book.name"));
File conf = new File(bookdir, "audiobook.abk");
loadBookStructure(conf);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public void loadCoverArt() {
if (book == null) return;
JFileChooser jc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Image Files", "png", "jpg", "gif");
jc.addChoosableFileFilter(filter);
jc.setFileFilter(filter);
jc.setDialogTitle("Select coverart image");
int r = jc.showOpenDialog(this);
if (r == JFileChooser.APPROVE_OPTION) {
File src = jc.getSelectedFile();
if (src.exists()) {
File dest = null;
File bookFolder = new File(Options.get("path.storage"), book.getName());
if (src.getName().endsWith(".png")) {
dest = new File(bookFolder, "coverart.png");
} else if (src.getName().endsWith(".jpg")) {
dest = new File(bookFolder, "coverart.jpg");
} else if (src.getName().endsWith(".gif")) {
dest = new File(bookFolder, "coverart.gif");
}
if (dest == null) {
JOptionPane.showMessageDialog(this, "Invalid image format or filename", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
new File(bookFolder, "coverart.png").delete();
new File(bookFolder, "coverart.jpg").delete();
new File(bookFolder, "coverart.gif").delete();
Files.copy(src.toPath(), dest.toPath());
ImageIcon i = new ImageIcon(dest.getAbsolutePath());
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
book.setIcon(new ImageIcon(ri));
bookTreeModel.reload(book);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}

View File

@@ -28,16 +28,35 @@ public class BookPanel extends JPanel {
boolean highlight = false;
public BookPanel(Properties p, ImageIcon i) {
loadBookData(p, i);
}
public BookPanel(File r) {
try {
root = r;
Properties props = new Properties();
props.loadFromXML(new FileInputStream(new File(root, "audiobook.abk")));
loadBookData(props, null);
} catch (Exception e) {
e.printStackTrace();
}
}
public void loadBookData(Properties props, ImageIcon i) {
try {
name = props.getProperty("book.name");
author = props.getProperty("book.author");
genre = props.getProperty("book.genre");
comment = props.getProperty("book.comment");
if (i == null) {
File icon = new File(root, "coverart.png");
if (!icon.exists()) {
icon = new File(root, "coverart.jpg");
}
if (!icon.exists()) {
icon = new File(root, "coverart.gif");
}
if (icon.exists()) {
cover = new ImageIcon(icon.getAbsolutePath());
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
@@ -47,6 +66,11 @@ public class BookPanel extends JPanel {
resizedCover = null;
iconLabel = new JLabel("");
}
} else {
cover = i;
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
iconLabel = new JLabel(new ImageIcon(resizedCover));
}
iconLabel.setSize(new Dimension(75, 75));
iconLabel.setPreferredSize(new Dimension(75, 75));

View File

@@ -23,6 +23,7 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
if (s.isInSample()) {
ret.setIcon(Icons.star);
}
} else if (value instanceof Chapter) {
ret.setIcon(Icons.chapter);
} else if (value instanceof Book) {

View File

@@ -81,7 +81,7 @@ public class Chapter extends DefaultMutableTreeNode {
}
@SuppressWarnings("unchecked")
public void exportChapter(ExportDialog exportDialog) throws
public void exportChapter(ProgressDialog exportDialog) throws
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
EncoderException, UnsupportedTagException, InvalidDataException {
@@ -200,4 +200,18 @@ public class Chapter extends DefaultMutableTreeNode {
wavFile.delete();
}
public double getChapterLength() {
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
for (Enumeration s = children(); s.hasMoreElements();) {
Sentence sentence = (Sentence)s.nextElement();
totalTime += sentence.getLength();
if (s.hasMoreElements()) {
totalTime += (sentence.getPostGap() / 1000d);
} else {
totalTime += Options.getInteger("audio.recording.post-chapter") / 1000d;
}
}
return totalTime;
}
}

View File

@@ -0,0 +1,56 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.net.*;
public class DonationPanel extends JPanel {
public DonationPanel() {
super();
setLayout(new BorderLayout());
JLabel icon = new JLabel(Icons.dollar);
icon.setBorder(new EmptyBorder(10, 10, 10, 10));
add(icon, BorderLayout.WEST);
JTextArea label = new JTextArea(
"Thank you for using AudiobookRecorder by\n" +
"Majenko Technologies. This software is\n" +
"Free Open Source Software (FOSS). It is\n" +
"created and maintained voluntarily with\n" +
"no possibility of any profits from it.\n" +
"If you enjoy using this software and end\n" +
"up making millions of dollars from using\n" +
"it we hope that you would maybe kindly\n" +
"donate a couple of those dollars to the\n" +
"developer to help with the costs of maintaining\n" +
"the software.\n" +
"\n" +
"You can donate by going to:\n" +
"\n" +
"https://paypal.me/majenko"
);
label.setEditable(false);
label.setFocusable(false);
label.setBorder(new EmptyBorder(10, 10, 10, 10));
add(label, BorderLayout.CENTER);
JButton donate = new JButton("Donate!");
donate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().browse(new URI("https://paypal.me/majenko"));
} catch (Exception ex) {
}
}
}
});
add(donate, BorderLayout.SOUTH);
}
}

View File

@@ -30,4 +30,5 @@ public class Icons {
static public final ImageIcon mic = new ImageIcon(Icons.class.getResource("icons/mic.png"));
static public final ImageIcon zoomIn = new ImageIcon(Icons.class.getResource("icons/zoom-in.png"));
static public final ImageIcon zoomOut = new ImageIcon(Icons.class.getResource("icons/zoom-out.png"));
static public final ImageIcon dollar = new ImageIcon(Icons.class.getResource("icons/dollar.png"));
}

View File

@@ -0,0 +1,21 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class JButtonSpacePlay extends JButton {
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
super(i);
getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
"startPlayback"
);
setToolTipText(tt);
addActionListener(al);
setFocusPainted(false);
setFocusable(false);
}
}

View File

@@ -0,0 +1,21 @@
package uk.co.majenko.audiobookrecorder;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class JToggleButtonSpacePlay extends JToggleButton {
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
super(i);
getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0),
"startPlayback"
);
setToolTipText(tt);
addActionListener(al);
setFocusPainted(false);
setFocusable(false);
}
}

View File

@@ -7,15 +7,15 @@ import java.awt.event.*;
public class MainToolBar extends JToolBar {
JButton newBook;
JButton openBook;
JButton saveBook;
JButton newChapter;
JButton recordRoomNoise;
JButton playSentence;
JButton playonSentence;
JButton stopPlaying;
JButton eq;
JButtonSpacePlay newBook;
JButtonSpacePlay openBook;
JButtonSpacePlay saveBook;
JButtonSpacePlay newChapter;
JButtonSpacePlay recordRoomNoise;
JButtonSpacePlay playSentence;
JButtonSpacePlay playonSentence;
JButtonSpacePlay stopPlaying;
JButtonSpacePlay eq;
JToggleButton mic;
AudiobookRecorder root;
@@ -25,27 +25,21 @@ public class MainToolBar extends JToolBar {
root = r;
newBook = new JButton(Icons.newBook);
newBook.setToolTipText("New Book");
newBook.addActionListener(new ActionListener() {
newBook = new JButtonSpacePlay(Icons.newBook, "New Book", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.createNewBook();
}
});
add(newBook);
openBook = new JButton(Icons.openBook);
openBook.setToolTipText("Open Book");
openBook.addActionListener(new ActionListener() {
openBook = new JButtonSpacePlay(Icons.openBook, "Open Book", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.openBook();
}
});
add(openBook);
saveBook = new JButton(Icons.save);
saveBook.setToolTipText("Save Book");
saveBook.addActionListener(new ActionListener() {
saveBook = new JButtonSpacePlay(Icons.save, "Save Book", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.saveBookStructure();
}
@@ -54,18 +48,14 @@ public class MainToolBar extends JToolBar {
addSeparator();
newChapter = new JButton(Icons.newChapter);
newChapter.setToolTipText("New Chapter");
newChapter.addActionListener(new ActionListener() {
newChapter = new JButtonSpacePlay(Icons.newChapter, "New Chapter", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.addChapter();
}
});
add(newChapter);
recordRoomNoise = new JButton(Icons.recordRoom);
recordRoomNoise.setToolTipText("Record Room Noise");
recordRoomNoise.addActionListener(new ActionListener() {
recordRoomNoise = new JButtonSpacePlay(Icons.recordRoom, "Record Room Noise", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.recordRoomNoise();
}
@@ -74,27 +64,21 @@ public class MainToolBar extends JToolBar {
addSeparator();
playSentence = new JButton(Icons.play);
playSentence.setToolTipText("Play sentence");
playSentence.addActionListener(new ActionListener() {
playSentence = new JButtonSpacePlay(Icons.play, "Play sentence", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.playSelectedSentence();
}
});
add(playSentence);
playonSentence = new JButton(Icons.playon);
playonSentence.setToolTipText("Play from sentence");
playonSentence.addActionListener(new ActionListener() {
playonSentence = new JButtonSpacePlay(Icons.playon, "Play from sentence", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.playFromSelectedSentence();
}
});
add(playonSentence);
stopPlaying = new JButton(Icons.stop);
stopPlaying.setToolTipText("Stop playing / recording");
stopPlaying.addActionListener(new ActionListener() {
stopPlaying = new JButtonSpacePlay(Icons.stop, "Stop playing", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.stopPlaying();
}
@@ -102,9 +86,7 @@ public class MainToolBar extends JToolBar {
add(stopPlaying);
addSeparator();
eq = new JButton(Icons.eq);
eq.setToolTipText("Equaliser");
eq.addActionListener(new ActionListener() {
eq = new JButtonSpacePlay(Icons.eq, "Equaliser", new ActionListener() {
public void actionPerformed(ActionEvent e) {
root.showEqualiser();
}
@@ -114,17 +96,24 @@ public class MainToolBar extends JToolBar {
addSeparator();
mic = new JToggleButton(Icons.mic);
mic.setToolTipText("Enable/disable microphone");
mic.addActionListener(new ActionListener() {
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
Color bgCol = null;
public void actionPerformed(ActionEvent e) {
JToggleButton b = (JToggleButton)e.getSource();
if (b.isSelected()) {
if (!root.enableMicrophone()) {
b.setSelected(false);
} else {
if (bgCol == null) {
bgCol = b.getBackground();
}
b.setBackground(Color.RED);
}
} else {
root.disableMicrophone();
if (bgCol != null) {
b.setBackground(bgCol);
}
}
}
});

View File

@@ -20,10 +20,12 @@ public class Options extends JDialog {
JComboBox<KVPair> channelList;
JComboBox<KVPair> rateList;
JComboBox<KVPair> bitDepth;
JComboBox<KVPair> trimMethod;
JTextField storageFolder;
JSpinner preChapterGap;
JSpinner postChapterGap;
JSpinner postSentenceGap;
JSpinner shortSentenceGap;
JSpinner postParagraphGap;
JTextField ffmpegLocation;
JComboBox<KVPair> bitRate;
@@ -247,6 +249,7 @@ public class Options extends JDialog {
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"));
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
addSeparator(optionsPanel);
@@ -259,6 +262,7 @@ public class Options extends JDialog {
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms");
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms");
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
addSeparator(optionsPanel);
@@ -444,6 +448,7 @@ public class Options extends JDialog {
defaultPrefs.put("audio.recording.channels", "2");
defaultPrefs.put("audio.recording.samplerate", "44100");
defaultPrefs.put("audio.recording.resolution", "16");
defaultPrefs.put("audio.recording.trim", "peak");
if (playbackMixers.length > 0) {
defaultPrefs.put("audio.playback.device", playbackMixers[0].key);
} else {
@@ -453,6 +458,7 @@ public class Options extends JDialog {
defaultPrefs.put("catenation.pre-chapter", "1000");
defaultPrefs.put("catenation.post-chapter", "1500");
defaultPrefs.put("catenation.post-sentence", "1000");
defaultPrefs.put("catenation.short-sentence", "100");
defaultPrefs.put("catenation.post-paragraph", "2000");
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
@@ -589,12 +595,14 @@ public class Options extends JDialog {
set("audio.recording.channels", ((KVPair)channelList.getSelectedItem()).key);
set("audio.recording.samplerate", ((KVPair)rateList.getSelectedItem()).key);
set("audio.recording.resolution", ((KVPair)bitDepth.getSelectedItem()).key);
set("audio.recording.trim", ((KVPair)trimMethod.getSelectedItem()).key);
set("audio.playback.device", ((KVPair)playbackList.getSelectedItem()).key);
set("path.storage", storageFolder.getText());
set("path.ffmpeg", ffmpegLocation.getText());
set("catenation.pre-chapter", preChapterGap.getValue());
set("catenation.post-chapter", postChapterGap.getValue());
set("catenation.post-sentence", postSentenceGap.getValue());
set("catenation.short-sentence", shortSentenceGap.getValue());
set("catenation.post-paragraph", postParagraphGap.getValue());
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
@@ -652,4 +660,11 @@ public class Options extends JDialog {
pairs[0] = new KVPair("16", "16 Bit");
return pairs;
}
public static KVPair[] getTrimMethods() {
KVPair[] pairs = new KVPair[2];
pairs[0] = new KVPair("peak", "Peak Amplitude");
pairs[1] = new KVPair("fft", "FFT Analysis");
return pairs;
}
}

View File

@@ -8,7 +8,7 @@ import java.awt.event.*;
import java.util.*;
import it.sauronsoftware.jave.*;
public class ExportDialog extends JDialog implements EncoderProgressListener {
public class ProgressDialog extends JDialog implements EncoderProgressListener {
JLabel message;
JLabel icon;
@@ -18,7 +18,7 @@ public class ExportDialog extends JDialog implements EncoderProgressListener {
public ExportDialog(String m) {
public ProgressDialog(String m) {
super();
setModalityType(Dialog.ModalityType.APPLICATION_MODAL);

View File

@@ -35,6 +35,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
TargetDataLine line;
AudioInputStream inputStream;
AudioFormat storedFormat = null;
double storedLength = -1d;
int[] storedAudioData = null;
@@ -147,9 +149,16 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
}
storedAudioData = null;
storedFormat = null;
storedLength = -1;
if (!id.equals("room-noise")) {
String tm = Options.get("audio.recording.trim");
if (tm.equals("peak")) {
autoTrimSamplePeak();
} else if (tm.equals("fft")) {
autoTrimSampleFFT();
}
if (Options.getBoolean("process.sphinx")) {
recognise();
}
@@ -256,6 +265,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
end = i;
}
end++;
if (end <= 0) {
end = blocks - 1;
}
@@ -413,7 +424,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
File f = getFile();
try {
AudioInputStream s = AudioSystem.getAudioInputStream(f);
AudioFormat format = s.getFormat();
AudioFormat format = getAudioFormat();
int[] samples = null;
@@ -495,7 +506,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
try {
AudioInputStream s = AudioSystem.getAudioInputStream(f);
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
AudioFormat format = eq.getFormat();
AudioFormat format = getAudioFormat();
IIRControls controls = eq.getControls();
AudiobookRecorder.window.book.equaliser.apply(controls, format.getChannels());
@@ -511,56 +522,20 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
}
public AudioFormat getAudioFormat() {
if (storedFormat != null) return storedFormat;
File f = getFile();
try {
AudioInputStream s = AudioSystem.getAudioInputStream(f);
AudioFormat format = s.getFormat();
return format;
storedFormat = s.getFormat();
s.close();
return storedFormat;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public void play() {
File f = getFile();
try {
AudioInputStream s = AudioSystem.getAudioInputStream(f);
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
AudioFormat format = eq.getFormat();
IIRControls controls = eq.getControls();
AudiobookRecorder.window.book.equaliser.apply(controls, format.getChannels());
int frameSize = format.getFrameSize();
updateCrossings();
int pos = crossStartOffset * frameSize;
SourceDataLine play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
play.open(format);
play.start();
byte[] buffer = new byte[1024];
eq.skip(pos);
while (pos < crossEndOffset * frameSize) {
int nr = eq.read(buffer);
pos += nr;
play.write(buffer, 0, nr);
};
play.drain();
play.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public byte[] getRawAudioData() {
File f = getFile();
try {
@@ -569,7 +544,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
AudioFormat format = eq.getFormat();
AudioFormat format = getAudioFormat();
IIRControls controls = eq.getControls();
AudiobookRecorder.window.book.equaliser.apply(controls, format.getChannels());
@@ -599,27 +574,14 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
return null;
}
public void recognise() {
Thread t = new Thread(new Runnable() {
public void run() {
public void doRecognition(StreamSpeechRecognizer recognizer) {
try {
Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
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");
StreamSpeechRecognizer recognizer;
recognizer = new StreamSpeechRecognizer(sphinxConfig);
setText("[recognising...]");
AudiobookRecorder.window.bookTreeModel.reload(this);
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
AudioFormat format = s.getFormat();
AudioFormat format = getAudioFormat();
int frameSize = format.getFrameSize();
int length = (int)s.getFrameLength();
byte[] data = new byte[length * frameSize];
@@ -640,7 +602,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
}
}
ByteArrayInputStream bas = new ByteArrayInputStream(decimated);
recognizer.startRecognition(bas);
SpeechResult result;
@@ -654,11 +615,34 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
text = res;
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
} catch (Exception e) {
e.printStackTrace();
}
}
public void recognise() {
Thread t = new Thread(new Runnable() {
public void run() {
try {
Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
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() / 3f));
StreamSpeechRecognizer recognizer;
recognizer = new StreamSpeechRecognizer(sphinxConfig);
doRecognition(recognizer);
} catch (Exception e) {
e.printStackTrace();
}
}
});
@@ -727,4 +711,32 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
}
return pos;
}
/* Get the length of the sample in seconds */
public double getLength() {
if (storedLength > -1d) return storedLength;
AudioFormat format = getAudioFormat();
float sampleFrequency = format.getFrameRate();
int length = crossEndOffset - crossStartOffset;
double time = (double)length / (double)sampleFrequency;
storedLength = time;
return time;
}
public Sentence cloneSentence() throws IOException {
Sentence sentence = new Sentence();
sentence.setPostGap(getPostGap());
if (!id.equals(text)) {
sentence.setText(text);
}
sentence.setStartOffset(getStartOffset());
sentence.setEndOffset(getEndOffset());
File from = getFile();
File to = sentence.getFile();
Files.copy(from.toPath(), to.toPath());
sentence.updateCrossings();
return sentence;
}
}

View File

@@ -16,6 +16,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
int leftMarkerSaved = 0;
int rightMarkerSaved = 0;
int playMarker = 0;
int leftAltMarker = 0;
int rightAltMarker = 0;
@@ -126,6 +128,10 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
g.drawLine((leftMarker - offset)/step, 0, (leftMarker - offset)/step, h);
g.drawLine((rightMarker - offset)/step, 0, (rightMarker - offset)/step, h);
g.setColor(new Color(0, 255, 255));
for (int i = 0; i < h; i += 2) {
g.drawLine((playMarker - offset) / step, i, (playMarker - offset) / step, i);
}
}
}
@@ -168,6 +174,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
public void setData(int[] s) {
samples = s;
playMarker = 0;
repaint();
}
@@ -185,13 +192,13 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
public void mousePressed(MouseEvent e) {
int x = e.getX();
if ((x >= ((leftMarker - offset)/step) - 2) && (x <= ((leftMarker - offset)/step) + 2)) {
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
leftMarkerSaved = leftMarker;
rightMarkerSaved = rightMarker;
dragging = 1;
return;
}
if ((x >= ((rightMarker - offset)/step) - 2) && (x <= ((rightMarker - offset)/step) + 2)) {
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
rightMarkerSaved = rightMarker;
leftMarkerSaved = leftMarker;
dragging = 2;
@@ -219,11 +226,11 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
public void mouseMoved(MouseEvent e) {
int x = e.getX();
if ((x >= ((leftMarker - offset)/step) - 2) && (x <= ((leftMarker - offset)/step) + 2)) {
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
return;
}
if ((x >= ((rightMarker - offset)/step) - 2) && (x <= ((rightMarker - offset)/step) + 2)) {
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
return;
}
@@ -271,4 +278,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
repaint();
}
public void setPlayMarker(int m) {
playMarker = leftAltMarker + m;
repaint();
}
}