[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, "isPlugin": true,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
"loadPluginInEditor": true, "loadPluginInEditor": false,
"subMetas": {} "subMetas": {}
} }

View File

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

View File

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