This commit is contained in:
Huaaudio 2026-03-21 08:46:51 +01:00
parent 347eabd0de
commit 763a774c3e
3 changed files with 17 additions and 4 deletions

View file

@ -48,7 +48,11 @@ func NewGroqTranscriber(apiKey string) *GroqTranscriber {
} }
} }
func (t *GroqTranscriber) TranscribeData(ctx context.Context, data []byte, filename string) (*TranscriptionResponse, error) { func (t *GroqTranscriber) TranscribeData(
ctx context.Context,
data []byte,
filename string,
) (*TranscriptionResponse, error) {
logger.InfoCF("voice", "Starting memory transcription", map[string]any{"filename": filename, "bytes": len(data)}) logger.InfoCF("voice", "Starting memory transcription", map[string]any{"filename": filename, "bytes": len(data)})
var requestBody bytes.Buffer var requestBody bytes.Buffer
@ -111,7 +115,12 @@ func (t *GroqTranscriber) Transcribe(ctx context.Context, audioFilePath string)
return t.doRequest(ctx, &requestBody, writer.FormDataContentType(), fileInfo.Size()) return t.doRequest(ctx, &requestBody, writer.FormDataContentType(), fileInfo.Size())
} }
func (t *GroqTranscriber) doRequest(ctx context.Context, requestBody *bytes.Buffer, contentType string, fileSize int64) (*TranscriptionResponse, error) { func (t *GroqTranscriber) doRequest(
ctx context.Context,
requestBody *bytes.Buffer,
contentType string,
fileSize int64,
) (*TranscriptionResponse, error) {
url := t.apiBase + "/audio/transcriptions" url := t.apiBase + "/audio/transcriptions"
req, err := http.NewRequestWithContext(ctx, "POST", url, requestBody) req, err := http.NewRequestWithContext(ctx, "POST", url, requestBody)
if err != nil { if err != nil {
@ -188,7 +197,8 @@ func DetectTranscriber(cfg *config.Config) Transcriber {
} }
// Fall back to any model-list entry that uses the groq/ protocol or is explicitly named groq. // Fall back to any model-list entry that uses the groq/ protocol or is explicitly named groq.
for _, mc := range cfg.ModelList { for _, mc := range cfg.ModelList {
if (strings.HasPrefix(mc.Model, "groq/") || mc.ModelName == "groq" || mc.Model == "whisper-large-v3-turbo") && mc.APIKey != "" { if (strings.HasPrefix(mc.Model, "groq/") || mc.ModelName == "groq" || mc.Model == "whisper-large-v3-turbo") &&
mc.APIKey != "" {
return NewGroqTranscriber(mc.APIKey) return NewGroqTranscriber(mc.APIKey)
} }
} }

View file

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/logger" "github.com/sipeed/picoclaw/pkg/logger"
) )

View file

@ -11,6 +11,7 @@ import (
"github.com/pion/rtp" "github.com/pion/rtp"
"github.com/pion/webrtc/v3/pkg/media/oggwriter" "github.com/pion/webrtc/v3/pkg/media/oggwriter"
"github.com/sipeed/picoclaw/pkg/asr" "github.com/sipeed/picoclaw/pkg/asr"
"github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/logger" "github.com/sipeed/picoclaw/pkg/logger"
@ -187,7 +188,8 @@ func (a *Agent) processUtterance(ctx context.Context, acc *speechAccumulator) {
channelType := "discord" channelType := "discord"
text := strings.ToLower(strings.TrimSpace(res.Text)) text := strings.ToLower(strings.TrimSpace(res.Text))
if strings.Contains(text, "leave the voice channel") || strings.Contains(text, "leave voice") || strings.Contains(text, "disconnect voice") { if strings.Contains(text, "leave the voice channel") || strings.Contains(text, "leave voice") ||
strings.Contains(text, "disconnect voice") {
logger.InfoCF("voice-agent", "Voice command triggered: leave", nil) logger.InfoCF("voice-agent", "Voice command triggered: leave", nil)
a.bus.PublishVoiceControl(ctx, bus.VoiceControl{ a.bus.PublishVoiceControl(ctx, bus.VoiceControl{
SessionID: acc.sessionID, SessionID: acc.sessionID,