feat: better language selection

This commit is contained in:
leonardotrapani
2026-02-01 18:53:44 +01:00
parent 0025bf97b6
commit 3ae86f7bae
40 changed files with 452 additions and 852 deletions
@@ -8,6 +8,7 @@ import (
"log"
"net/http"
"net/url"
"strings"
"sync"
"time"
@@ -21,6 +22,7 @@ type OpenAIRealtimeAdapter struct {
apiKey string
model string
language string
keywords []string
conn *websocket.Conn
resultsCh chan TranscriptionResult
mu sync.Mutex
@@ -56,6 +58,7 @@ type openaiRealtimeSessionConfig struct {
type openaiRealtimeTranscription struct {
Model string `json:"model,omitempty"`
Language string `json:"language,omitempty"`
Prompt string `json:"prompt,omitempty"`
}
type openaiRealtimeTurnDetection struct {
@@ -104,12 +107,13 @@ type openaiRealtimeError struct {
// apiKey: OpenAI API key
// model: model ID (e.g., "gpt-4o-realtime-preview")
// lang: canonical language code (will be used for transcription config)
func NewOpenAIRealtimeAdapter(endpoint *provider.EndpointConfig, apiKey, model, lang string) *OpenAIRealtimeAdapter {
func NewOpenAIRealtimeAdapter(endpoint *provider.EndpointConfig, apiKey, model, lang string, keywords []string) *OpenAIRealtimeAdapter {
return &OpenAIRealtimeAdapter{
endpoint: endpoint,
apiKey: apiKey,
model: model,
language: lang,
keywords: keywords,
resultsCh: make(chan TranscriptionResult, 100),
maxRetries: 3,
retryDelays: defaultRetryDelays,
@@ -206,6 +210,10 @@ func (a *OpenAIRealtimeAdapter) configureSession() error {
sessionUpdate.Session.InputAudioTranscription.Language = a.language
}
if len(a.keywords) > 0 {
sessionUpdate.Session.InputAudioTranscription.Prompt = strings.Join(a.keywords, ", ")
}
return a.conn.WriteJSON(sessionUpdate)
}