Text_to_Speech/assets/Test.ts

57 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-01-21 09:50:26 +00:00
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
// LIFE-CYCLE CALLBACKS:
// private EditBox: cc.EditBox = null;
onLoad(): void {
// this.EditBox = this.node.getChildByName("EditBox").getComponent(cc.EditBox);
// this.EditBox.node.on("text-changed", this.Voice, this);
}
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;
// },
});
}
// public Voice(): void {
// let ResponsiveVoice: any = responsiveVoice;
// // var voicelist: any = ResponsiveVoice.getVoices();
// let voice: string = this.EditBox.string;
// ResponsiveVoice.speak(voice, "Chinese Female", {
// // onend: function (EndCallback: any): void {
// // // IsEnd = true;
// // }
// });
// }
// update (dt) {}
}