如何在 nativescript-texttospeech 中使用完成的回调函数?
How to use finished callback function in nativescript-texttospeech?
如何使用回调函数订购 nativescript texttospeech 消息?
完成回调函数如何使用?
nativescript-texttospeech 在 SpeakOptions 中有 finishedCallback
属性。
只需要TTS就可以一条一条的读完
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>
尝试包装自己的承诺,这应该会有所帮助
talk: function(message) {
var speakOptions = { ...this.speakoptions, text: message };
return new Promise((resolve, reject) => {
speakOptions.finishedCallback = resolve;
TTS.speak(speakOptions)
});
}
如何使用回调函数订购 nativescript texttospeech 消息?
完成回调函数如何使用?
nativescript-texttospeech 在 SpeakOptions 中有 finishedCallback
属性。
只需要TTS就可以一条一条的读完
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>
尝试包装自己的承诺,这应该会有所帮助
talk: function(message) {
var speakOptions = { ...this.speakoptions, text: message };
return new Promise((resolve, reject) => {
speakOptions.finishedCallback = resolve;
TTS.speak(speakOptions)
});
}