I am working on a browser speech accessibility tool and wanted to show the user the interim results as they are speaking.
The issue I am facing is when receiving data from the speech service the consumer subscription side is not changing the template variable as expected.
ngOnInit(): void {
console.log("OnInit -- subscribing");
this._subscription = this.speech
.speechInput()
.pipe(debounceTime(100), distinctUntilChanged())
.subscribe((s) => {
if (this.speech.getLastPhrase() != null)
this.updateFinalResult(this.speech.getLastPhrase());
this.updateInterimResult(s); // <------- This call updates `interimResults` variable
console.log("Subscribe text " + s);
});
}
When getting results from the service I can see the console.log
response but this.updateInterimResults(s)
does not update the template. The only way to see changes is by clicking the button. I don't know why the button makes the variables update.
<div>Interim Results: {{interimResults}}</div>
<div>Final Results: {{finalResults}}</div>
<button
(click)="toggleMic()"
[style]="microphone ? 'background-color: white' : 'background-color: red'"
[textContent]="microphone ? 'Record' :'Listening...'"
></button>