remove redundant groq and mistral transcription adapters
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
package transcriber
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
// GroqTranscriptionAdapter implements BatchAdapter for Groq Whisper API
|
||||
type GroqTranscriptionAdapter struct {
|
||||
client *openai.Client
|
||||
config Config
|
||||
}
|
||||
|
||||
func NewGroqTranscriptionAdapter(config Config) *GroqTranscriptionAdapter {
|
||||
clientConfig := openai.DefaultConfig(config.APIKey)
|
||||
clientConfig.BaseURL = "https://api.groq.com/openai/v1"
|
||||
client := openai.NewClientWithConfig(clientConfig)
|
||||
|
||||
return &GroqTranscriptionAdapter{
|
||||
client: client,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *GroqTranscriptionAdapter) Transcribe(ctx context.Context, audioData []byte) (string, error) {
|
||||
if len(audioData) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Convert raw PCM to WAV format
|
||||
wavData, err := convertToWAV(audioData)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("convert to WAV: %w", err)
|
||||
}
|
||||
|
||||
// Create transcription request
|
||||
req := openai.AudioRequest{
|
||||
Model: a.config.Model,
|
||||
Reader: bytes.NewReader(wavData),
|
||||
FilePath: "audio.wav",
|
||||
Language: a.config.Language,
|
||||
}
|
||||
|
||||
// Add keywords as prompt to help with spelling hints
|
||||
if len(a.config.Keywords) > 0 {
|
||||
req.Prompt = strings.Join(a.config.Keywords, ", ")
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
resp, err := a.client.CreateTranscription(ctx, req)
|
||||
duration := time.Since(start)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("groq-transcription-adapter: API call failed after %v: %v", duration, err)
|
||||
return "", fmt.Errorf("groq transcription: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("groq-transcription-adapter: transcribed %d bytes in %v: %q", len(audioData), duration, resp.Text)
|
||||
return resp.Text, nil
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package transcriber
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/sashabaranov/go-openai"
|
||||
)
|
||||
|
||||
// MistralAdapter implements BatchAdapter for Mistral Voxtral API
|
||||
type MistralAdapter struct {
|
||||
client *openai.Client
|
||||
config Config
|
||||
}
|
||||
|
||||
func NewMistralAdapter(config Config) *MistralAdapter {
|
||||
clientConfig := openai.DefaultConfig(config.APIKey)
|
||||
clientConfig.BaseURL = "https://api.mistral.ai/v1"
|
||||
client := openai.NewClientWithConfig(clientConfig)
|
||||
|
||||
return &MistralAdapter{
|
||||
client: client,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *MistralAdapter) Transcribe(ctx context.Context, audioData []byte) (string, error) {
|
||||
if len(audioData) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// Convert raw PCM to WAV format
|
||||
wavData, err := convertToWAV(audioData)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("convert to WAV: %w", err)
|
||||
}
|
||||
|
||||
// Create transcription request
|
||||
req := openai.AudioRequest{
|
||||
Model: a.config.Model,
|
||||
Reader: bytes.NewReader(wavData),
|
||||
FilePath: "audio.wav",
|
||||
Language: a.config.Language,
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
resp, err := a.client.CreateTranscription(ctx, req)
|
||||
duration := time.Since(start)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("mistral-adapter: API call failed after %v: %v", duration, err)
|
||||
return "", fmt.Errorf("mistral transcription: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("mistral-adapter: transcribed %d bytes in %v: %q", len(audioData), duration, resp.Text)
|
||||
return resp.Text, nil
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/leonardotrapani/hyprvoice/internal/provider"
|
||||
"github.com/leonardotrapani/hyprvoice/internal/recording"
|
||||
)
|
||||
|
||||
@@ -44,7 +45,9 @@ func NewTranscriber(config Config) (Transcriber, error) {
|
||||
if config.APIKey == "" {
|
||||
return nil, fmt.Errorf("Groq API key required")
|
||||
}
|
||||
adapter = NewGroqTranscriptionAdapter(config)
|
||||
// use consolidated OpenAI adapter with Groq endpoint
|
||||
endpoint := &provider.EndpointConfig{BaseURL: "https://api.groq.com/openai"}
|
||||
adapter = NewOpenAIAdapter(endpoint, config.APIKey, config.Model, config.Language, config.Keywords, "groq")
|
||||
|
||||
case "groq-translation":
|
||||
if config.APIKey == "" {
|
||||
@@ -56,7 +59,9 @@ func NewTranscriber(config Config) (Transcriber, error) {
|
||||
if config.APIKey == "" {
|
||||
return nil, fmt.Errorf("Mistral API key required")
|
||||
}
|
||||
adapter = NewMistralAdapter(config)
|
||||
// use consolidated OpenAI adapter with Mistral endpoint
|
||||
endpoint := &provider.EndpointConfig{BaseURL: "https://api.mistral.ai"}
|
||||
adapter = NewOpenAIAdapter(endpoint, config.APIKey, config.Model, config.Language, config.Keywords, "mistral")
|
||||
|
||||
case "elevenlabs":
|
||||
if config.APIKey == "" {
|
||||
|
||||
Reference in New Issue
Block a user