Skip to main content
5-Regular Member
March 26, 2018
Solved

Work instruction Speech and Step Number to be adjusted

  • March 26, 2018
  • 1 reply
  • 4452 views

Hello,

 

I am using the below script to hear work instruction( on IoS Device ) created in Illustrate as well as show it up on a 3d label.

 

var labelId = "3DLabel-1";
$scope.$on('newStep', function(evt, arg)
{
$scope.setWidgetProp( labelId, "text", arg);
var msg = new SpeechSynthesisUtterance(arg)
window.speechSynthesis.speak(msg);
});

 

But I am facing two challenges here:

 

1. Even before the 3DLabel is made visible, the the first step of the work instruction( Illustrate Sequence Name ) is said out loud as soon as the experience is loaded,  which is not needed, even though the rest of the sequence comes up only after I click the button.

 

2.  Also it pronounces the steps numbers as well (eg., 1/11 Step1, 2/11 Step 2 .,.) I would like to avoid it saying 1/11 or 2/11 step numbers.

 

Any suggestions?

 

Thanks,

Avinash

 

Best answer by AllanThompson

Hi Avinash,

 

For point 1, I think you should look at how you load the experience.  Have you used a button or some other mechanism of launching the java function?

 

For point 2, refer to this thread: https://community.ptc.com/t5/ThingWorx-Studio/Can-Cortana-speak-the-work-instructions-that-you-have-created/m-p/502803#M105.

 

I've used the method originally outlined here to build my version of this.  I split it into 2 functions so I could choose whether or not the experience speaks as well as shows the text and I used 2 labels just to help me visualise/troubleshoot.  Label-1 isn't visible in the final experience.

 

var labelId = "label-1"; 
$scope.$on('newStep', function(evt, arg) {

$scope.setWidgetProp( labelId, "text", arg); // get the currentStep from the arg
var labelText = $scope.view.wdg['label-1'].text;
var InstructText = labelText.substr(labelText.indexOf(")") + 1);
$scope.setWidgetProp( "label-2", "text", InstructText);
});

 

$scope.speak = function(){
var spokenText = $scope.view.wdg["label-2"].text;
var msg = new SpeechSynthesisUtterance(spokenText);
window.speechSynthesis.speak(msg);
}

 

Hope this helps.

 

Allan

1 reply

16-Pearl
March 28, 2018

Hi Avinash,

 

For point 1, I think you should look at how you load the experience.  Have you used a button or some other mechanism of launching the java function?

 

For point 2, refer to this thread: https://community.ptc.com/t5/ThingWorx-Studio/Can-Cortana-speak-the-work-instructions-that-you-have-created/m-p/502803#M105.

 

I've used the method originally outlined here to build my version of this.  I split it into 2 functions so I could choose whether or not the experience speaks as well as shows the text and I used 2 labels just to help me visualise/troubleshoot.  Label-1 isn't visible in the final experience.

 

var labelId = "label-1"; 
$scope.$on('newStep', function(evt, arg) {

$scope.setWidgetProp( labelId, "text", arg); // get the currentStep from the arg
var labelText = $scope.view.wdg['label-1'].text;
var InstructText = labelText.substr(labelText.indexOf(")") + 1);
$scope.setWidgetProp( "label-2", "text", InstructText);
});

 

$scope.speak = function(){
var spokenText = $scope.view.wdg["label-2"].text;
var msg = new SpeechSynthesisUtterance(spokenText);
window.speechSynthesis.speak(msg);
}

 

Hope this helps.

 

Allan

agangaiah5-Regular MemberAuthor
5-Regular Member
March 28, 2018

Thanks Allan.

 

This works well when i try to play the sequence with a step by step procedure on every button click, but somehow it does not play well if I choose the button that triggers " Play All " Option.

 

Thanks,

Avinash

16-Pearl
March 28, 2018

I"m not sure about using the Play All option.  When I create sequences, I only ever use the Play option as I want the end users to be able to follow through step-by-step.

 

Maybe you need to build the java to get the step info and read it out into a higher level function as I image that when you are using Play All these values will be continually changing as it moves through all the steps and you'll need something to trigger the reading.  Something else that could cause problems would be if it takes longer to read out the instructions than it does to play the step.