diff --git a/.classpath b/.classpath index 783b547..2594ec5 100644 --- a/.classpath +++ b/.classpath @@ -9,5 +9,6 @@ + diff --git a/all_records/Converted/10.flac b/all_records/Converted/10.flac deleted file mode 100644 index 7c4debf..0000000 Binary files a/all_records/Converted/10.flac and /dev/null differ diff --git a/all_records/Converted/10.wav b/all_records/Converted/10.wav new file mode 100644 index 0000000..048bf8e Binary files /dev/null and b/all_records/Converted/10.wav differ diff --git a/all_records/Converted/11.flac b/all_records/Converted/11.flac deleted file mode 100644 index 34606ac..0000000 Binary files a/all_records/Converted/11.flac and /dev/null differ diff --git a/all_records/Converted/11.wav b/all_records/Converted/11.wav new file mode 100644 index 0000000..ad543d8 Binary files /dev/null and b/all_records/Converted/11.wav differ diff --git a/all_records/Converted/12.flac b/all_records/Converted/12.flac deleted file mode 100644 index ad52bf4..0000000 Binary files a/all_records/Converted/12.flac and /dev/null differ diff --git a/all_records/Converted/12.wav b/all_records/Converted/12.wav new file mode 100644 index 0000000..92a221b Binary files /dev/null and b/all_records/Converted/12.wav differ diff --git a/all_records/Converted/13.flac b/all_records/Converted/13.flac deleted file mode 100644 index def3bd9..0000000 Binary files a/all_records/Converted/13.flac and /dev/null differ diff --git a/all_records/Converted/13.wav b/all_records/Converted/13.wav new file mode 100644 index 0000000..fe4332d Binary files /dev/null and b/all_records/Converted/13.wav differ diff --git a/all_records/Converted/14.flac b/all_records/Converted/14.flac deleted file mode 100644 index 8cfa51c..0000000 Binary files a/all_records/Converted/14.flac and /dev/null differ diff --git a/all_records/Converted/14.wav b/all_records/Converted/14.wav new file mode 100644 index 0000000..3ded175 Binary files /dev/null and b/all_records/Converted/14.wav differ diff --git a/all_records/Converted/15.flac b/all_records/Converted/15.flac deleted file mode 100644 index bfdd6e5..0000000 Binary files a/all_records/Converted/15.flac and /dev/null differ diff --git a/all_records/Converted/15.wav b/all_records/Converted/15.wav new file mode 100644 index 0000000..b215c6e Binary files /dev/null and b/all_records/Converted/15.wav differ diff --git a/all_records/Converted/16.flac b/all_records/Converted/16.flac deleted file mode 100644 index b20b5c0..0000000 Binary files a/all_records/Converted/16.flac and /dev/null differ diff --git a/all_records/Converted/16.wav b/all_records/Converted/16.wav new file mode 100644 index 0000000..0f17479 Binary files /dev/null and b/all_records/Converted/16.wav differ diff --git a/all_records/Converted/17.flac b/all_records/Converted/17.flac deleted file mode 100644 index e963498..0000000 Binary files a/all_records/Converted/17.flac and /dev/null differ diff --git a/all_records/Converted/17.wav b/all_records/Converted/17.wav new file mode 100644 index 0000000..8fcfe65 Binary files /dev/null and b/all_records/Converted/17.wav differ diff --git a/all_records/Converted/18.flac b/all_records/Converted/18.flac deleted file mode 100644 index fb4b2d8..0000000 Binary files a/all_records/Converted/18.flac and /dev/null differ diff --git a/all_records/Converted/18.wav b/all_records/Converted/18.wav new file mode 100644 index 0000000..0ffed0a Binary files /dev/null and b/all_records/Converted/18.wav differ diff --git a/all_records/Converted/19.flac b/all_records/Converted/19.flac deleted file mode 100644 index f2b00bc..0000000 Binary files a/all_records/Converted/19.flac and /dev/null differ diff --git a/all_records/Converted/19.wav b/all_records/Converted/19.wav new file mode 100644 index 0000000..ef17930 Binary files /dev/null and b/all_records/Converted/19.wav differ diff --git a/all_records/Converted/20.flac b/all_records/Converted/20.flac deleted file mode 100644 index a19df4e..0000000 Binary files a/all_records/Converted/20.flac and /dev/null differ diff --git a/all_records/Converted/20.wav b/all_records/Converted/20.wav new file mode 100644 index 0000000..d0bba1b Binary files /dev/null and b/all_records/Converted/20.wav differ diff --git a/all_records/Converted/21.flac b/all_records/Converted/21.flac deleted file mode 100644 index 05351e3..0000000 Binary files a/all_records/Converted/21.flac and /dev/null differ diff --git a/all_records/Converted/21.wav b/all_records/Converted/21.wav new file mode 100644 index 0000000..abe0dd3 Binary files /dev/null and b/all_records/Converted/21.wav differ diff --git a/all_records/Converted/22.flac b/all_records/Converted/22.flac deleted file mode 100644 index 78b7f3d..0000000 Binary files a/all_records/Converted/22.flac and /dev/null differ diff --git a/all_records/Converted/22.wav b/all_records/Converted/22.wav new file mode 100644 index 0000000..6adee37 Binary files /dev/null and b/all_records/Converted/22.wav differ diff --git a/all_records/Converted/23.flac b/all_records/Converted/23.flac deleted file mode 100644 index 2a81c7b..0000000 Binary files a/all_records/Converted/23.flac and /dev/null differ diff --git a/all_records/Converted/23.wav b/all_records/Converted/23.wav new file mode 100644 index 0000000..0928bc8 Binary files /dev/null and b/all_records/Converted/23.wav differ diff --git a/all_records/Converted/24.flac b/all_records/Converted/24.flac deleted file mode 100644 index 6382076..0000000 Binary files a/all_records/Converted/24.flac and /dev/null differ diff --git a/all_records/Converted/24.wav b/all_records/Converted/24.wav new file mode 100644 index 0000000..449cba4 Binary files /dev/null and b/all_records/Converted/24.wav differ diff --git a/all_records/Converted/25.flac b/all_records/Converted/25.flac deleted file mode 100644 index 1116944..0000000 Binary files a/all_records/Converted/25.flac and /dev/null differ diff --git a/all_records/Converted/25.wav b/all_records/Converted/25.wav new file mode 100644 index 0000000..eb87724 Binary files /dev/null and b/all_records/Converted/25.wav differ diff --git a/all_records/Converted/26.flac b/all_records/Converted/26.flac deleted file mode 100644 index 0de2b7a..0000000 Binary files a/all_records/Converted/26.flac and /dev/null differ diff --git a/all_records/Converted/26.wav b/all_records/Converted/26.wav new file mode 100644 index 0000000..e92601b Binary files /dev/null and b/all_records/Converted/26.wav differ diff --git a/all_records/Converted/27.flac b/all_records/Converted/27.flac deleted file mode 100644 index 8a7d9d8..0000000 Binary files a/all_records/Converted/27.flac and /dev/null differ diff --git a/all_records/Converted/27.wav b/all_records/Converted/27.wav new file mode 100644 index 0000000..2f98a94 Binary files /dev/null and b/all_records/Converted/27.wav differ diff --git a/all_records/Converted/28.flac b/all_records/Converted/28.flac deleted file mode 100644 index 38f2fc4..0000000 Binary files a/all_records/Converted/28.flac and /dev/null differ diff --git a/all_records/Converted/28.wav b/all_records/Converted/28.wav new file mode 100644 index 0000000..8bc18c1 Binary files /dev/null and b/all_records/Converted/28.wav differ diff --git a/all_records/Converted/29.flac b/all_records/Converted/29.flac deleted file mode 100644 index b6e3399..0000000 Binary files a/all_records/Converted/29.flac and /dev/null differ diff --git a/all_records/Converted/29.wav b/all_records/Converted/29.wav new file mode 100644 index 0000000..1d032c0 Binary files /dev/null and b/all_records/Converted/29.wav differ diff --git a/all_records/Converted/3.flac b/all_records/Converted/3.flac deleted file mode 100644 index e4039c9..0000000 Binary files a/all_records/Converted/3.flac and /dev/null differ diff --git a/all_records/Converted/3.wav b/all_records/Converted/3.wav new file mode 100644 index 0000000..660880d Binary files /dev/null and b/all_records/Converted/3.wav differ diff --git a/all_records/Converted/30.flac b/all_records/Converted/30.flac deleted file mode 100644 index c4959aa..0000000 Binary files a/all_records/Converted/30.flac and /dev/null differ diff --git a/all_records/Converted/30.wav b/all_records/Converted/30.wav new file mode 100644 index 0000000..b0b668c Binary files /dev/null and b/all_records/Converted/30.wav differ diff --git a/all_records/Converted/31.flac b/all_records/Converted/31.flac deleted file mode 100644 index 47194e4..0000000 Binary files a/all_records/Converted/31.flac and /dev/null differ diff --git a/all_records/Converted/31.wav b/all_records/Converted/31.wav new file mode 100644 index 0000000..94dc72a Binary files /dev/null and b/all_records/Converted/31.wav differ diff --git a/all_records/Converted/32.flac b/all_records/Converted/32.flac deleted file mode 100644 index c931e5d..0000000 Binary files a/all_records/Converted/32.flac and /dev/null differ diff --git a/all_records/Converted/32.wav b/all_records/Converted/32.wav new file mode 100644 index 0000000..a031526 Binary files /dev/null and b/all_records/Converted/32.wav differ diff --git a/all_records/Converted/33.flac b/all_records/Converted/33.flac deleted file mode 100644 index d5a1073..0000000 Binary files a/all_records/Converted/33.flac and /dev/null differ diff --git a/all_records/Converted/33.wav b/all_records/Converted/33.wav new file mode 100644 index 0000000..d5fdb77 Binary files /dev/null and b/all_records/Converted/33.wav differ diff --git a/all_records/Converted/34.flac b/all_records/Converted/34.flac deleted file mode 100644 index 3d46b61..0000000 Binary files a/all_records/Converted/34.flac and /dev/null differ diff --git a/all_records/Converted/34.wav b/all_records/Converted/34.wav new file mode 100644 index 0000000..0911bb6 Binary files /dev/null and b/all_records/Converted/34.wav differ diff --git a/all_records/Converted/35.flac b/all_records/Converted/35.flac deleted file mode 100644 index fbbbf8d..0000000 Binary files a/all_records/Converted/35.flac and /dev/null differ diff --git a/all_records/Converted/35.wav b/all_records/Converted/35.wav new file mode 100644 index 0000000..6828b4d Binary files /dev/null and b/all_records/Converted/35.wav differ diff --git a/all_records/Converted/36.flac b/all_records/Converted/36.flac deleted file mode 100644 index be49908..0000000 Binary files a/all_records/Converted/36.flac and /dev/null differ diff --git a/all_records/Converted/36.wav b/all_records/Converted/36.wav new file mode 100644 index 0000000..aa4137f Binary files /dev/null and b/all_records/Converted/36.wav differ diff --git a/all_records/Converted/37.flac b/all_records/Converted/37.flac deleted file mode 100644 index 03563ab..0000000 Binary files a/all_records/Converted/37.flac and /dev/null differ diff --git a/all_records/Converted/37.wav b/all_records/Converted/37.wav new file mode 100644 index 0000000..7166299 Binary files /dev/null and b/all_records/Converted/37.wav differ diff --git a/all_records/Converted/38.flac b/all_records/Converted/38.flac deleted file mode 100644 index f43e92f..0000000 Binary files a/all_records/Converted/38.flac and /dev/null differ diff --git a/all_records/Converted/38.wav b/all_records/Converted/38.wav new file mode 100644 index 0000000..48083bf Binary files /dev/null and b/all_records/Converted/38.wav differ diff --git a/all_records/Converted/39.flac b/all_records/Converted/39.flac deleted file mode 100644 index 1f551c3..0000000 Binary files a/all_records/Converted/39.flac and /dev/null differ diff --git a/all_records/Converted/39.wav b/all_records/Converted/39.wav new file mode 100644 index 0000000..6f044a5 Binary files /dev/null and b/all_records/Converted/39.wav differ diff --git a/all_records/Converted/4.flac b/all_records/Converted/4.flac deleted file mode 100644 index 9c246f1..0000000 Binary files a/all_records/Converted/4.flac and /dev/null differ diff --git a/all_records/Converted/4.wav b/all_records/Converted/4.wav new file mode 100644 index 0000000..7a8c1dc Binary files /dev/null and b/all_records/Converted/4.wav differ diff --git a/all_records/Converted/40.flac b/all_records/Converted/40.flac deleted file mode 100644 index 4266618..0000000 Binary files a/all_records/Converted/40.flac and /dev/null differ diff --git a/all_records/Converted/40.wav b/all_records/Converted/40.wav new file mode 100644 index 0000000..d4e3bf5 Binary files /dev/null and b/all_records/Converted/40.wav differ diff --git a/all_records/Converted/41.flac b/all_records/Converted/41.flac deleted file mode 100644 index 47c68c1..0000000 Binary files a/all_records/Converted/41.flac and /dev/null differ diff --git a/all_records/Converted/41.wav b/all_records/Converted/41.wav new file mode 100644 index 0000000..314b411 Binary files /dev/null and b/all_records/Converted/41.wav differ diff --git a/all_records/Converted/42.flac b/all_records/Converted/42.flac deleted file mode 100644 index 7cac160..0000000 Binary files a/all_records/Converted/42.flac and /dev/null differ diff --git a/all_records/Converted/42.wav b/all_records/Converted/42.wav new file mode 100644 index 0000000..3f99961 Binary files /dev/null and b/all_records/Converted/42.wav differ diff --git a/all_records/Converted/43.flac b/all_records/Converted/43.flac deleted file mode 100644 index 750f1f5..0000000 Binary files a/all_records/Converted/43.flac and /dev/null differ diff --git a/all_records/Converted/44.flac b/all_records/Converted/44.flac deleted file mode 100644 index 490da10..0000000 Binary files a/all_records/Converted/44.flac and /dev/null differ diff --git a/all_records/Converted/45.flac b/all_records/Converted/45.flac deleted file mode 100644 index 8c1cf5c..0000000 Binary files a/all_records/Converted/45.flac and /dev/null differ diff --git a/all_records/Converted/46.flac b/all_records/Converted/46.flac deleted file mode 100644 index 7fd65dd..0000000 Binary files a/all_records/Converted/46.flac and /dev/null differ diff --git a/all_records/Converted/47.flac b/all_records/Converted/47.flac deleted file mode 100644 index 01291df..0000000 Binary files a/all_records/Converted/47.flac and /dev/null differ diff --git a/all_records/Converted/48.flac b/all_records/Converted/48.flac deleted file mode 100644 index 2a6189c..0000000 Binary files a/all_records/Converted/48.flac and /dev/null differ diff --git a/all_records/Converted/49.flac b/all_records/Converted/49.flac deleted file mode 100644 index f9c5bb5..0000000 Binary files a/all_records/Converted/49.flac and /dev/null differ diff --git a/all_records/Converted/5.flac b/all_records/Converted/5.flac deleted file mode 100644 index 981a86f..0000000 Binary files a/all_records/Converted/5.flac and /dev/null differ diff --git a/all_records/Converted/5.wav b/all_records/Converted/5.wav new file mode 100644 index 0000000..9507254 Binary files /dev/null and b/all_records/Converted/5.wav differ diff --git a/all_records/Converted/50.flac b/all_records/Converted/50.flac deleted file mode 100644 index 3be500b..0000000 Binary files a/all_records/Converted/50.flac and /dev/null differ diff --git a/all_records/Converted/51.flac b/all_records/Converted/51.flac deleted file mode 100644 index 14c9a44..0000000 Binary files a/all_records/Converted/51.flac and /dev/null differ diff --git a/all_records/Converted/52.flac b/all_records/Converted/52.flac deleted file mode 100644 index e87f664..0000000 Binary files a/all_records/Converted/52.flac and /dev/null differ diff --git a/all_records/Converted/6.flac b/all_records/Converted/6.flac deleted file mode 100644 index fc358b2..0000000 Binary files a/all_records/Converted/6.flac and /dev/null differ diff --git a/all_records/Converted/6.wav b/all_records/Converted/6.wav new file mode 100644 index 0000000..e99b847 Binary files /dev/null and b/all_records/Converted/6.wav differ diff --git a/all_records/Converted/7.flac b/all_records/Converted/7.flac deleted file mode 100644 index 587ca82..0000000 Binary files a/all_records/Converted/7.flac and /dev/null differ diff --git a/all_records/Converted/7.wav b/all_records/Converted/7.wav new file mode 100644 index 0000000..da00974 Binary files /dev/null and b/all_records/Converted/7.wav differ diff --git a/all_records/Converted/8.flac b/all_records/Converted/8.flac deleted file mode 100644 index 11d1ccd..0000000 Binary files a/all_records/Converted/8.flac and /dev/null differ diff --git a/all_records/Converted/8.wav b/all_records/Converted/8.wav new file mode 100644 index 0000000..32132cc Binary files /dev/null and b/all_records/Converted/8.wav differ diff --git a/all_records/Converted/9.flac b/all_records/Converted/9.flac deleted file mode 100644 index 7a5ed5b..0000000 Binary files a/all_records/Converted/9.flac and /dev/null differ diff --git a/all_records/Converted/9.wav b/all_records/Converted/9.wav new file mode 100644 index 0000000..3840351 Binary files /dev/null and b/all_records/Converted/9.wav differ diff --git a/lib/jflac-1.3.jar b/lib/jflac-1.3.jar new file mode 100755 index 0000000..296d24e Binary files /dev/null and b/lib/jflac-1.3.jar differ diff --git a/src/com/company/Main.java b/src/com/company/Main.java index f0ce50f..82af86e 100644 --- a/src/com/company/Main.java +++ b/src/com/company/Main.java @@ -12,6 +12,8 @@ public class Main { public static void main (String[] args) throws LineUnavailableException, IOException, UnsupportedAudioFileException { + //RecordingThread recordingThread = new RecordingThread(); + //File AudioStream = new File("/Users/user/IdeaProjects/test_google_speach_api/all_records/Converted/4.wav"); RecordingThread recordingThread = new RecordingThread(); CommandsRecognizer commandsRecognizer = new CommandsRecognizer(); diff --git a/src/com/company/RecordingThread/RecordingThread.java b/src/com/company/RecordingThread/RecordingThread.java index 3020e1e..f44d8f1 100644 --- a/src/com/company/RecordingThread/RecordingThread.java +++ b/src/com/company/RecordingThread/RecordingThread.java @@ -33,6 +33,8 @@ public class RecordingThread extends Thread { private List listeners; + private File AudioFileStream; + public RecordingThread() { microphone = new MicrophoneAnalyzer(FLACFileWriter.FLAC); @@ -47,6 +49,17 @@ public RecordingThread() { } + public RecordingThread(File AudioFile) { + + microphone = new MicrophoneAnalyzer(FLACFileWriter.FLAC); + + recognizer = new Recognizer(Recognizer.Languages.RUSSIAN, apiKey); + listeners = new ArrayList(); + + this.AudioFileStream = AudioFile; + + } + private double CalculateNoiseLevel(int TimeInMsToCalculateNoiseLevel) { tempAudioFile = new File("DisplayAllReponce.flac"); @@ -94,56 +107,111 @@ public void addResponceListener(ResponseListener listener) { public void run() { int curSample = 0; + if(this.AudioFileStream == null) { - while (true) { - microphone.open(); + while (true) { + microphone.open(); + + try { + tempAudioFile = new File("DisplayAllReponce.flac"); + microphone.setAudioFile(tempAudioFile); + microphone.captureAudioToFile(microphone.getAudioFile()); - try { - tempAudioFile = new File("DisplayAllReponce.flac"); - microphone.setAudioFile(tempAudioFile); - microphone.captureAudioToFile(microphone.getAudioFile()); - Thread.sleep(checkVolumeSampleTime * 3); + Thread.sleep(checkVolumeSampleTime * 3); - double magnitude = microphone.magnitude(120, 122); + double magnitude = microphone.magnitude(120, 122); - //int magnitude = microphone.getAudioVolume(checkVolumeSampleTime); - System.out.println(magnitude); - //boolean isSpeaking = (volume > minimumVolumeToStartrecording); - boolean isSpeaking = (magnitude > 200); + //int magnitude = microphone.getAudioVolume(checkVolumeSampleTime); + System.out.println(magnitude); + //boolean isSpeaking = (volume > minimumVolumeToStartrecording); + boolean isSpeaking = (magnitude > 200); - if (isSpeaking) { + if (isSpeaking) { - DebugLog("Start RECORDING..."); + DebugLog("Start RECORDING..."); - do { - DebugLog("RECORDING proc..."); - Thread.sleep(sampleTime);//Updates every second - } while (microphone.magnitude(120, 122) > 100); + do { + DebugLog("RECORDING proc..."); + Thread.sleep(sampleTime);//Updates every second + } while (microphone.magnitude(120, 122) > 100); - DebugLog("Recording Complete!"); - microphone.close(); + DebugLog("Recording Complete!"); + microphone.close(); - DebugLog("Recognizing..."); + DebugLog("Recognizing..."); - GoogleResponse response = recognizer.getRecognizedDataForFlac(microphone.getAudioFile(), 1); - notifyListeners(response); + GoogleResponse response = recognizer.getRecognizedDataForFlac(microphone.getAudioFile(), 1); + notifyListeners(response); - DebugLog("Looping back");//Restarts loops + DebugLog("Looping back");//Restarts loops + } + microphone.getAudioFile().delete(); + + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.out.println("Error Occured"); + } finally { + microphone.close();//Makes sure microphone closes on exit. } - microphone.getAudioFile().delete(); + } + } else { + while (true) { + microphone.open(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - System.out.println("Error Occured"); - } finally { - microphone.close();//Makes sure microphone closes on exit. + try { + tempAudioFile = new File("DisplayAllReponce.flac"); + microphone.setAudioFile(tempAudioFile); + microphone.captureAudioFromFileToFile(microphone.getAudioFile(), AudioFileStream); + + Thread.sleep(checkVolumeSampleTime * 3); + + double magnitude = microphone.magnitudeInFile(120, 122); + + //int magnitude = microphone.getAudioVolume(checkVolumeSampleTime); + System.out.println(magnitude); + //boolean isSpeaking = (volume > minimumVolumeToStartrecording); + boolean isSpeaking = (magnitude > 200); + + if (isSpeaking) { + + DebugLog("Start RECORDING..."); + + do { + DebugLog("RECORDING proc..."); + Thread.sleep(sampleTime);//Updates every second + } while (microphone.magnitude(120, 122) > 100); + + DebugLog("Recording Complete!"); + microphone.close(); + + DebugLog("Recognizing..."); + + GoogleResponse response = recognizer.getRecognizedDataForFlac(microphone.getAudioFile(), 1); + notifyListeners(response); + + DebugLog("Looping back");//Restarts loops + + + } + microphone.getAudioFile().delete(); + + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + System.out.println("Error Occured"); + } finally { + microphone.close();//Makes sure microphone closes on exit. + } } + } } diff --git a/src/com/company/microphone/Microphone.java b/src/com/company/microphone/Microphone.java index dc45862..572c264 100644 --- a/src/com/company/microphone/Microphone.java +++ b/src/com/company/microphone/Microphone.java @@ -1,5 +1,7 @@ package com.company.microphone; +import org.kc7bfi.jflac.sound.spi.FlacAudioFileReader; + import javax.sound.sampled.*; import java.io.Closeable; @@ -132,6 +134,29 @@ public void captureAudioToFile(File audioFile) throws LineUnavailableException { new Thread(new CaptureThread()).start(); + } + + protected File audioFileStream; + /** + * Captures audio from the microphone and saves it a file + * + * @param audioFile The File to save the audio to + * @throws LineUnavailableException + */ + public void captureAudioFromFileToFile(File audioFile, File audioFileStream) throws LineUnavailableException { + + setState(CaptureState.STARTING_CAPTURE); + setAudioFile(audioFile); + this.audioFileStream = audioFileStream; + + if(getTargetDataLine() == null){ + initTargetDataLine(); + } + + //Get Audio + new Thread(new CaptureFromFileThread()).start(); + + } /** @@ -209,6 +234,7 @@ private class CaptureThread implements Runnable { * Run method for thread */ public void run() { + try { AudioFileFormat.Type fileType = getFileType(); File audioFile = getAudioFile(); @@ -221,4 +247,29 @@ public void run() { } } + /** + * Thread to capture the audio from the microphone and save it to a file + */ + private class CaptureFromFileThread implements Runnable { + + /** + * Run method for thread + */ + public void run() { + + try { + AudioFileFormat.Type fileType = getFileType(); + File audioFile = getAudioFile(); + File audioStream = audioFileStream; + open(); + + AudioInputStream inputStream = AudioSystem.getAudioInputStream(audioFileStream); + AudioSystem.write(inputStream, fileType, audioFile); + //Will write to File until it's closed. + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } \ No newline at end of file diff --git a/src/com/company/microphone/MicrophoneAnalyzer.java b/src/com/company/microphone/MicrophoneAnalyzer.java index b3ba8a3..591e282 100644 --- a/src/com/company/microphone/MicrophoneAnalyzer.java +++ b/src/com/company/microphone/MicrophoneAnalyzer.java @@ -2,11 +2,14 @@ import com.darkprograms.speech.util.Complex; import com.darkprograms.speech.util.FFT; +import org.kc7bfi.jflac.sound.spi.FlacAudioFileReader; import java.io.IOException; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.UnsupportedAudioFileException; /******************************************************************************************** @@ -208,6 +211,62 @@ public double magnitude (int minFreq, int maxFreq) { } + static int numOfBytesTotalOffset = 0; + + public double magnitudeInFile (int minFreq, int maxFreq) throws IOException, UnsupportedAudioFileException { + + int numOfBytes = 2048; + + numOfBytesTotalOffset += numOfBytes; + FlacAudioFileReader flacAudioFileReader = new FlacAudioFileReader(); + AudioInputStream stream = flacAudioFileReader.getAudioInputStream(this.getAudioFile()); + + byte[] data = new byte[numOfBytes+1];//One byte is lost during conversion + try { + stream.read(data, 0, numOfBytes); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + + double[] audioData = this.bytesToDoubleArray(data); + audioData = applyHanningWindow(audioData); + Complex[] complex = new Complex[audioData.length]; + for(int i = 0; i + + +