nativescript-community / texttospeech

Text to Speech NativeScript plugin for Android & iOS :loudspeaker:

Home Page:http://nativescript-community.github.io/texttospeech/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript example

d3mac123 opened this issue · comments

I know this is a stupid question (I recognize my limited skills) but, how do I translate the Typescript example below to pure Javascript?

/// javascript
var TextToSpeech = require("nativescript-texttospeech");


/// TypeScript
import { TNSTextToSpeech, SpeakOptions } from 'nativescript-texttospeech';

let TTS = new TNSTextToSpeech();

let speakOptions: SpeakOptions = {
    text: 'Whatever you like', /// *** required ***
    speakRate: 0.5, // optional - default is 1.0
    pitch: 1.0, // optional - default is 1.0
    volume: 1.0, // optional - default is 1.0
    locale: "en-GB",  // optional - default is system locale,
    finishedCallback: Function // optional
}

// Call the `speak` method passing the SpeakOptions object
TTS.speak(speakOptions).then(() => {
    // everything is fine
}, (err) => {
    // oops, something went wrong!
});

Here's the answer:

var TextToSpeech = require("nativescript-texttospeech");
var TTS = new TextToSpeech.TNSTextToSpeech();
 var speakOptions = {
        text: L('msgTimeFlyTitle')+L('msgTimeFly'),
        speakRate: 0.5,
        pitch: 1.0,
        volume: 1.0 //,
        locale: "en-GB",
        finishedCallback: Function // optional
    };
    // Call the `speak` method passing the SpeakOptions object
    TTS.speak(speakOptions).then(function () {
        // everything is fine
    }, function (err) {
        // oops, something went wrong!
    });