Is there a way to sequence nativescript text-to-speech messages and use a callback function?
How can the finished callback function be utilized?
The SpeakOptions in nativescript-texttospeech include a finishedCallback
property.
I want the TTS to read texts sequentially, that's all.
talk("First message");
talk("Second message");
talk("Last message");
<template>
<Page>
<ActionBar title="Speak Promises Component" />
<StackLayout>
<Label :text="speakoptions.text" col="0" row="0" />
<Button text="start" @tap="start" />
</StackLayout>
</Page>
</template>
<script >
import { TNSTextToSpeech, SpeakOptions as speakoptions } from "nativescript-texttospeech";
let TTS = new TNSTextToSpeech();
export default {
data() {
return {
speakoptions: {
text: " ",
locale: "en-GB",
finishedCallback: "" // what kind of function it should be?
}
};
},
methods: {
start: async function() {
await this.talk("First message");
await this.talk("Second message");
await this.talk("Last message");
},
talk: function(message) {
this.speakoptions.text = message;
return TTS.speak(this.speakoptions);
}
}
};
</script>
<style scoped >
</style>