-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathRS_MessageTTS.js
83 lines (65 loc) · 2.4 KB
/
RS_MessageTTS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//================================================================
// RS_MessageTTS.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2020 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
//================================================================
/*:
* @plugindesc <RS_MessageTTS>
* @author biud436
*
* @help
*
*/
var Imported = Imported || {};
Imported.RS_MessageTTS = true;
var RS = RS || {};
RS.MessageTTS = RS.MessageTTS || {};
(function($) {
"use strict";
var parameters = $plugins.filter(function (i) {
return i.description.contains('<RS_MessageTTS>');
});
parameters = (parameters.length > 0) && parameters[0].parameters;
RS.MessageTTS.Params = {};
RS.MessageTTS.Params.rate = 1.2;
RS.MessageTTS.Params.volume = 1.0;
var alias_Game_System_initialize = Game_System.prototype.initialize;
Game_System.prototype.initialize = function() {
alias_Game_System_initialize.call(this);
this._isValidTTS = true;
if(!Utils.isNwjs()) {
this.disableTTF();
}
};
Game_System.prototype.isValidTTS = function() {
return this._isValidTTS;
};
Game_System.prototype.enableTTF = function() {
this._isValidTTS = true;
};
Game_System.prototype.disableTTF = function() {
this._isValidTTS = false;
};
var alias_Window_Message_newPage = Window_Message.prototype.newPage;
Window_Message.prototype.newPage = function(textState) {
alias_Window_Message_newPage.call(this, textState);
let lang = navigator.language;
if($gameSystem.isKorean()) lang = 'ko-KR';
if(!Utils.isNwjs()) return;
chrome.tts.isSpeaking(value => {
if(!value) {
const p = RS.MessageTTS.Params;
chrome.tts.speak(textState.text, {'lang': lang, 'rate': p.rate, 'volume': p.volume});
}
});
};
var alias_Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if(command === "EnableTTF") $gameSystem.enableTTF();
if(command === "DisableTTF") $gameSystem.disableTTF();
};
})(RS.MessageTTS);