@@ -115,7 +115,7 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
115
115
return {
116
116
result : true ,
117
117
message : _trim ( text ) ,
118
- hash : hashCode ( text ) ,
118
+ hash : hashCode ( text + new Date ( ) . getTime ( ) ) ,
119
119
} ;
120
120
} ;
121
121
@@ -125,49 +125,56 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
125
125
* 한번에 로드가 가능하도록 매번 로더를 따로 만들어서 사용하도록 수정
126
126
* https://github.com/CreateJS/PreloadJS/issues/232#issuecomment-338739115
127
127
* */
128
- const read = function ( args ) {
129
- const { message, hash, prop, callback } = args ;
130
- const tts = Entry . AI_UTILIZE_BLOCK . tts ;
131
- const id = `tts-${ hash } -${ JSON . stringify ( prop ) } ` ;
132
- const type = createjs . LoadQueue . SOUND ;
128
+ const read = async function ( args , isWait ) {
129
+ const currentInstance = new Promise ( ( resolve , reject ) => {
130
+ const { message, hash, prop } = args ;
131
+ const tts = Entry . AI_UTILIZE_BLOCK . tts ;
132
+ const id = `tts-${ hash } -${ JSON . stringify ( prop ) } ` ;
133
+ const type = createjs . LoadQueue . SOUND ;
133
134
134
- const soundQueue = new createjs . LoadQueue ( true ) ;
135
- soundQueue . installPlugin ( createjs . Sound ) ;
136
- soundQueue . maintainScriptOrder = true ;
137
- const src = `${ Entry . baseUrl } ${ Entry . AI_UTILIZE_BLOCK . tts . api } .mp3?${ toQueryString ( {
138
- text : message ,
139
- ...prop ,
140
- } ) } `;
141
-
142
- const loadHandler = ( { currentTarget } ) => {
143
- const items = currentTarget . getItems ( ) . map ( ( { item } ) => item ) ;
144
- tts . loadQueue = tts . loadQueue . filter ( ( id ) => {
145
- const filtered = items . find ( ( item ) => item . id === id ) ;
146
- if ( filtered ) {
147
- const instance = Entry . Utils . playSound ( id , filtered . prop ) ;
148
- instance . soundType = 'tts' ;
149
- Entry . Utils . addSoundInstances ( instance ) ;
150
- if ( filtered . callback ) {
135
+ const soundQueue = new createjs . LoadQueue ( true ) ;
136
+ soundQueue . installPlugin ( createjs . Sound ) ;
137
+ soundQueue . maintainScriptOrder = true ;
138
+ const src = `${ Entry . baseUrl } ${ Entry . AI_UTILIZE_BLOCK . tts . api } .mp3?${ toQueryString ( {
139
+ text : message ,
140
+ ...prop ,
141
+ } ) } `;
142
+ const loadHandler = ( { currentTarget } ) => {
143
+ const items = currentTarget . getItems ( ) . map ( ( { item } ) => item ) ;
144
+ tts . loadQueue = tts . loadQueue . filter ( ( id ) => {
145
+ const filtered = items . find ( ( item ) => item . id === id ) ;
146
+ if ( filtered ) {
147
+ const instance = Entry . Utils . playSound ( id , filtered . prop ) ;
148
+ instance . soundType = 'tts' ;
149
+ Entry . Utils . addSoundInstances ( instance ) ;
151
150
const duration =
152
151
instance . duration > 0 ? instance . duration : filtered . duration * 300 ;
153
- setTimeout ( filtered . callback , duration ) ;
152
+ setTimeout ( ( ) => {
153
+ resolve ( ) ;
154
+ } , duration ) ;
154
155
}
155
- return false ;
156
+ return true ;
157
+ } ) ;
158
+ } ;
159
+ // if Error, retry
160
+ const errorHandler = async ( error ) => {
161
+ soundQueue . removeEventListener ( 'complete' , loadHandler ) ;
162
+ soundQueue . removeEventListener ( 'error' , errorHandler ) ;
163
+ soundQueue . destroy ( ) ;
164
+ if ( isWait ) {
165
+ await read ( args , true ) ;
166
+ } else {
167
+ read ( args ) ;
156
168
}
157
- return true ;
158
- } ) ;
159
- } ;
160
- // if Error, retry
161
- const errorHandler = ( error ) => {
162
- soundQueue . removeEventListener ( 'complete' , loadHandler ) ;
163
- soundQueue . removeEventListener ( 'error' , errorHandler ) ;
164
- soundQueue . destroy ( ) ;
165
- read ( args ) ;
166
- } ;
167
- soundQueue . on ( 'complete' , loadHandler ) ;
168
- soundQueue . on ( 'error' , errorHandler ) ;
169
- soundQueue . loadFile ( { id, src, type, prop, callback, duration : message . length } ) ;
170
- tts . loadQueue . push ( id ) ;
169
+ } ;
170
+ soundQueue . on ( 'complete' , loadHandler ) ;
171
+ soundQueue . on ( 'error' , errorHandler ) ;
172
+ soundQueue . loadFile ( { id, src, type, prop, duration : message . length } ) ;
173
+ tts . loadQueue . push ( id ) ;
174
+ } ) ;
175
+ if ( isWait ) {
176
+ return await currentInstance ;
177
+ }
171
178
} ;
172
179
173
180
return {
@@ -289,29 +296,19 @@ Entry.AI_UTILIZE_BLOCK.tts.getBlocks = function() {
289
296
} ,
290
297
class : 'tts' ,
291
298
isNotFor : [ 'tts' ] ,
292
- func ( sprite , script ) {
299
+ async func ( sprite , script ) {
293
300
const { result, message, hash } = checkText ( script . getStringValue ( 'TEXT' , script ) ) ;
294
301
const prop = sprite . getVoiceProp ( ) ;
295
302
if ( result ) {
296
- if ( ! script . isPlay ) {
297
- script . isPlay = true ;
298
- script . playState = 1 ;
299
- read ( {
303
+ await read (
304
+ {
300
305
message,
301
306
hash,
302
307
prop,
303
- callback : ( ) => {
304
- script . playState = 0 ;
305
- } ,
306
- } ) ;
307
- return script ;
308
- } else if ( script . playState == 1 ) {
309
- return script ;
310
- } else {
311
- delete script . playState ;
312
- delete script . isPlay ;
313
- return script . callReturn ( ) ;
314
- }
308
+ } ,
309
+ true
310
+ ) ;
311
+ return script . callReturn ( ) ;
315
312
}
316
313
} ,
317
314
syntax : {
0 commit comments