diff --git a/aigenAudioAutoPlay/audioAutoPlay.go b/aigenAudioAutoPlay/audioAutoPlay.go index 086f68e..f91f5e4 100644 --- a/aigenAudioAutoPlay/audioAutoPlay.go +++ b/aigenAudioAutoPlay/audioAutoPlay.go @@ -91,17 +91,18 @@ func PlayAudioPlayback(filename string) error { return fmt.Errorf("failed to start device: %w", err) } fmt.Println("Recording") - durationMillis := audioLength / 50 // Set loop duration to 10 seconds (in milliseconds) + durationMillis := audioLength / 60 // Set loop duration to 10 seconds (in milliseconds) for i := durationMillis; i >= 0; i-- { time.Sleep(1 * time.Millisecond) if i == 0 { - break // Exit the loop if duration has elapsed } - //// Do something here (e.g. print a message) - //fmt.Println(i/1000, "seconds remaining") - + // Log the counter + if i%1000 == 0 { + fmt.Print("Playing Back") + fmt.Printf("_____%v__seconds______\r", i/1000) + } } return nil } diff --git a/chat.go b/chat.go index 497689b..643bc34 100644 --- a/chat.go +++ b/chat.go @@ -47,13 +47,26 @@ func addChatBubble(box *fyne.Container, message string, isUser bool) { audioFile := widget.NewButtonWithIcon("Audio", theme.MediaPlayIcon(), func() { //Play audio log.Printf("Playing audio file %s", audio) - err := aigenAudioAutoPlay.PlayAudioPlayback("cache/voice_20032023143853YKDYUN.wav") - if err != nil { - log.Printf("Error: %s", err) - } - log.Printf("Audio file %s played successfully", audio) }) + audioFile.OnTapped = func() { + //change icon to stop + audioFile.SetIcon(nil) + + audioFile.Refresh() + //Play audio + defer func(filename string) { + err := aigenAudioAutoPlay.PlayAudioPlayback(filename) + if err != nil { + log.Printf("Error: %s", err) + } + log.Printf("Audio file %s played successfully", filename) + audioFile.SetIcon(theme.MediaPlayIcon()) + }(audio) + + log.Printf("Playing audio file %s", audio) + return + } messageCard = widget.NewCard("", "", label) messageCard.Content = container.NewHBox(audioFile, messageCard.Content) @@ -109,7 +122,8 @@ func voiceChatButton(inputBox *widget.Entry, tab1 *fyne.Container) *widget.Butto if recordingError(err) { return } - log.Printf("Voice recorder started: %v", recorder) + + log.Printf("Voice recorder __ started: %v", recorder) message := aigenRest.Whisper(recorder)