1616 < script type ="text/javascript " src ="src/modules/shared/ring-buffer.min.js "> </ script >
1717 < script >
1818 //set correct modules folder
19- SepiaFW . webAudio . defaultProcessorOptions . moduleFolder = "src/modules" ;
19+ if ( window . SepiaFW ) SepiaFW . webAudio . defaultProcessorOptions . moduleFolder = "src/modules" ;
2020 </ script >
2121
2222 < link rel ="stylesheet " type ="text/css " href ="test-pages/recorder.css?v=0.9.7 ">
@@ -39,7 +39,7 @@ <h2>Recorder</h2>
3939 < option value ="toggle-vad "> Toggle ON/VAD OFF</ option >
4040 <!--<option value="push-to-talk">Push-to-talk</option> TODO -->
4141 </ select > </ div >
42- < div class ="group "> < label > Start/Stop:</ label > < button id ="micButton " onclick =" toggleMic(); " > </ button > </ div >
42+ < div class ="group "> < label > Start/Stop:</ label > < button id ="micButton "> </ button > </ div >
4343 < div class ="group "> < label > Gain:</ label > < input id ="microphoneGain " class ="small " type ="number " value ="1.0 " min ="0.1 " max ="100 " step ="0.1 "> </ div >
4444 < div class ="group "> < label > Resources:</ label > < button onclick ="releaseMic(); "> Release</ button > </ div >
4545 </ div >
@@ -60,7 +60,10 @@ <h2>Log <button class="variant-2" onclick="clearMessages()" style="margin: 0 0 0
6060</ div >
6161< script type ='text/javascript ' src ="test-pages/test-commons.js "> </ script >
6262< script type ='text/javascript '>
63-
63+ if ( ! window . SepiaVoiceRecorder ) {
64+ SepiaVoiceRecorder = { notSupported : true } ; //Library not found or not supported (browser <= IE11)
65+ }
66+
6467 //--- Recorder ---
6568
6669 var volumeThresholds = [ 0.05 , 10 ] ; //too low/too high
@@ -124,10 +127,14 @@ <h2>Log <button class="variant-2" onclick="clearMessages()" style="margin: 0 0 0
124127 } ) ;
125128 }
126129 }
127- function releaseMic ( ) {
130+ function releaseMic ( callback ) {
128131 SepiaVoiceRecorder . stopAndReleaseIfActive ( function ( ) {
129- addMessage ( "RELEASED Microphone" ) ;
132+ isLoading = false ;
133+ isRecording = false ;
130134 samplesReceived = null ;
135+ addMessage ( "RELEASED Microphone" ) ;
136+ setMicState ( "idle" ) ;
137+ if ( callback ) callback ( ) ;
131138 } ) ;
132139 }
133140 function onMicError ( ) {
@@ -273,19 +280,44 @@ <h2>Log <button class="variant-2" onclick="clearMessages()" style="margin: 0 0 0
273280 }
274281 }
275282
276- //--- Messages and animations ---
283+ //--- Controls, Messages and Animations ---
277284
278285 var micButton = document . getElementById ( "micButton" ) ;
279286 function setMicState ( state ) {
280- micButton . classList . remove ( "recording" , "loading" ) ;
287+ micButton . classList . remove ( "recording" , "loading" , "reset" ) ;
281288 if ( state == "loading" ) {
282289 micButton . classList . add ( "loading" ) ;
283290 } else if ( state == "recording" ) {
284291 micButton . classList . add ( "recording" ) ;
292+ } else if ( state == "reset" ) {
293+ micButton . classList . add ( "reset" ) ;
285294 } else {
286295 //idle
287296 }
288297 }
298+ var micLongPressTimer = undefined ;
299+ var micIsLongPress = false ;
300+ micButton . addEventListener ( 'pointerdown' , function ( event ) {
301+ clearTimeout ( micLongPressTimer ) ;
302+ micLongPressTimer = setTimeout ( function ( ) {
303+ onMicLongPress ( ) ;
304+ } , 1000 ) ;
305+ } ) ;
306+ micButton . addEventListener ( 'pointerup' , function ( event ) {
307+ clearTimeout ( micLongPressTimer ) ;
308+ if ( ! micIsLongPress ) {
309+ toggleMic ( ) ;
310+ } else {
311+ setMicState ( "" ) ;
312+ }
313+ micIsLongPress = false ;
314+ } ) ;
315+ function onMicLongPress ( ) {
316+ micIsLongPress = true ;
317+ releaseMic ( function ( ) {
318+ if ( micIsLongPress ) setMicState ( "reset" ) ;
319+ } ) ;
320+ }
289321
290322 var volumeBar = document . getElementById ( "volumeBar" ) ;
291323 var volBarPassedCheck = false ;
@@ -325,6 +357,7 @@ <h2>Log <button class="variant-2" onclick="clearMessages()" style="margin: 0 0 0
325357 messages . style . height = "150px" ;
326358 }
327359 function showInfoModal ( msg ) {
360+ if ( ! window . createModal ) { alert ( msg ) ; return ; }
328361 var modalContent = document . createElement ( "div" ) ;
329362 modalContent . textContent = msg ;
330363 var mod = createModal ( modalContent , "480px" , "85%" ) ;
@@ -336,9 +369,12 @@ <h2>Log <button class="variant-2" onclick="clearMessages()" style="margin: 0 0 0
336369 }
337370
338371 // ON READY
339-
340- setVolume ( 0 ) ;
341- setMicState ( "idle" ) ;
372+ if ( SepiaVoiceRecorder . notSupported ) {
373+ showInfoModal ( "SEPIA Web Audio Library not found or not supported (IE11?)!" ) ;
374+ } else {
375+ setVolume ( 0 ) ;
376+ setMicState ( "idle" ) ;
377+ }
342378</ script >
343379</ body >
344380</ html >
0 commit comments