Skip to content

Commit

Permalink
json output
Browse files Browse the repository at this point in the history
  • Loading branch information
voidKandy committed Sep 20, 2024
1 parent 54857bb commit 1e04144
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions cmd/transcribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -25,16 +26,31 @@ var transcribeCmd = &cobra.Command{
if len(args) == 0 {
return fmt.Errorf("%s", "no file path provided\n")
}

transcriptionMap := make(map[string]string)
transcriptions, err := transcribe(args)
if err != nil {
return err
}
for _, trans := range transcriptions {
_, err := io.WriteString(os.Stdout, trans+"\n")
if err != nil {
return fmt.Errorf("error writing to stdout: %v", err)
}

for i, trans := range transcriptions {
transcriptionMap[args[i]] = trans
// _, err := io.WriteString(os.Stdout, trans+"\n")
// if err != nil {
// return fmt.Errorf("error writing to stdout: %v", err)
// }
}

jsonOutput, err := json.Marshal(transcriptionMap)
if err != nil {
return fmt.Errorf("error marshaling to JSON: %v", err)
}

_, err = io.WriteString(os.Stdout, string(jsonOutput)+"\n")
if err != nil {
return fmt.Errorf("error writing to stdout: %v", err)
}

return nil
},
}
Expand Down Expand Up @@ -90,5 +106,9 @@ func transcribe(fps []string) ([]string, error) {

returnStrings = strings.Split(strings.ToLower(output), embed.SeparatorExpectedString)

for _, str := range returnStrings {
str = fmt.Sprintf("---%s---\n", str)
}

return returnStrings, nil
}

0 comments on commit 1e04144

Please sign in to comment.