Add base code

This commit is contained in:
2024-11-09 22:57:47 +01:00
parent 967f80d734
commit c7b40276cf
14 changed files with 975 additions and 0 deletions

74
cmd/process.go Normal file
View 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")
}

52
cmd/root.go Normal file
View File

@@ -0,0 +1,52 @@
/*
Copyright © 2024 Matteo Schiff <matteo@underdesk.net>
*/
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "transcriber",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. 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.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.transcriber.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}