Skip to content

Commit

Permalink
added recording icon functionality and fixed bug where recording woul…
Browse files Browse the repository at this point in the history
…dn't stop at end of checklist
  • Loading branch information
brian-mckeown committed Oct 21, 2023
1 parent 2d912d0 commit 3fc71f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<button class="btn btn-danger ml-2" ng-click="handleButtonPress('D')">D</button>
<button class="btn btn-outline-primary ml-2" ng-click="toggleMicrophone()" id="microphoneButton">
<i class="fas fa-microphone"></i>
<i class="fas fa-dot-circle text-danger" ng-show="recognitionSignalStarted"></i>
</button>
</div>
<div>State: {{ state }}</div>
Expand Down Expand Up @@ -321,7 +322,7 @@ <h2>Navigraph Charts</h2>
</p>
<p class="text-danger">
Per Navigraph's Developer Restrictions, displaying their charts on physical EFBs or Desktop Applications is
<a href="https://developers.navigraph.com/docs/general/restrictions" target="_blank" rel="noopener noreferrer">prohibited at this time</a>.
<a href="https://developers.navigraph.com/docs/general/restrictions" target="_blank" rel="noopener noreferrer">prohibited by Navigraph at this time</a>.
</p>
<p>We will look into options in the future.</p>
</div>
Expand Down
15 changes: 14 additions & 1 deletion src/main/resources/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ app.controller('ChecklistController', ['$scope', '$sce', '$timeout', '$http', '$

//** Voice/Speech Recognition section **/
$scope.isListening = false;
$scope.preventRecognitionRestart = false;
$scope.toggleMicrophone = function() {
$scope.preventRecognitionRestart = false;
$scope.isListening = !$scope.isListening;

// If listening state is turned on
Expand Down Expand Up @@ -162,8 +164,13 @@ app.controller('ChecklistController', ['$scope', '$sce', '$timeout', '$http', '$
$scope.recognition.interimResults = false; // We only want the final result
$scope.recognition.lang = 'en-US'; // Set to your preferred language

$scope.recognitionSignalStarted = false; // Initialize the variable

$scope.recognition.onstart = function() {
console.log('Voice recognition started. Try speaking into the microphone.');
$scope.$apply(function() {
$scope.recognitionSignalStarted = true; // Show the red dot
});
};

$scope.recognition.onerror = function(event) {
Expand All @@ -173,6 +180,9 @@ app.controller('ChecklistController', ['$scope', '$sce', '$timeout', '$http', '$
$scope.recognition.onend = function() {
console.log('Voice recognition ended.');
$scope.recognitionStarted = false;
$scope.$apply(function() {
$scope.recognitionSignalStarted = false; // Hide the red dot
});
};

$scope.recognition.onresult = function(event) {
Expand Down Expand Up @@ -262,6 +272,9 @@ app.controller('ChecklistController', ['$scope', '$sce', '$timeout', '$http', '$
var completionMessage = $scope.currentChecklist.checklist + " checklist complete.";
$scope.chatMessage = completionMessage;
$scope.sendMessage();
// Set the flag to true to prevent automatic restarting of recognition
$scope.preventRecognitionRestart = true;
$scope.stopSpeechRecognition();
}
};

Expand Down Expand Up @@ -310,7 +323,7 @@ app.controller('ChecklistController', ['$scope', '$sce', '$timeout', '$http', '$

// Start the voice recognition here if the microphone button is enabled.
setTimeout(function() {
if ($scope.isListening) {
if ($scope.isListening && $scope.currentSubRowIndex !== $scope.currentChecklist.subRows.length) {
$scope.startSpeechRecognition();
}
}, 2000); // 2-second delay
Expand Down

0 comments on commit 3fc71f7

Please sign in to comment.