Is it possible to preserve the spoken "text" through Ionic Speech Recognition for future reference?

After successfully implementing Ionic Speech Recognition in my project using the Ionic framework documentation, I am now facing a challenge with saving the text or audio input using any form input method like ngmodel or formcontrol.

My attempts to bind the matches variable to ng-model assigned to a new variable have been unsuccessful.

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>

My goal is to see the text displayed in the input field so that I can edit it before saving it to the database.

Answer №1

Consider the following approach,

Your voice-to-text results will be stored in the matches variable.

Now, adjust your input slightly. It seems like you want to display your spoken text in an input field and make it editable for corrections or changes.

To achieve this, you can set the input value to matches. This way, the input field will show the matching texts while remaining editable. However, you should use a different [(ngModel)] variable for this input in order to keep track of the modified matching values (matches)

<ion-input  type="text" value="matches" [(ngModel)]="correctedMatches">

Answer №2

After much trial and error, I was able to successfully overcome the challenge using Angular's trackBy feature.

 <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;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The outcome does not display default selected checkboxes

I am facing an issue with default checked items. The default checkbox is functioning properly, but when I click a button to display all checked items, the default checks are not being shown (they appear as unchecked). However, if I uncheck and then check t ...

Challenge with sharing an array from a different component in Angular using @Input()

Recently, I started learning Angular and decided to create a basic blog application. While trying to retrieve a property from another component using the @Input() decorator, I encountered an issue specifically related to arrays. In a post-list-item compone ...

What is the best way to define a category in order to utilize a saved string as a variable for referencing it?

An object named CONFIG holds the following information: export const CONFIG = { buttonDestinations: { detailedStats: `detailedStats`, mealPlans: `mealPlans`, products: `products` }, buttonTexts: { detailedStats: ...

How can I retrieve the date from the following week with Ionic?

I am looking to retrieve the date of today plus 7 days. Currently, I am retrieving today's date using the following code: public dateToday: string = new Date().toLocaleDateString('de-DE'); After searching on Google, I came across the soluti ...

The element is absent in Type {}, however, it is mandatory in Type '&' and '&' cannot be designated to String Index Type Errors

I have a goal of passing the logged-in user's email address to a 'dict' as a key, fetching its corresponding token value, and using it as a query parameter for an API call. The user's email is retrieved from the user data upon login, sp ...

Tips for creating a jasmine test scenario for a function executed within the ngOnInit lifecycle hook

I am finding it challenging to create a successful test case for the code snippet below. In my component.ts file id = 123456; data = []; constructor(private serv: ApiService){} ngOnInint(){ getData(id); } getData(id){ this.serv.getRequest(url+id) ...

Guide on integrating external libraries with Angular CLI

I've been working on incorporating external libraries into my project, and I've been following the instructions provided here. While I know it's possible to use CDNs in my index.html, I'm interested in learning how to do it using TypeS ...

Tips for sorting through aggregated information in Foundry Functions

How can I filter on grouped data in Foundry Functions after grouping and aggregating my data? See the code snippet below for reference: @Function() public async grouping(lowerBound : Integer ): Promise<TwoDimensionalAggregation<string>> { ...

Ways to mock a static method within an abstract class in TypeScript

Having a difficult time testing the function Client.read.pk(string).sk(string). This class was created to simplify working with dynamoDB's sdk, but I'm struggling to properly unit test this method. Any help or guidance would be greatly appreciate ...

Revamp the switch-case statement in JavaScript code

Is there a way to refactor this code in order to prevent repeating dailogObj.image? I would have used a return statement if it wasn't for case 5 where two assignments are required. getDialogData(imageNum): any { const dailogObj = { image: ...

Adding an event listener to the DOM through a service

In the current method of adding a DOM event handler, it is common to utilize Renderer2.listen() for cases where it needs to be done outside of a template. This technique seamlessly integrates with Directives and Components. However, if this same process i ...

One of the interfaces in use is malfunctioning, despite being identical to the other interface in TypeScript

I have been working on the IDocumentFilingDto.ts file. import { DocumentOrigin } from "./IDocumentFilingDto"; export interface IDocumentFilingDtoGen { UniqueId?: any; Title?: string; DocumentId?: string; Binder?: any; Communi ...

TypeScript error: The type 'ActionTypes' does not meet the requirement of being an 'Action<any>'

I am currently developing a TypeScript application that utilizes React and Redux, and I have run into a specific issue. I am in need of an additional default option. Below is the relevant code snippet: import { ThunkAction } from 'redux-thunk' ...

Retrieving data from both a Firestore collection and its nested sub-collection simultaneously

In my Ionic 5 app, I have organized my Firestore database structure as follows. Book (collection) {bookID} (document with book fields) Like (sub-collection) {userID} (document named after user ID with respective fields) The collection Book consists of ...

Is there a way to assign DTO to an entity within typescript?

For my current project, I am utilizing Vue with TypeScript and Axios to retrieve objects from the backend. Here is an example of the object type I am working with: class Annoucement { id!: string; description?: string; deal?: Deal; realty?: ...

When users install my npm module, they are not seeing text prediction (intellisense) in their editors

I'm currently focused on developing my package @xatsuuc/startonomy. I'm encountering an issue where Intellisense is not working properly when the package is installed on the user's side. Even though the .d.ts files are visible in node_modul ...

Encountering a type error with React component children in TypeScript

A few days ago, I delved into learning React with TypeScript and encountered the following error: /home/sotiris/Github/ecommerce-merng-platform/admin/src/components/DashboardHOC/DashboardHOC.tsx TypeScript error in /home/sotiris/Github/ecommerce-merng- ...

Issue with react-native-svg ForeignObject missing in project (React Native with Expo using TypeScript)

I am working on a React Native project in Expo and have incorporated the expo TypeScript configuration. Using "expo install," I added react-native-svg version 9.13.3 to my project. However, every time I attempt to render the SVG using react-native-svg, I ...

"Mastering the art of debouncing in Angular using

I am facing an issue where, during a slow internet connection, users can press the save button multiple times resulting in saving multiple sets of data. This problem doesn't occur when working locally, but it does happen on our staging environment. E ...

The issue of HTTP parameters not being appended to the GET request was discovered

app.module.ts getHttpParams = () => { const httpParamsInstance = new HttpParams(); console.log(this.userForm.controls) Object.keys(this.userForm.controls).forEach(key => { console.log(this.userForm.get(key).value) const v ...