Reputation: 35
I have been able to use the ionic framework documentation to implement Ionic Speech Recognition (speech to text) on my project now I want to be able to save the text or audio using any form input, ngmodel or formcontrol
I have tried using binding the matches variable to ng model assigned to a new variable but didn't work
startListening() {
let options = {
language: 'en-US',
matches: 2,
prompt: 'Say Something!'
}
this.speechRecognition.startListening(options).subscribe(matches => {
this.matches = matches;
this.cd.detectChanges();
});
this.isRecording = true;
}
<ion-grid>
<ion-row>
<ion-col *ngIf="matches">
<h3 *ngFor="let match of matches">
{{ match }}
</h3>
<ion-item>
<ion-input type="text" [(ngModel)]="matches">
</ion-input>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
I expect to be able to see the text in the input so that I can have the option to edit before I save to database
Upvotes: 0
Views: 530
Reputation: 35
I solved finally solved it with Angular trackBy
<ion-grid>
<ion-row>
<ion-col *ngIf="matches">
<h3 *ngFor="let match of matches; let i = index; trackBy:trackByInstance"">
{{ match }}
</h3>
<ion-item>
<ion-input type="text" [(ngModel)]="matches[i]">
</ion-input>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
trackByInstance(index: any) {
return index;
Upvotes: 0
Reputation: 1565
You can do something like this,
Now your voice text results are saved in matches
variable.
Now lets change you input little bit. According to your problem what i understood was that you need to show your spoken text in an input field and then you need to change is by your hand if that text is not correct or something else.
For that you can set you input value to matches. When you do that, your input field will display the matches texts and yet it will be editable. But you need to provide a different [(ngModel)] variable for that input since you need to identify and track the changed matching values(matches
)
<ion-input type="text" value="matches" [(ngModel)]="correctedMatches">
Upvotes: 0