Add base code
This commit is contained in:
74
cmd/process.go
Normal file
74
cmd/process.go
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright © 2024 Matteo Schiff <matteo@underdesk.net>
|
||||
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.underdesk.net/Matte23/transcriber/internal/llm"
|
||||
"git.underdesk.net/Matte23/transcriber/internal/stt"
|
||||
"git.underdesk.net/Matte23/transcriber/internal/video"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// processCmd represents the process command
|
||||
var processCmd = &cobra.Command{
|
||||
Use: "process",
|
||||
Short: "Process video file by generating text notes",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
inputFile := cmd.Flag("input").Value.String()
|
||||
filename, _, _ := strings.Cut(inputFile, ".")
|
||||
|
||||
audioFile := "./output/" + filename + ".wav"
|
||||
transcriptionFile := "./output/" + filename + ".transcription.txt"
|
||||
splitFile := "./output/" + filename + ".split.json"
|
||||
finalFile := "./output/" + filename + ".md"
|
||||
|
||||
config := openai.DefaultConfig("")
|
||||
config.BaseURL = "http://192.168.1.111:8080/v1"
|
||||
client := openai.NewClientWithConfig(config)
|
||||
|
||||
log.Println("Starting video to audio conversion")
|
||||
video.ExtractVideo(inputFile, audioFile)
|
||||
log.Println("Conversion terminated")
|
||||
|
||||
transcriber := stt.NewWhisperTranscriver(client)
|
||||
log.Println("Starting audio transcription")
|
||||
transcription, _ := transcriber.Transcribe(audioFile, transcriptionFile)
|
||||
log.Println("Audio transcription terminated")
|
||||
|
||||
splitter := llm.NewStructureBuilder(client)
|
||||
log.Println("Starting splitting transcription")
|
||||
paragraphs, _ := splitter.Split(splitFile, transcription)
|
||||
log.Println("Transcription splitted")
|
||||
|
||||
llm.RewriteText(client, paragraphs, finalFile)
|
||||
|
||||
log.Println("Text rewrite completed!")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(processCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// processCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
processCmd.Flags().StringP("input", "i", "./input.mp4", "Input video to be processed")
|
||||
}
|
||||
Reference in New Issue
Block a user