diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 95c2ae8..4055543 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ github: [c-loftus] +custom: ["https://www.paypal.com/paypalme/coltonloftus"] \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index ec51078..9df6679 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "editor.formatOnType": true, // hide git ignored files - "explorer.excludeGitIgnore": false + "explorer.excludeGitIgnore": false, + "go.testFlags": ["-count=1"] // disable caching for go tests } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9946d5e..d846e94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # docker build -t quickpiperaudiobook . # docker run quickpiperaudiobook /app/examples/lorem_ipsum.txt -FROM --platform=linux/amd64 golang:latest as build +FROM --platform=linux/amd64 golang:1.22 as build WORKDIR /app diff --git a/cli/cli.go b/cli/cli.go index 2b6c3b6..ae712a1 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -146,6 +146,9 @@ func RunCLI() { if err != nil { fmt.Printf("Error: %v\n", err) ctx.FatalIfErrorf(err) + } else if data == nil { + fmt.Println("After converting" + cli.Input + "to txt, no data was generated.") + return } else { fmt.Println("Text conversion completed successfully.") } diff --git a/cli/e2e_test.go b/cli/e2e_test.go index 5a0ba1e..f445a72 100644 --- a/cli/e2e_test.go +++ b/cli/e2e_test.go @@ -12,3 +12,11 @@ func TestCLI(t *testing.T) { os.Args = append(os.Args, "https://example-files.online-convert.com/document/txt/example.txt") RunCLI() } + +func TestCLIWithDiacritics(t *testing.T) { + // reset all cli args, since the golang testing framework changes them + os.RemoveAll(configDir) + os.Args = os.Args[:1] + os.Args = append(os.Args, "https://example-files.online-convert.com/document/txt/example.txt", "--speak-diacritics") + RunCLI() +} diff --git a/lib/piper.go b/lib/piper.go index a6c62c3..05203b9 100644 --- a/lib/piper.go +++ b/lib/piper.go @@ -16,8 +16,11 @@ import ( "github.com/gen2brain/beeep" ) -func RunPiper(filename string, // we need to have the filename here since the file passed in is a tmp file and a dummy name - model string, file *os.File, outdir string) error { +func RunPiper( + filename string, // filename must be specified since the file passed in is a tmp file and a dummy name + model string, // piper model used + file *os.File, // file with text to convert + outdir string) error { // Debugging: Read file content to check if it's empty fileContent, err := io.ReadAll(file) diff --git a/lib/textProcessing.go b/lib/textProcessing.go index a8cd5e4..ae2cc83 100644 --- a/lib/textProcessing.go +++ b/lib/textProcessing.go @@ -12,11 +12,11 @@ import ( func RemoveDiacritics(file *os.File) (*os.File, error) { if file == nil { - return nil, fmt.Errorf("file is nil") + return nil, fmt.Errorf("file to remove diacritics from is nil") } // Create a temporary file for the output - tmpFile, err := os.CreateTemp("", "diacritics-removed-*.txt") + tmpFile, err := os.CreateTemp("/tmp/", "diacritics-removed-*.txt") if err != nil { return nil, fmt.Errorf("failed to create temporary file: %v", err) } @@ -106,8 +106,6 @@ func GetConvertedRawText(inputPath string) (*os.File, error) { if err != nil { return nil, fmt.Errorf("failed to create temporary file: %v", err) } - defer tmpFile.Close() - c := color.New(color.Bold, color.FgMagenta) c.Println("Converting " + filepath.Base(inputPath) + " to the proper intermediary text format...") diff --git a/lib/textProcessing_test.go b/lib/textProcessing_test.go index 6cda31a..ff2c1e9 100644 --- a/lib/textProcessing_test.go +++ b/lib/textProcessing_test.go @@ -2,6 +2,7 @@ package lib import ( "os" + "path/filepath" "testing" ) @@ -88,7 +89,42 @@ func TestRemoveDiacritics_FileNotExist(t *testing.T) { t.Fatal("expected error but got nil") } - if err.Error() != "file is nil" { + if err.Error() != "file to remove diacritics from is nil" { t.Errorf("unexpected error: got %v, want %v", err.Error(), "file is nil") } } + +func TestPiperWithRemovedDiacritics(t *testing.T) { + homeDir, _ := os.UserHomeDir() + path := filepath.Join(homeDir, ".config/QuickPiperAudiobook") + + if !PiperIsInstalled(path) { + if err := InstallPiper(path); err != nil { + t.Fatalf("error installing piper: %v", err) + } + } + + model := "en_US-hfc_male-medium.onnx" + if err := DownloadModelIfNotExists(model, "."); err != nil { + t.Fatalf("error grabbing model: %v", err) + } + + // read in test_diacritics.txt + inputFile, err := os.Open("test_diacritics.txt") + if err != nil { + t.Fatalf("failed to open input file: %v", err) + } + defer inputFile.Close() + + // Call RemoveDiacritics function + outputFile, err := RemoveDiacritics(inputFile) + if err != nil { + t.Fatalf("RemoveDiacritics failed: %v", err) + } + defer os.Remove(outputFile.Name()) + + if err := RunPiper("test_diacritics.txt", model, outputFile, "/tmp/"); err != nil { + t.Fatalf("error running piper: %v", err) + } + +}