@@ -506,6 +506,8 @@ function SampleWidget() {
506506 _ ( "Trim" ) ,
507507 ""
508508 ) ;
509+
510+ let generating = false ;
509511
510512 this . _promptBtn . onclick = ( ) => {
511513
@@ -564,6 +566,18 @@ function SampleWidget() {
564566 textArea . style . border = "none"
565567 textArea . style . padding = "15px" ;
566568 textArea . placeholder = randomPrompt ;
569+ textArea . addEventListener ( "input" , function ( ) {
570+
571+ if ( generating ) {
572+ submit . disabled = true ;
573+ preview . disabled = true ;
574+ save . disabled = true ;
575+ } else {
576+ submit . disabled = false ;
577+ preview . disabled = true ;
578+ save . disabled = true ;
579+ }
580+ } )
567581
568582 const buttonDiv = document . createElement ( "div" ) ;
569583 buttonDiv . style . display = "flex" ;
@@ -579,12 +593,17 @@ function SampleWidget() {
579593 submit . style . cursor = "pointer" ;
580594 submit . innerHTML = "Submit" ;
581595 submit . onclick = async function ( ) {
596+
597+ submit . disabled = true ;
598+
582599 const prompt = textArea . value ;
583600 const encodedPrompt = encodeURIComponent ( prompt ) ;
584601 const url = `http://localhost:8000/generate?prompt=${ encodedPrompt } ` ;
585602
586603 try {
587604
605+ generating = true ;
606+
588607 activity . textMsg ( _ ( "Generating Audio..." ) , 2500 )
589608
590609 let blinkInterval = setInterval ( ( ) => {
@@ -597,13 +616,16 @@ function SampleWidget() {
597616 clearInterval ( blinkInterval ) ;
598617
599618 if ( result . status === "success" ) {
619+ generating = false ;
600620 activity . textMsg ( _ ( "Audio ready!" ) , 3000 ) ;
601621 preview . disabled = false ;
602622 save . disabled = false ;
603623 } else {
624+ generating = false ;
604625 activity . textMsg ( _ ( "Failed to generate audio" ) , 3000 ) ;
605626 }
606627 } catch ( error ) {
628+ generating = false ;
607629 activity . textMsg ( _ ( "Error occurred" ) , 3000 ) ;
608630 }
609631 } ;
@@ -693,7 +715,7 @@ function SampleWidget() {
693715 divUploadSample . style . alignItems = "center" ;
694716
695717 const uploadSample = document . createElement ( "img" ) ;
696- uploadSample . setAttribute ( "src" , ".. /header-icons/load-media.svg" ) ;
718+ uploadSample . setAttribute ( "src" , "/header-icons/load-media.svg" ) ;
697719 uploadSample . style . height = "32px" ;
698720 uploadSample . style . width = "32px" ;
699721
@@ -774,6 +796,18 @@ function SampleWidget() {
774796 preview . style . cursor = "pointer" ;
775797 preview . innerHTML = "Preview" ;
776798
799+ preview . onclick = async function ( ) {
800+ const from = fromInputBox . value
801+ const to = toInputBox . value
802+
803+ const audioURL = `http://localhost:8000/trim-preview?start=${ from } &end=${ to } ` ;
804+
805+ const audio = new Audio ( audioURL ) ;
806+ audio . play ( ) ;
807+ save . disabled = false ;
808+
809+ }
810+
777811 const save = document . createElement ( "button" ) ;
778812 save . style . width = "152px" ;
779813 save . style . height = "61px" ;
@@ -782,6 +816,16 @@ function SampleWidget() {
782816 save . style . border = "none"
783817 save . style . cursor = "pointer" ;
784818 save . innerHTML = "Save" ;
819+ save . disabled = true ;
820+ save . onclick = function ( ) {
821+ const audioURL = `http://localhost:8000/trim-save` ;
822+ const link = document . createElement ( 'a' ) ;
823+ link . href = audioURL ;
824+ link . download = 'trimmed-output.wav' ;
825+ document . body . appendChild ( link ) ;
826+ link . click ( ) ;
827+ document . body . removeChild ( link ) ;
828+ }
785829
786830 buttonDiv . appendChild ( preview ) ;
787831 buttonDiv . appendChild ( save ) ;
0 commit comments