Text_to_Speech/assets/Test.ts

64 lines
2.2 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);
2022-01-22 03:26:41 +00:00
// let url: string = "https://code.responsivevoice.org/responsivevoice.js?key=8LG4XCOk";
// cc.assetManager.loadRemote(url, (err: Error, res: cc.JsonAsset) => {
// if (err) {
// console.error(`[Error] ${url}載入失敗 err: ${err}`);
// return;
// }
// });
2022-01-21 09:50:26 +00:00
}
start(): void {
let self: this = this;
let url: string = window.location.search;
let request: object = [];
if (url.indexOf("?") !== -1) {
2022-01-22 03:26:41 +00:00
let str: string = url.substring(1);
2022-01-21 09:50:26 +00:00
let strs: string[] = str.split("&");
for (let i: number = 0; i < strs.length; i++) {
request[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
}
}
2022-01-22 02:21:19 +00:00
let ResponsiveVoice: any = window["responsiveVoice"];
2022-01-21 09:50:26 +00:00
// 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) {}
}