nativescript-community / texttospeech

Text to Speech NativeScript plugin for Android & iOS :loudspeaker:
http://nativescript-community.github.io/texttospeech/
MIT License
50 stars 24 forks source link

Javascript example #12

Closed d3mac123 closed 7 years ago

d3mac123 commented 7 years ago

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!
});
d3mac123 commented 7 years ago

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!
    });