JM_KA/assets/Script/Text_to_Speech.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-08-25 09:49:29 +00:00
const responsiveVoice = window["responsiveVoice"];
export default class Text_to_Speech {
//#region 外調參數
private voice: string = null;
//#endregion
//#region Custom
constructor() {
let self: this = this;
responsiveVoice.init();
var voicelist = responsiveVoice.getVoices();
this.setDefaultVoice(voicelist[14].name);
}
public setDefaultVoice(voice: string): void {
this.voice = voice;
responsiveVoice.setDefaultVoice(voice);
}
public speak(msg: string): void {
let self: this = this;
if (responsiveVoice.voiceSupport()) {
responsiveVoice.speak(msg, this.voice, {
onstart: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
onend: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
});
} else {
console.error(`!responsiveVoice.voiceSupport`);
}
}
//#endregion
}