Commit 376a523e authored by Oliver Adams's avatar Oliver Adams

Javadocing. Only 100 checkstyle errors to go.

parent 2170b4bc
......@@ -34,6 +34,15 @@ import org.lp20.aikuma.model.Recording;
public class PhoneRespeaker implements
AudioListener, AudioHandler, MicrophoneListener {
/**
* Constructor
*
* @param original The original recording.
* @param respeakingUUID The UUID of this respeaking.
* @param analyzer The analyzer that determines what audio constitutes
* speech.
* @throws MicException If there is an issue setting up the microphone.
* @throws IOException If there is an I/O issue.
public PhoneRespeaker(Recording original, UUID respeakingUUID,
Analyzer analyzer) throws MicException, IOException {
this.analyzer = analyzer;
......@@ -59,7 +68,12 @@ public class PhoneRespeaker implements
respeakingUUID + ".wav").getPath());
}
/** Sets the sensitivity of the respeaker to microphone noise */
/**
* Sets the sensitivity of the respeaker to microphone noise
*
* @param threshold The threshold above which audio is considered to be
* speech.
*/
public void setSensitivity(int threshold) {
this.analyzer = new ThresholdSpeechAnalyzer(88, 3,
new AverageRecognizer(threshold, threshold));
......@@ -69,7 +83,7 @@ public class PhoneRespeaker implements
this.player = new SimplePlayer(original, false);
}
/** Callback for the microphone */
@Override
public void onBufferFull(short[] buffer) {
// This will call back the methods:
// * silenceTriggered
......@@ -77,12 +91,18 @@ public class PhoneRespeaker implements
analyzer.analyze(this, buffer);
}
/**
* Resumes the phone respeaking process.
*/
public void resume() {
microphone.listen(this);
//mapper.markOriginal(player);
switchToPlay();
}
/**
* Halts the phone respeaking process, but allows for resumption.
*/
public void halt() {
mapper.store(player, file);
stopMic();
......@@ -90,6 +110,9 @@ public class PhoneRespeaker implements
analyzer.reset();
}
/**
* Stops/finishes the phone respeaking process.
*/
public void stop() {
stopMic();
player.release();
......@@ -105,6 +128,7 @@ public class PhoneRespeaker implements
}
}
@Override
public void audioTriggered(short[] buffer, boolean justChanged) {
if (justChanged) {
switchToRecord();
......@@ -121,6 +145,7 @@ public class PhoneRespeaker implements
player.play();
}
@Override
public void silenceTriggered(short[] buffer, boolean justChanged) {
if (justChanged) {
mapper.store(player, file);
......@@ -133,6 +158,9 @@ public class PhoneRespeaker implements
}
}
/**
* Releases the resources associated with this respeaker.
*/
public void release() {
if (player != null) {
player.release();
......
......@@ -40,6 +40,11 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
/**
* Creates a Recorder that uses an analyzer which tells the recorder to
* always record regardless of input.
*
* @param path The path to the file where the recording will be stored
* @param sampleRate The sample rate that the recording should be taken
* at.
* @throws MicException If there is an issue setting up the microphone.
*/
public Recorder(File path, long sampleRate) throws MicException {
this(path, sampleRate, new SimpleAnalyzer());
......@@ -57,11 +62,13 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
*/
/**
* Accepts and analyzer that decides whether the recorder should record or
* ignore the input
* Constructor
*
* @param Pass in an analyzer which decides whether
* the recorder should record or ignore the input.
* @param path The path to where the recording should be stored.
* @param sampleRate The sample rate the recording should be taken at.
* @param analyzer The analyzer that determines whether the recorder
* should record or ignore the input
* @throws MicException If there is an issue setting up the microphone.
*/
public Recorder(File path, long sampleRate, Analyzer analyzer) throws MicException {
this.analyzer = analyzer;
......@@ -129,31 +136,44 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
);
}
/** Stop listening to the microphone and close the file.
/**
* Stop listening to the microphone and close the file.
*
* Note: Once stopped you cannot restart the recorder.
*
* @throws MicException If there was an issue stopping the microphone.
*/
public void stop() throws MicException {
microphone.stop();
file.close();
}
/**
* Release resources associated with this recorder.
*/
public void release() {
if (microphone != null) {
microphone.release();
}
}
/** Pause listening to the microphone. */
/**
* Pause listening to the microphone.
*
* @throws MicException If there was an issue stopping the microphone.
*/
public void pause() throws MicException {
//Log.e("beep", "what", new Throwable());
microphone.stop();
/*
beeper.beep();
*/
}
/** Callback for the microphone */
/**
* Callback for the microphone.
*
* @param buffer The buffer containing audio data.
*/
public void onBufferFull(short[] buffer) {
// This will call back the methods:
// * silenceTriggered
......@@ -168,12 +188,23 @@ public class Recorder implements AudioHandler, MicrophoneListener, Sampler {
// If you need a different behaviour, override.
//
/** By default simply writes the buffer to the file. */
/**
* By default simply writes the buffer to the file.
* @param buffer The buffer containing the audio data.
* @param justChanged Indicates whether audio has just been triggered
* after a bout of silence.
*/
public void audioTriggered(short[] buffer, boolean justChanged) {
file.write(buffer);
}
/** Does nothing by default if silence is triggered. */
/**
* Does nothing by default if silence is triggered.
*
* @param buffer The buffer containing the audio data.
* @param justChanged Indicates whether silence has just been triggered
* after a bout of audio.
*/
public void silenceTriggered(short[] buffer, boolean justChanged) {
// Intentionally empty.
}
......
......@@ -34,6 +34,14 @@ import org.lp20.aikuma.model.Recording;
*/
public class ThumbRespeaker {
/**
* Constructor
*
* @param original The original recording to make a respeaking of.
* @param respeakingUUID The UUID of the respeaking we will create.
* @throws MicException If the microphone couldn't be used.
* @throws IOException If there is an I/O issue.
*/
public ThumbRespeaker(Recording original, UUID respeakingUUID)
throws MicException, IOException {
recorder = new Recorder(new File(Recording.getNoSyncRecordingsPath(),
......@@ -43,55 +51,75 @@ public class ThumbRespeaker {
setFinishedPlaying(false);
}
/*
public ThumbRespeaker(Context context) {
recorder = new Recorder(context);
player = new Player();
mapper = new Mapper();
setFinishedPlaying(false);
}
*/
/**
* Plays the original recording.
*/
public void playOriginal() {
player.seekToSample(mapper.getOriginalStartSample());
mapper.markOriginal(player);
player.play();
}
/**
* Pauses playing of the original recording.
*/
public void pauseOriginal() {
player.pause();
}
/**
* Activates recording of the respeaking.
*/
public void recordRespeaking() {
mapper.markRespeaking(player, recorder);
recorder.listen();
}
/**
* Pauses the respeaking process.
*
* @throws MicException If the micrphone recording couldn't be paused.
*/
public void pauseRespeaking() throws MicException {
recorder.pause();
mapper.store(player, recorder);
}
/**
* Stops/finishes the respeaking process
*
* @throws MicException If there is an issue stopping the microphone.
*/
public void stop() throws MicException {
recorder.stop();
player.pause();
mapper.stop();
}
/** finishedPlaying mutator */
public void setFinishedPlaying(boolean finishedPlaying) {
this.finishedPlaying = finishedPlaying;
}
public void setFinishedPlaying(boolean finishedPlaying) {
this.finishedPlaying = finishedPlaying;
}
public int getCurrentMsec() {
return recorder.getCurrentMsec();
}
/** finishedPlaying accessor */
/**
* finishedPlaying accessor
*
* @return true if the original recording has finished playing; false
* otherwise.
*/
public boolean getFinishedPlaying() {
return this.finishedPlaying;
}
/**
* Sets the callback to be run when the original recording has finished
* playing.
*
* @param ocl The callback to be played on completion.
*/
public void setOnCompletionListener(OnCompletionListener ocl) {
player.setOnCompletionListener(ocl);
}
......@@ -100,6 +128,9 @@ public class ThumbRespeaker {
return this.player;
}
/**
* Releases the resources associated with this respeaker.
*/
public void release() {
if (player != null) {
player.release();
......
......@@ -20,19 +20,28 @@ import org.lp20.aikuma.audio.record.analyzers.BackgroundNoiseListener;
* @author Oliver Adams <oliver.adams@gmail.com>
*/
public class BackgroundNoise {
/** The thing that extracts the level of background noise from the buffers*/
protected Noise thresholder;
/** The microphone used to gather the noise data. */
protected Microphone microphone;
protected float factor;
/**
* Constructor
*
* @param duration The duration of the noise
* @param sampleRate The sample rate of the noise.
* @throws MicException If there is an issue creating the microphone.
*/
public BackgroundNoise(int duration, long sampleRate) throws MicException {
this.thresholder = new Noise(duration);
this.microphone = new Microphone(sampleRate);
this.factor = 1.5f;
}
/**
* Tries to find a threshold value.
* Tries to find a meaningful threshold value to define speech with.
*
* @param listener The thing that will listen to the background noise.
*/
public void getThreshold(final BackgroundNoiseListener listener) {
// Try finding a stable background noise.
......@@ -52,7 +61,12 @@ public class BackgroundNoise {
}
});
}
/**
* Stops the microphone.
*
* @throws MicException If there is an issue stopping the microphone.
*/
public void stop() throws MicException {
microphone.stop();
}
......
......@@ -16,11 +16,15 @@ public interface BackgroundNoiseListener {
/**
* Quality will be a negative value getting closer and closer to 0 (higher is better).
*
* @param information Information about the background noise.
*/
public void noiseLevelQualityUpdated(Noise.Information information);
/**
* Level will be a positive value. This will be called once when it's found.
* Level will be a positive value; This will be called once when it's found.
*
* @param information Information about the background noise.
*/
public void noiseLevelFound(Noise.Information information);
......
......@@ -128,8 +128,13 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
this.recognizer = recognizer;
}
/** Does the given buffer trigger silence? */
/**
* Does the given buffer trigger silence?
*
* @param buffer The buffer to analyze
* @return true if the buffer represents silence; false otherwise.
*/
protected boolean doesTriggerSilence(short[] buffer) {
if (recognizer.isSilence(buffer)) {
silenceTriggers++;
......@@ -138,8 +143,13 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
}
return silenceTriggers > silenceTriggerAmount;
}
/** Does the given buffer trigger speech? */
/**
* Does the given buffer trigger speech?
*
* @param buffer The buffer to analyze
* @return true if the buffer represents speech; false otherwise.
*/
protected boolean doesTriggerSpeech(short[] buffer) {
if (recognizer.isSpeech(buffer)) {
speechTriggers++;
......@@ -148,8 +158,12 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
}
return speechTriggers > speechTriggerAmount;
}
/** Shifts off a piece of the onset buffer and adds the given buffer to the end. */
/**
* Shifts off a piece of the onset buffer and adds the given buffer to the end.
*
* @param buffer The buffer to be added.
*/
protected void shiftOnsetBufferWith(short[] buffer) {
onsetBuffer = Arrays.copyOfRange(onsetBuffer, buffer.length,
onsetBuffer.length);
......@@ -157,15 +171,22 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
addToOnsetBuffer(buffer);
}
/** Replaces the onset buffer with the given buffer. */
/**
* Replaces the onset buffer with the given buffer.
*
* @param buffer The buffer to replace the onset buffer with.
*/
protected void replaceOnsetBufferWith(short[] buffer) {
onsetBuffer = Arrays.copyOf(buffer, buffer.length);
}
/** Adds the given buffer to the after buffer.
*
* TODO Duplicate method. See addToOnsetBuffer.
*/
//TODO Duplicate method. See addToOnsetBuffer.
/**
* Adds the given buffer to the after buffer.
*
* @param buffer The buffer to be added.
*/
protected void addToAfterBuffer(short[] buffer) {
int offset = afterBuffer.length;
......@@ -185,10 +206,12 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
}
}
/** Adds the given buffer to the onset buffer.
*
* TODO Duplicate method. See addToAfterBuffer.
*/
//TODO Duplicate method. See addToAfterBuffer.
/**
* Adds the given buffer to the onset buffer.
*
* @param buffer The buffer to be added.
*/
public void addToOnsetBuffer(short[] buffer) {
int offset = onsetBuffer.length;
......@@ -218,7 +241,6 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
afterBuffer = new short[] {};
}
protected int speedCount;
/** Analyzes if there's speech.
*
......@@ -276,7 +298,6 @@ public class ThresholdSpeechAnalyzer extends Analyzer {
}
}
/** Mainly exposed for testing */
public short[] getOnsetBuffer() {
return onsetBuffer;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment