[add] Text_to_Speech

This commit is contained in:
建喵 2022-01-22 11:34:53 +08:00
parent b1dffd1f6b
commit 587caaa9b4
3 changed files with 28 additions and 13 deletions

View File

@ -4,6 +4,6 @@
"isPlugin": true,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -16,7 +16,7 @@ export default class Manager extends cc.Component {
//#region private
private _text_to_Speech: Text_to_Speech = new Text_to_Speech();
private _text_to_Speech: Text_to_Speech;
//#endregion
@ -24,6 +24,7 @@ export default class Manager extends cc.Component {
protected onLoad(): void {
let self: this = this;
this._text_to_Speech = new Text_to_Speech();
window.addEventListener("message", function (e: MessageEvent<any>): void {
let data: any = e.data;
let method: string = data.method;
@ -73,7 +74,7 @@ export default class Manager extends cc.Component {
console.log(msg);
}
private _speak(msg: string): void {
public Speak(msg: string): void {
this._text_to_Speech.speak(msg);
}

View File

@ -1,26 +1,40 @@
const responsiveVoice = window["responsiveVoice"];
export default class Text_to_Speech {
//#region 外調參數
private _responsiveVoice: any = window["responsiveVoice"];
private voice: string = null;
//#endregion
//#region Custom
constructor() {
this._responsiveVoice.speak("hello world");
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;
this._responsiveVoice.speak(msg, "Chinese Female", {
onstart: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
onend: function (Callback: any): void {
console.log(`onstart msg: ${msg}`);
},
});
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