feat: better language selection
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user