Skip to content

Commit

Permalink
#51- Play Historical Audio, Refactor, Add Voice Notes UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanHacks committed Mar 20, 2023
1 parent 4d9c919 commit 98aa7d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
11 changes: 6 additions & 5 deletions aigenAudioAutoPlay/audioAutoPlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
26 changes: 20 additions & 6 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 98aa7d2

Please sign in to comment.