File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change 191
191
} ) . join ( ' ' ) . replace ( / \s + / g, ' ' ) ;
192
192
} ;
193
193
194
+ const AudioContext = window . AudioContext || window . webkitAudioContext ;
195
+ const context = new AudioContext ( ) ;
194
196
const audio = ( text , opts ) => {
195
197
const options = getOptions ( opts ) ;
196
198
const morse = encode ( text , opts ) ;
197
- const AudioContext = window . AudioContext || window . webkitAudioContext ;
198
- const context = new AudioContext ( ) ;
199
199
const oscillator = context . createOscillator ( ) ;
200
200
const gainNode = context . createGain ( ) ;
201
201
let timeout ;
234
234
oscillator . connect ( gainNode ) ;
235
235
gainNode . connect ( context . destination ) ;
236
236
237
+
238
+ const play = ( ) => {
239
+ oscillator . start ( context . currentTime ) ;
240
+ timeout = setTimeout ( ( ) => stop ( ) , ( t - context . currentTime ) * 1000 ) ;
241
+ } ;
242
+
243
+ const stop = ( ) => {
244
+ clearTimeout ( timeout ) ;
245
+ timeout = 0 ;
246
+ oscillator . stop ( 0 ) ;
247
+ } ;
248
+
237
249
return {
238
- play : ( ) => {
239
- oscillator . start ( context . currentTime ) ;
240
- timeout = setTimeout ( this . stop . bind ( this ) , ( t - context . currentTime ) * 1000 ) ;
241
- } ,
242
- stop : ( ) => {
243
- clearTimeout ( timeout ) ;
244
- timeout = 0 ;
245
- oscillator . stop ( 0 ) ;
246
- } ,
250
+ play,
251
+ stop,
247
252
context,
248
253
oscillator,
249
254
gainNode
You can’t perform that action at this time.
0 commit comments