首页 > 解决方案 > 有没有办法将语音中的“文本”保存为文本离子语音识别

问题描述

我已经能够使用离子框架文档在我的项目中实现离子语音识别(语音到文本)现在我希望能够使用任何表单输入、ngmodel 或 formcontrol 保存文本或音频

我尝试使用将匹配变量绑定到分配给新变量的 ng 模型但没有用

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>

我希望能够看到输入中的文本,以便在保存到数据库之前可以选择进行编辑

标签: typescriptionic-frameworkionic3cordova-pluginsphonegap-plugins

解决方案


我解决了终于用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;

推荐阅读