Text To Speech Native Plugin

I have a very simple question to ask. I want to speak other language ,that just the default en-US. I check with the official page(https://ionicframework.com/docs/native/text-to-speech/#TTSOptions), but i don’t really have clue how to apply it inside the code.
Which is this TTSOptions.

TTSOptions is an array that can be given to speak() as a parameter instead of just a string. It can optionally contain a locale or a rate value additionally to the required text.

1 Like

Feel free to post a code example if you got it working.

Here’s the working code.

Voice.ts

async read(TranslateText,category) : Promise<any> {
  try {
    await this.tts.speak({
      text: TranslateText,
      locale: category,
      rate: 1
    });
  }
  catch (e) {
    console.log(e);
  }
}

Voice.html

<button ion-button clear small icon-left color="primary" (click)="read(item.translatedText,this.category)">

1 Like

Hi All,
I am in middle of the application for the text to speech, I used Ionic cordova native text to speech plugin, It works fine when I pass option local:‘en-US’, In same scenario when I pass local:‘hi’ for hindi, not working.
Here i s the code snippet. src/pages/home/home.html

Ionic Text To Speech Text Language Hindi English Play Text src/pages/home/home.ts

import {Component} from ‘@angular/core’;
import {TextToSpeech} from ‘@ionic-native/text-to-speech’;

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {
text: string;
rate: number;
locale: string;

constructor(private tts: TextToSpeech) {
this.text = ‘Initial text’;
this.rate = 1;
this.locale = ‘en-US’;
}

playText() {
this.tts.speak({
text: this.text,
rate: this.rate / 10,
locale: this.locale
})
.then(() => console.log(‘Success’))
.catch((reason: any) => console.log(reason));
}

}
Please look into it. I want multiple language text to speech.

Thanks.