1- # ##############################################################################
1+ # ##############################################################################
22<#
33. SYNOPSIS
44Generates subtitle files for audio and video files using OpenAI Whisper.
@@ -155,7 +155,6 @@ function Save-Transcriptions {
155155 Position = 1 ,
156156 HelpMessage = ' The language to expect in the audio.'
157157 )]
158- [PSDefaultValue (Value = ' English' )]
159158 [ValidateSet (
160159 ' Afrikaans' ,
161160 ' Akan' ,
@@ -465,7 +464,7 @@ function Save-Transcriptions {
465464 ' Yoruba' ,
466465 ' Zulu'
467466 )]
468- [string ] $LanguageOut = $null ,
467+ [string ] $LanguageOut ,
469468 # ##########################################################################
470469 [Parameter (
471470 Mandatory = $false ,
@@ -708,9 +707,16 @@ function Save-Transcriptions {
708707 - ErrorAction SilentlyContinue)
709708
710709 # get resolved language using meta language processing
711- $languageIn = GenXdev.AI\Get-AIMetaLanguage @params - Language $LanguageIn
712-
713- $languageOut = GenXdev.AI\Get-AIMetaLanguage @params - Language $LanguageOut
710+ $params.Language = $LanguageIn
711+ if ([string ]::IsNullOrWhiteSpace($LanguageIn )) {
712+ $null = $params.Remove (' Language' )
713+ }
714+ $languageIn = GenXdev.AI\Get-AIMetaLanguage @params
715+ $params.Language = $LanguageOut
716+ if ([string ]::IsNullOrWhiteSpace($LanguageOut )) {
717+ $null = $params.Remove (' Language' )
718+ }
719+ $languageOut = GenXdev.AI\Get-AIMetaLanguage @params
714720
715721 # define array of supported media file extensions for processing
716722 $extensions = @ (
@@ -908,6 +914,10 @@ function Save-Transcriptions {
908914 return
909915 }
910916
917+ # display file being processed
918+ Microsoft.PowerShell.Utility\Write-Host (' Processing: ' +
919+ " $ ( $PSItem.FullName ) " ) - ForegroundColor Cyan
920+
911921 # construct paths for old and new subtitle file naming patterns
912922 $enPathOld = " $ ( $PSItem.FullName ) .en.srt"
913923
@@ -931,6 +941,9 @@ function Save-Transcriptions {
931941 $newPath = [IO.Path ]::ChangeExtension($PSItem.FullName ,
932942 " .$targetLanguage .srt" )
933943
944+ Microsoft.PowerShell.Utility\Write-Verbose " Target language: '$targetLanguage '"
945+ Microsoft.PowerShell.Utility\Write-Verbose " Target file path: '$newPath '"
946+
934947 # handle legacy Dutch subtitle file naming convention
935948 if ([io.file ]::Exists($nlPathOld )) {
936949
@@ -988,20 +1001,29 @@ function Save-Transcriptions {
9881001 " transcription for: $ ( $PSItem.FullName ) " )
9891002
9901003 # prepare parameters for transcription generation
991- $transcriptionParams = (GenXdev.Helpers\Copy-IdenticalParamValues `
992- - BoundParameters $PSBoundParameters `
993- - FunctionName ' GenXdev.AI\Start-AudioTranscription' `
994- - DefaultValues (Microsoft.PowerShell.Utility\Get-Variable `
995- - Scope Local `
996- - ErrorAction SilentlyContinue)
997- ) + @ {
998- Input = $PSItem.FullName
999- SRT = $true
1000- }
1004+ $transcriptionParams = GenXdev.Helpers\Copy-IdenticalParamValues `
1005+ - BoundParameters $PSBoundParameters `
1006+ - FunctionName ' GenXdev.AI\Start-AudioTranscription'
1007+
1008+ # Add required parameters for SRT generation
1009+ $transcriptionParams.Input = $PSItem.FullName
1010+ $transcriptionParams.Srt = $true
1011+ $transcriptionParams.LanguageIn = $languageIn
1012+ $transcriptionParams.LanguageOut = $languageOut
1013+
1014+ Microsoft.PowerShell.Utility\Write-Host " Starting transcription..." - ForegroundColor Yellow
1015+ Microsoft.PowerShell.Utility\Write-Verbose " Parameters: $ ( $transcriptionParams.Keys -join ' , ' ) "
10011016
10021017 # generate transcription using whisper model
1003- $transcription = GenXdev.AI\Start-AudioTranscription `
1004- @transcriptionParams
1018+ $transcription = GenXdev.AI\Start-AudioTranscription @transcriptionParams | Microsoft.PowerShell.Utility\Out-String
1019+
1020+ if ($null -eq $transcription -or [string ]::IsNullOrWhiteSpace($transcription )) {
1021+ Microsoft.PowerShell.Utility\Write-Warning " No transcription generated for $ ( $PSItem.Name ) "
1022+ return
1023+ }
1024+
1025+ Microsoft.PowerShell.Utility\Write-Host " Transcription completed successfully" - ForegroundColor Green
1026+ Microsoft.PowerShell.Utility\Write-Verbose " Transcription length: $ ( $transcription.Length ) characters"
10051027 }
10061028 finally {
10071029
@@ -1012,21 +1034,26 @@ function Save-Transcriptions {
10121034 }
10131035 catch {
10141036
1015- Microsoft.PowerShell.Utility\Write-Verbose (' Failed to ' +
1016- " process file: $ ( $PSItem.FullName ) " )
1017-
1018- Microsoft.PowerShell.Utility\Write-Verbose (' Error details: ' +
1019- " $PSItem " )
1037+ Microsoft.PowerShell.Utility\Write-Error " Failed to process file: $ ( $PSItem.FullName ) "
1038+ Microsoft.PowerShell.Utility\Write-Error " Error details: $ ( $_.Exception.Message ) "
1039+ Microsoft.PowerShell.Utility\Write-Verbose " Full error: $_ "
10201040
10211041 return
10221042 }
10231043
10241044 # save generated transcription to subtitle file
1025- $null = $transcription |
1026- Microsoft.PowerShell.Utility\Out-File $newPath - Force
1027-
1028- Microsoft.PowerShell.Utility\Write-Verbose (' Transcription saved ' +
1029- " to: $newPath " )
1045+ try {
1046+ $null = $transcription |
1047+ Microsoft.PowerShell.Utility\Out-File $newPath - Force - Encoding UTF8
1048+
1049+ Microsoft.PowerShell.Utility\Write-Host " Saved: $ ( [System.IO.Path ]::GetFileName($newPath )) " - ForegroundColor Green
1050+ Microsoft.PowerShell.Utility\Write-Verbose (' Transcription saved ' +
1051+ " to: $newPath " )
1052+ } catch {
1053+ Microsoft.PowerShell.Utility\Write-Error " Failed to save transcription to: $newPath "
1054+ Microsoft.PowerShell.Utility\Write-Error " Save error: $ ( $_.Exception.Message ) "
1055+ return
1056+ }
10301057
10311058 $transcription
10321059 }
0 commit comments