@@ -173,8 +173,9 @@ export class WaterfallSpectrogram {
173173 // Audio
174174 const stream = await navigator . mediaDevices . getUserMedia ( { audio : { echoCancellation : false , noiseSuppression : false } , video : false } )
175175 this . mediaStream = stream
176- const AudioCtx : typeof AudioContext = ( window as unknown as { AudioContext ?: typeof AudioContext ; webkitAudioContext ?: typeof AudioContext } ) . AudioContext
177- ?? ( window as unknown as { webkitAudioContext ?: typeof AudioContext } ) . webkitAudioContext
176+ type AudioContextConstructor = { new ( contextOptions ?: AudioContextOptions ) : AudioContext }
177+ const AudioCtx : AudioContextConstructor | undefined = window . AudioContext ?? window . webkitAudioContext
178+ if ( ! AudioCtx ) throw new Error ( 'Web Audio API not supported' )
178179 const audioContext = new AudioCtx ( )
179180 this . audioContext = audioContext
180181 this . contextStartTime = audioContext . currentTime
@@ -201,8 +202,9 @@ export class WaterfallSpectrogram {
201202 if ( this . disposed ) throw new Error ( 'Instance disposed' )
202203 if ( this . animationFrameId ) this . stop ( )
203204 const arrayBuf = await file . arrayBuffer ( )
204- const AudioCtx : typeof AudioContext = ( window as unknown as { AudioContext ?: typeof AudioContext ; webkitAudioContext ?: typeof AudioContext } ) . AudioContext
205- ?? ( window as unknown as { webkitAudioContext ?: typeof AudioContext } ) . webkitAudioContext
205+ type AudioContextConstructor = { new ( contextOptions ?: AudioContextOptions ) : AudioContext }
206+ const AudioCtx : AudioContextConstructor | undefined = window . AudioContext ?? window . webkitAudioContext
207+ if ( ! AudioCtx ) throw new Error ( 'Web Audio API not supported' )
206208 const audioContext = new AudioCtx ( )
207209 this . audioContext = audioContext
208210 this . contextStartTime = audioContext . currentTime
0 commit comments