JM_KA/assets/Script/Text_to_Speech.ts
2022-01-20 19:20:17 +08:00

37 lines
1.2 KiB
TypeScript

const { ccclass, property } = cc._decorator;
@ccclass
export default class Text_to_Speech extends cc.Component {
// LIFE-CYCLE CALLBACKS:
start(): void {
let self: this = this;
let url: string = window.location.search;
let request: object = [];
if (url.indexOf("?") !== -1) {
let str: string = url.substr(1);
let strs: string[] = str.split("&");
for (let i: number = 0; i < strs.length; i++) {
request[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
let ResponsiveVoice: any = responsiveVoice;
// var voicelist: any = ResponsiveVoice.getVoices();
// let voice: string = this.EditBox.string;
// let voice: string = "傻B豆豆";
let voice: string = request["voice"];
ResponsiveVoice.speak(voice, "Chinese Female", {
onstart: function (Callback: any): void {
// IsEnd = true;
self.node.getChildByName("Label").getComponent(cc.Label).string = voice;
},
// onend: function (Callback: any): void {
// // IsEnd = true;
// },
});
}
}