Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
seemywingz committed May 23, 2024
1 parent da59d9a commit eb57f23
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 78 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM golang:1.21.5-alpine3.19 AS builder
FROM golang:1.22.3-alpine3.20 AS builder
ENV APP_NAME pluralia
ENV WORKDIR /app
WORKDIR $WORKDIR
Expand Down
13 changes: 5 additions & 8 deletions cmd/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,19 @@ var chatCmd = &cobra.Command{
var err error
if convo {
for {
response, audio := chatResponse(prompt)
response, _ := chatResponse(prompt)
fmt.Println("\npluralia:")
syntaxHighlight(response)
if narrate {
playAudio(audio)
}
// if narrate {
// playAudio(audio)
// }
fmt.Print("\nYou:\n ")
prompt, err = getUserInput()
catchErr(err, "warn")
}
} else {
response, audio := chatResponse(prompt)
response, _ := chatResponse(prompt)
syntaxHighlight(response)
if narrate {
playAudio(audio)
}
}
},
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&convo, "convo", "c", false, "Conversational Style chat")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
rootCmd.PersistentFlags().BoolVarP(&narrate, "narrate", "n", false, "Narrate the response using TTS and the default audio output")
rootCmd.PersistentFlags().StringVar(&voice, "voice", "onyx", "Voice to use: alloy, echo, fable, onyx, nova, and shimmer")

// Check for Required Environment Variables
OPENAI_API_KEY = os.Getenv("OPENAI_API_KEY")
Expand Down Expand Up @@ -129,10 +128,10 @@ func viperConfig() {

viper.SetDefault("printify_endpoint", "https://api.printify.com/v1/")

viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED the config file does not have an extension
viper.AddConfigPath(".") // look for config in the working directory
viper.AddConfigPath("./files") // look for config in the working directory /files
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED the config file does not have an extension
viper.AddConfigPath(".") // look for config in the working directory
viper.AddConfigPath("./files") // look for config in the working directory /files
viper.AddConfigPath("$HOME/.pluralia") // call multiple times to add many search paths

if configFile != "" {
Expand Down
8 changes: 4 additions & 4 deletions cmd/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ var ttsCmd = &cobra.Command{
You can use the TTS API to generate audio from text.
`,
Run: func(cmd *cobra.Command, args []string) {
audio := tts(prompt)
if audio != nil {
playAudio(audio)
}
// audio := tts(prompt)
// if audio != nil {
// playAudio(audio)
// }
},
}

Expand Down
59 changes: 0 additions & 59 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"bytes"
"fmt"
"io"
"net/url"
"os"
"path/filepath"
Expand All @@ -16,9 +15,6 @@ import (
"github.com/alecthomas/chroma/formatters"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/styles"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/pterm/pterm"
)

Expand Down Expand Up @@ -185,58 +181,3 @@ func trace() {
file, line := f.FileLine(pc[0])
fmt.Printf("%s:%d\n%s\n", file, line, f.Name())
}

// playAudio plays audio from a byte slice.
func playAudio(audioContent []byte) {
if verbose {
fmt.Println("🔊 Playing audio...")
}

// Create an io.Reader from the byte slice
reader := bytes.NewReader(audioContent)

// Wrap the reader in a NopCloser to make it an io.ReadCloser.
readCloser := io.NopCloser(reader)

// Decode the MP3 stream.
streamer, format, err := mp3.Decode(readCloser)
catchErr(err)
defer streamer.Close()

// Initialize the speaker with the sample rate of the audio and a buffer size.
err = speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
catchErr(err)

// Play the decoded audio.
done := make(chan bool)
speaker.Play(beep.Seq(streamer, beep.Callback(func() {
done <- true
})))

// Wait for the audio to finish playing.
<-done
}

func playMP3File(file string) {
if verbose {
fmt.Println("🔊 Playing audio file:", file)
}

f, err := os.Open(file)
catchErr(err)
defer f.Close()

streamer, format, err := mp3.Decode(f)
catchErr(err)
defer streamer.Close()

err = speaker.Init(format.SampleRate, format.SampleRate.N(time.Second/10))
catchErr(err)

done := make(chan bool)
speaker.Play(beep.Seq(streamer, beep.Callback(func() {
done <- true
})))

<-done
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ require (
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
github.com/hajimehoshi/oto v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
Expand Down

0 comments on commit eb57f23

Please sign in to comment.