diff --git a/internal/transcription/adapters/canary_adapter.go b/internal/transcription/adapters/canary_adapter.go index a7979c91..ef0e05ba 100644 --- a/internal/transcription/adapters/canary_adapter.go +++ b/internal/transcription/adapters/canary_adapter.go @@ -168,6 +168,11 @@ func (c *CanaryAdapter) GetSupportedModels() []string { func (c *CanaryAdapter) PrepareEnvironment(ctx context.Context) error { logger.Info("Preparing NVIDIA Canary environment", "env_path", c.envPath) + // Copy transcription script + if err := c.copyTranscriptionScript(); err != nil { + return fmt.Errorf("failed to copy transcription script: %w", err) + } + // Check if environment is already ready (using cache to speed up repeated checks) if CheckEnvironmentReady(c.envPath, "import nemo.collections.asr") { modelPath := filepath.Join(c.envPath, "canary-1b-v2.nemo") @@ -188,11 +193,6 @@ func (c *CanaryAdapter) PrepareEnvironment(ctx context.Context) error { return fmt.Errorf("failed to download Canary model: %w", err) } - // Create transcription script - if err := c.copyTranscriptionScript(); err != nil { - return fmt.Errorf("failed to create transcription script: %w", err) - } - c.initialized = true logger.Info("Canary environment prepared successfully") return nil diff --git a/internal/transcription/adapters/parakeet_adapter.go b/internal/transcription/adapters/parakeet_adapter.go index 5c20a673..bd4577a1 100644 --- a/internal/transcription/adapters/parakeet_adapter.go +++ b/internal/transcription/adapters/parakeet_adapter.go @@ -125,6 +125,15 @@ func (p *ParakeetAdapter) GetSupportedModels() []string { func (p *ParakeetAdapter) PrepareEnvironment(ctx context.Context) error { logger.Info("Preparing NVIDIA Parakeet environment", "env_path", p.envPath) + // Copy transcription scripts (standard and buffered) + if err := p.copyTranscriptionScript(); err != nil { + return fmt.Errorf("failed to copy transcription script: %w", err) + } + + if err := p.copyBufferedScript(); err != nil { + return fmt.Errorf("failed to create buffered script: %w", err) + } + // Check if environment is already ready (using cache to speed up repeated checks) if CheckEnvironmentReady(p.envPath, "import nemo.collections.asr") { modelPath := filepath.Join(p.envPath, "parakeet-tdt-0.6b-v3.nemo") @@ -159,15 +168,6 @@ func (p *ParakeetAdapter) PrepareEnvironment(ctx context.Context) error { return fmt.Errorf("failed to download Parakeet model: %w", err) } - // Create transcription scripts (standard and buffered) - if err := p.copyTranscriptionScript(); err != nil { - return fmt.Errorf("failed to create transcription script: %w", err) - } - - if err := p.createBufferedScript(); err != nil { - return fmt.Errorf("failed to create buffered script: %w", err) - } - p.initialized = true logger.Info("Parakeet environment prepared successfully") return nil @@ -557,8 +557,8 @@ func (p *ParakeetAdapter) parseResult(tempDir string, input interfaces.AudioInpu return result, nil } -// createBufferedScript creates the Python script for NeMo buffered inference -func (p *ParakeetAdapter) createBufferedScript() error { +// copyBufferedScript creates the Python script for NeMo buffered inference +func (p *ParakeetAdapter) copyBufferedScript() error { scriptContent, err := nvidiaScripts.ReadFile("py/nvidia/parakeet_transcribe_buffered.py") if err != nil { return fmt.Errorf("failed to read embedded transcribe_buffered.py: %w", err) diff --git a/internal/transcription/adapters/pyannote_adapter.go b/internal/transcription/adapters/pyannote_adapter.go index d6a5a427..b50caf16 100644 --- a/internal/transcription/adapters/pyannote_adapter.go +++ b/internal/transcription/adapters/pyannote_adapter.go @@ -182,6 +182,11 @@ func (p *PyAnnoteAdapter) GetMinSpeakers() int { func (p *PyAnnoteAdapter) PrepareEnvironment(ctx context.Context) error { logger.Info("Preparing PyAnnote environment", "env_path", p.envPath) + // Always ensure diarization script exists + if err := p.copyDiarizationScript(); err != nil { + return fmt.Errorf("failed to create diarization script: %w", err) + } + // Check if PyAnnote is already available (using cache to speed up repeated checks) if CheckEnvironmentReady(p.envPath, "from pyannote.audio import Pipeline") { logger.Info("PyAnnote already available in environment") @@ -198,11 +203,6 @@ func (p *PyAnnoteAdapter) PrepareEnvironment(ctx context.Context) error { return fmt.Errorf("failed to setup PyAnnote environment: %w", err) } - // Always ensure diarization script exists - if err := p.copyDiarizationScript(); err != nil { - return fmt.Errorf("failed to create diarization script: %w", err) - } - // Verify PyAnnote is now available testCmd := exec.Command("uv", "run", "--native-tls", "--project", p.envPath, "python", "-c", "from pyannote.audio import Pipeline") if testCmd.Run() != nil { diff --git a/internal/transcription/adapters/sortformer_adapter.go b/internal/transcription/adapters/sortformer_adapter.go index 5419cde0..aea12d4a 100644 --- a/internal/transcription/adapters/sortformer_adapter.go +++ b/internal/transcription/adapters/sortformer_adapter.go @@ -152,6 +152,11 @@ func (s *SortformerAdapter) GetMinSpeakers() int { func (s *SortformerAdapter) PrepareEnvironment(ctx context.Context) error { logger.Info("Preparing NVIDIA Sortformer environment", "env_path", s.envPath) + // Copy diarization script + if err := s.copyDiarizationScript(); err != nil { + return fmt.Errorf("failed to copy diarization script: %w", err) + } + // Check if environment is already ready (using cache to speed up repeated checks) if CheckEnvironmentReady(s.envPath, "from nemo.collections.asr.models import SortformerEncLabelModel") { modelPath := filepath.Join(s.envPath, "diar_streaming_sortformer_4spk-v2.nemo") @@ -179,11 +184,6 @@ func (s *SortformerAdapter) PrepareEnvironment(ctx context.Context) error { return fmt.Errorf("failed to download Sortformer model: %w", err) } - // Create diarization script - if err := s.copyDiarizationScript(); err != nil { - return fmt.Errorf("failed to create diarization script: %w", err) - } - s.initialized = true logger.Info("Sortformer environment prepared successfully") return nil