zveinn 3 months ago
parent
commit
19ecc97519
9 changed files with 13 additions and 286 deletions
  1. 4 7
      go.mod
  2. 4 12
      go.sum
  3. 0 37
      keyboard.go
  4. 2 2
      main.go
  5. 0 63
      mic-linux/main.go
  6. BIN
      mic-linux/test.wav
  7. 0 159
      mic/main.go
  8. BIN
      mic/output.wav
  9. 3 6
      variables.go

+ 4 - 7
go.mod

@@ -1,17 +1,14 @@
 module github.com/zveinn/twitch-bot
 
-go 1.22.4
+go 1.24.1
 
 require (
-	github.com/MarkKremer/microphone/v2 v2.0.1
 	github.com/gempir/go-twitch-irc/v4 v4.2.0
 	github.com/google/uuid v1.6.0
 	github.com/gopxl/beep v1.4.1
-	github.com/gopxl/beep/v2 v2.1.1
-	github.com/gorilla/websocket v1.5.3
 	github.com/joho/godotenv v1.5.1
 	github.com/nicklaw5/helix v1.25.0
-	go.mongodb.org/mongo-driver v1.17.1
+	go.mongodb.org/mongo-driver v1.17.4
 )
 
 require (
@@ -19,11 +16,11 @@ require (
 	github.com/ebitengine/purego v0.8.0 // indirect
 	github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
 	github.com/golang/snappy v0.0.4 // indirect
-	github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5 // indirect
 	github.com/hajimehoshi/go-mp3 v0.3.4 // indirect
-	github.com/klauspost/compress v1.13.6 // indirect
+	github.com/klauspost/compress v1.16.7 // indirect
 	github.com/montanaflynn/stats v0.7.1 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
+	github.com/stretchr/testify v1.10.0 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect
 	github.com/xdg-go/stringprep v1.0.4 // indirect

+ 4 - 12
go.sum

@@ -1,5 +1,3 @@
-github.com/MarkKremer/microphone/v2 v2.0.1 h1:PWI0MgBu3Nd9CSxdnIjwol8qshstNfywERIMOLD03Zk=
-github.com/MarkKremer/microphone/v2 v2.0.1/go.mod h1:IdM74GKdsZAWVbkgX8xLGAdd4ytzBt7uk5F0brfTZRM=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/ebitengine/oto/v3 v3.3.2 h1:VTWBsKX9eb+dXzaF4jEwQbs4yWIdXukJ0K40KgkpYlg=
@@ -18,19 +16,13 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/gopxl/beep v1.4.1 h1:WqNs9RsDAhG9M3khMyc1FaVY50dTdxG/6S6a3qsUHqE=
 github.com/gopxl/beep v1.4.1/go.mod h1:A1dmiUkuY8kxsvcNJNUBIEcchmiP6eUyCHSxpXl0YO0=
-github.com/gopxl/beep/v2 v2.1.1 h1:6FYIYMm2qPAdWkjX+7xwKrViS1x0Po5kDMdRkq8NVbU=
-github.com/gopxl/beep/v2 v2.1.1/go.mod h1:ZAm9TGQ9lvpoiFLd4zf5B1IuyxZhgRACMId1XJbaW0E=
-github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5 h1:5AlozfqaVjGYGhms2OsdUyfdJME76E6rx5MdGpjzZpc=
-github.com/gordonklaus/portaudio v0.0.0-20230709114228-aafa478834f5/go.mod h1:WY8R6YKlI2ZI3UyzFk7P6yGSuS+hFwNtEzrexRyD7Es=
-github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
-github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
 github.com/hajimehoshi/go-mp3 v0.3.4 h1:NUP7pBYH8OguP4diaTZ9wJbUbk3tC0KlfzsEpWmYj68=
 github.com/hajimehoshi/go-mp3 v0.3.4/go.mod h1:fRtZraRFcWb0pu7ok0LqyFhCUrPeMsGRSVop0eemFmo=
 github.com/hajimehoshi/oto/v2 v2.3.1/go.mod h1:seWLbgHH7AyUMYKfKYT9pg7PhUu9/SisyJvNTT+ASQo=
 github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
 github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
-github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
-github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
+github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
+github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
 github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
 github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
 github.com/nicklaw5/helix v1.25.0 h1:Mrz537izZVsGdM3I46uGAAlslj61frgkhS/9xQqyT/M=
@@ -52,8 +44,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi
 github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM=
 github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI=
 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
-go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
-go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
+go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
+go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=

+ 0 - 37
keyboard.go

@@ -2,15 +2,6 @@
 
 package main
 
-import (
-	"fmt"
-	"log"
-	"syscall"
-	"time"
-
-	"github.com/zveinn/twitch-bot/mic"
-)
-
 const (
 	// Add more keys as constants here if needed
 	VK_LBUTTON  = 0x01 // Left mouse button
@@ -86,31 +77,3 @@ const (
 	VK_APPS  = 0x5D // Applications key (Natural keyboard)
 	VK_SLEEP = 0x5F // Computer Sleep key
 )
-
-func captureKeys() {
-	defer func() {
-		r := recover()
-		if r != nil {
-			log.Println(r)
-		}
-		monitor <- 13
-	}()
-
-	user32 := syscall.NewLazyDLL("user32.dll")
-	getAsyncKeyState := user32.NewProc("GetAsyncKeyState")
-
-	fmt.Println("Listening for key presses... Press Ctrl+C to exit.")
-
-	for {
-		for _, vkCode := range []int{VK_XBUTTON2} {
-			r1, _, _ := getAsyncKeyState.Call(uintptr(vkCode))
-			if r1&0x8000 != 0 { // Check if the key is down
-				fmt.Printf("Key %#x is down\n", vkCode)
-				x := mic.TalkToEve()
-				fmt.Println("POST TRANSCRIBE: ", x)
-				PlaceBotEventInQueue("eve", x, x)
-			}
-		}
-		time.Sleep(time.Millisecond * 50) // To prevent excessive CPU usage
-	}
-}

+ 2 - 2
main.go

@@ -89,8 +89,8 @@ func main() {
 	if err != nil {
 		log.Fatal("Error loading .env file")
 	}
-	// MakeNewToken()
-	// os.Exit(1)
+	MakeNewToken()
+	os.Exit(1)
 
 	fmt.Println("MONGO CONNECTING:", os.Getenv("DB"))
 	err = mongowrapper.Connect(os.Getenv("DB"))

+ 0 - 63
mic-linux/main.go

@@ -1,63 +0,0 @@
-package main
-
-import (
-	"fmt"
-	"log"
-	"os"
-	"os/signal"
-	"strings"
-
-	"github.com/MarkKremer/microphone/v2"
-
-	"github.com/gopxl/beep/v2/wav"
-)
-
-func main() {
-	if len(os.Args) < 2 {
-		fmt.Println("missing required argument: output file name")
-		return
-	}
-	fmt.Println("Recording. Press Ctrl-C to stop.")
-
-	err := microphone.Init()
-	if err != nil {
-		log.Fatal(err)
-	}
-	defer microphone.Terminate()
-
-	stream, format, err := microphone.OpenDefaultStream(44100, 2)
-	if err != nil {
-		log.Fatal(err)
-	}
-	// Close the stream at the end if it hasn't already been
-	// closed explicitly.
-	defer stream.Close()
-
-	filename := os.Args[1]
-	if !strings.HasSuffix(filename, ".wav") {
-		filename += ".wav"
-	}
-	f, err := os.Create(filename)
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	// Stop the stream when the user tries to quit the program.
-	sig := make(chan os.Signal, 1)
-	signal.Notify(sig, os.Interrupt, os.Kill)
-	go func() {
-		<-sig
-		stream.Stop()
-		stream.Close()
-	}()
-
-	stream.Start()
-
-	// Encode the stream. This is a blocking operation because
-	// wav.Encode will try to drain the stream. However, this
-	// doesn't happen until stream.Close() is called.
-	err = wav.Encode(f, stream, format)
-	if err != nil {
-		log.Fatal(err)
-	}
-}

BIN
mic-linux/test.wav


+ 0 - 159
mic/main.go

@@ -1,159 +0,0 @@
-// Record Windows Audio project main.go
-package mic
-
-import (
-	"bytes"
-	"fmt"
-	"io"
-	"log"
-	"net/http"
-	"net/url"
-	"os"
-	"os/exec"
-	"runtime/debug"
-
-	"github.com/gorilla/websocket"
-)
-
-func TalkToEve() (msg string) {
-	os.Remove("output.mp3")
-
-	cmd := exec.Command("./ffmpeg.exe",
-		"-f", "dshow",
-		"-i", `audio=Microphone (Yeti Classic)`,
-		"-t", "5",
-		"-acodec", "libmp3lame",
-		"-ac", "1",
-		"-ar", "16000",
-		"output.mp3")
-	_, err := cmd.CombinedOutput()
-	if err != nil {
-		log.Println("capture err:", err)
-		return ""
-	}
-	// fmt.Println(string(out))
-	// fmt.Println(err)
-
-	fmt.Println("ABOUT TO TRANSCRIBE")
-	return transcribeV2llama("output.mp3")
-}
-
-func check(err error) {
-
-	if err != nil {
-		log.Println(err, string(debug.Stack()))
-		// panic(err)
-	}
-}
-
-const Host = "localhost"
-const Port = "2700"
-const buffsize = 1_000_000
-
-type Message struct {
-	Result []struct {
-		Conf  float64
-		End   float64
-		Start float64
-		Word  string
-	}
-	Text string
-}
-
-var m Message
-
-func transcribe(fn string) (msg string) {
-
-	u := url.URL{Scheme: "ws", Host: Host + ":" + Port, Path: ""}
-	fmt.Println("connecting to ", u.String())
-
-	// Opening websocket connection
-	c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
-	check(err)
-	defer c.Close()
-
-	f, err := os.Open(fn)
-	check(err)
-	if f == nil {
-		fmt.Println("NO FILE, ", fn)
-		return
-	}
-
-	// streamer, format, err := wav.Decode(f)
-	// if err != nil {
-	// 	fmt.Println(err)
-	// 	return
-	// }
-	// defer streamer.Close()
-	// Send configuration
-	config := map[string]interface{}{
-		"config": map[string]interface{}{
-			"sample_rate": 16000, // Assuming the audio is at 16kHz
-			// "sample_rate": format.SampleRate, // Assuming the audio is at 16kHz
-		},
-	}
-	err = c.WriteJSON(config)
-	if err != nil {
-		log.Fatal("write json:", err)
-	}
-
-	// for {
-	buff, err := io.ReadAll(f)
-
-	if len(buff) == 0 && err == io.EOF {
-		err = c.WriteMessage(websocket.TextMessage, []byte("{\"eof\" : 1}"))
-		check(err)
-		return ""
-	}
-	check(err)
-
-	err = c.WriteMessage(websocket.BinaryMessage, buff)
-	check(err)
-
-	// Read message from server
-	_, x2, errx := c.ReadMessage()
-	check(errx)
-	fmt.Println("YOU SAID: ", string(x2))
-
-	c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
-
-	return string(x2)
-	// 	break
-	// }
-
-	// Read final message from server
-	// _, msg, err := c.ReadMessage()
-	// fmt.Println("OUT:", string(msg))
-	// check(err)
-
-	// Closing websocket connection
-	// Unmarshalling received message
-	// err = json.Unmarshal(msg, &m)
-	// check(err)
-	// fmt.Println(m)
-}
-
-func transcribeV2llama(fn string) (msg string) {
-
-	// Read the file content
-	fileBytes, err := os.ReadFile(fn)
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	// Make an HTTP POST request
-	resp, err := http.Post("http://localhost:8080/upload", "application/octet-stream", bytes.NewReader(fileBytes))
-	if err != nil {
-		log.Fatal(err)
-	}
-	defer resp.Body.Close()
-
-	// Read the response body
-	body, err := io.ReadAll(resp.Body)
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	fmt.Println(string(body))
-	return string(body)
-}

BIN
mic/output.wav


+ 3 - 6
variables.go

@@ -46,17 +46,15 @@ func InitTwitchClient() {
 }
 
 func InitCommands() {
-	// TextCommands["!monero"] = "43V6N2BpjvMYUthyqLioafZ2MQQviWEhvVTpp3hHc6LB48WYE8SsjrJKyyYzR3AYu2HkSXu8xsJhr7wdLsgSc8mGDDTkCrn"
-	TextCommands["!nvim"] = "https://github.com/zveinn/dotfiles"
+	TextCommands["!helix"] = "https://github.com/zveinn/dotfiles"
 	TextCommands["!dotfiles"] = "https://github.com/zveinn/dotfiles"
 	TextCommands["!x"] = "https://x.com/keyb1nd"
 	TextCommands["!github"] = "https://github.com/zveinn"
 	TextCommands["!linkedin"] = "https://www.linkedin.com/in/keyb1nd/"
 	TextCommands["!discord"] = "https://discord.com/invite/wJ5m3Y6ezq"
-	TextCommands["!keyboard"] = "wooting.io"
+	TextCommands["!keyboard"] = "Keychron split keyboard"
 	TextCommands["!os"] = "All of them."
-	TextCommands["!terminal"] = "wezterm + tmux"
-	TextCommands["!editor"] = "nvim"
+	TextCommands["!editor"] = "helix"
 	TextCommands["!youtube"] = "https://www.youtube.com/@keyb1nd?sub_confirmation=1"
 	TextCommands["!lurk"] = "ABSOLUTELY NOT ... LURKING IS NOT ALLOWED IN HERE"
 	TextCommands["!signal"] = "https://signal.group/#CjQKILCHWDqtfKErs-6yV8i0kQHhScDTL4wQ2mW7JYoQoBLsEhC7R4AqmLxdxwdRa0fWK1tD"
@@ -76,7 +74,6 @@ func InitCommands() {
 		TextCommands["!cmd"] += " " + i
 		TextCommands["!commands"] += " " + i
 	}
-
 }
 
 func CheckCustomReward(U *User, msg tirc.PrivateMessage) (success bool) {