Skip to content

Commit

Permalink
timestamp change
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhuushmgl committed Jul 9, 2019
1 parent 2231b0b commit df21c30
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.ArrayList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
Expand Down Expand Up @@ -80,6 +81,15 @@ public static void main(String... args) {
}
}

public static String convertMillisToDate(double milliSeconds, DecimalFormat format) {
long millis = (long) milliSeconds;
return String.format("%s min : %s sec",
format.format( TimeUnit.MILLISECONDS.toMinutes(millis)),
format.format( TimeUnit.MILLISECONDS.toSeconds(millis) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)))
);

}
/** Performs infinite streaming speech recognition */
public static void infiniteStreamingRecognize(String languageCode) throws Exception {

Expand Down Expand Up @@ -134,21 +144,22 @@ public void onResponse(StreamingRecognizeResponse response) {

double correctedTime = resultEndTimeInMS - bridgingOffset
+ (STREAMING_LIMIT * restartCounter);
DecimalFormat format = new DecimalFormat("0.#");
DecimalFormat format = new DecimalFormat();
format.setMinimumIntegerDigits(2);

SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
if (result.getIsFinal()) {
System.out.print(GREEN);
System.out.print("\033[2K\r");
System.out.printf("%s: %s\n", format.format(correctedTime),
alternative.getTranscript());
System.out.printf("%s: %s\n", convertMillisToDate(correctedTime, format),
alternative.getTranscript() + " - " + alternative.getConfidence());

isFinalEndTime = resultEndTimeInMS;
lastTranscriptWasFinal = true;
} else {
System.out.print(RED);
System.out.print("\033[2K\r");
System.out.printf("%s: %s", format.format(correctedTime),
System.out.printf("%s: %s", convertMillisToDate(correctedTime, format),
alternative.getTranscript());

lastTranscriptWasFinal = false;
Expand Down

0 comments on commit df21c30

Please sign in to comment.