I'm building an application to calculate delay based on keywords found. The method I used is not accurate or even wrong (error). The methods used are as follows:
@Override
public void onResults(Bundle results) {
progressBar.setVisibility(View.GONE);
ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (matches != null && !matches.isEmpty()) {
String transcript = matches.get(0);
textSTT.setText(transcript);
if (transcript.contains(keyword)) {
long endTime = System.nanoTime(); // Using nano
delay = endTime - startTime;
double delayInSeconds = delay / 1_000_000_000.0;
double roundedDelay = roundToTwoDecimalPlaces(delayInSeconds); // Rounding delay
delayResult.setText(String.format("Delay: %.2f seconds\nTranscription result: %s", roundedDelay, transcript));
} else {
delayResult.setText("Keyword not found.");
}
} else {
delayResult.setText("No result from speech recognition.");
}
}
Condition:
- When I first press the button to start recording, after that I immediately mention the keyword (approximately the 1st second). But the results show the delay obtained is 2 or even more.
Tools:
- Speech Recognizer (Android default)
I have set 10 seconds for the countdown. When I pressed the button to start recording, I immediately mentioned the keyword (approximately the 1st second). But the delay result shows the 2nd second or even more. Similarly, when I try to mention the keyword at the 5th second, but the delay result shows the 7th second or even more.
I want the delay calculation to be more accurate, for example: I mention the keyword at the 7th second, then the delay is 7 seconds.
startTimeis or how it relates to what you are trying to do. Also, we do not know whenonResults()gets called and how it relates to what you are trying to do. If we guess thatonResults()is tied to receiving the speech recognition results, thenendTimeis the time when you get those results, and that has nothing to do with when in a recording any particular thing is said.