2024-01-14 21:39:35 -05:00
; ENVIRONMENT
;------------------------------------------------
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors.
;DetectHiddenWindows, On
if ( InStr ( A_ScriptFullPath , " .ahk " ) ) {
#SingleInstance , Force
}
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;SetKeyDelay, 500
CoordMode , ToolTip , Screen
CoordMode , Mouse , Screen
;#NoTrayIcon
; Notes/Extra Info/#Includes
;------------------------------------------------
#Include , %A_scriptdir% \Lib \RunCMD . ahk
; #Include C:\Users\%A_Username%\Syncthing\Scripts\AutoHotKey\RadialMenu\My codes\My Global Variables.ahk
Menu , Tray , Icon , %A_scriptDir% \Assets \Elegantthemes - Beautiful - Flat - Speaker . ico
ScriptName = Whisper - AHK
ScriptVersion = V1 . 0
; VARIABLES
;------------------------------------------------
WhitelistedMediaFilesExtensions = mp3 , wav , mp4
2024-07-31 04:37:48 -04:00
2024-01-14 21:42:40 -05:00
largeM_FP = %A_scriptdir% \Models \ggml - large - v1 . bin
mediumM_FP = %A_scriptdir% \Models \ggml - medium . bin
baseM_FP = %A_scriptdir% \Models \ggml - base . en . bin
smallM_FP = %A_scriptdir% \Models \ggml - small . en . bin
tinyM_FP = %A_scriptdir% \Models \ggml - tiny . en . bin
2024-01-14 21:39:35 -05:00
; Number of processors
EnvGet , ProcessorCount , NUMBER_OF_PROCESSORS
; EnvGet, ProcessorCount, NUMBER_OF_PROCESSORS
2024-07-31 04:37:48 -04:00
IniRead , ShutdownOnFinish , Settings . ini , %ScriptName% , ShutdownOnFinish , 0
2024-01-14 21:39:35 -05:00
IniRead , CPUThreads , Settings . ini , %ScriptName% , CPUThreads , %A_space%
IniRead , ShowTooltip , Settings . ini , %ScriptName% , ShowTooltip , %A_space%
IniRead , SelectedDirectoryPath , Settings . ini , %ScriptName% , SelectedDirectoryPath , %A_space%
IniRead , TranscriptionModelsSelected , Settings . ini , %ScriptName% , TranscriptionModelsSelected , %A_space%
2024-07-31 06:00:31 -04:00
; IniRead, TranscriptionLengthsSelected, Settings.ini, %ScriptName%, TranscriptionLengthsSelected, %A_space%
IniRead , NTFY , Settings . ini , %ScriptName% , NTFY , 0
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
2024-01-14 21:39:35 -05:00
( W i n E x i s t ( " P o d c a s t - T r a n s c r i p t i o n - I n - P r o g r e s s " ) ) ? ( C o n t i n u e A f t e r C M D C l o s e C h e c k S t a t u s : = 1 ) : ( C o n t i n u e A f t e r C M D C l o s e C h e c k S t a t u s : = 0 )
2024-07-31 04:37:48 -04:00
IniRead , HideCMDWindows , Settings . ini , %ScriptName% , HideCMDWindows , 0
IniRead , UploadResultToNTFY , Settings . ini , %ScriptName% , UploadResultToNTFY , 0
IniRead , NTFYEXEFilepath , Settings . ini , %ScriptName% , NTFYEXEFilepath , 0
IniRead , NTFYTopic , Settings . ini , %ScriptName% , NTFYTopic , 0
2024-01-14 21:39:35 -05:00
; Msgbox % "ContinueAfterCMDCloseCheckStatus: " ContinueAfterCMDCloseCheckStatus
/*
Gui , Add , Checkbox , y + 15 vTinyM , Tiny ( 75 MB Disk , ~ 125 MB RAM )
Gui , Add , Checkbox , vBaseM , Base ( 142 MB Disk , ~ 210 MB RAM )
Gui , Add , Checkbox , vSmallM , Small ( 466 MB Disk , ~ 600 MB RAM )
Gui , Add , Checkbox , vMediumM , Medium ( 1.5 GB Disk , ~ 1.7 GB RAM )
Gui , Add , Checkbox , vLargeM checked , Large ( 2.9 GB Disk , ~ 3.3 GB RAM )
Gui , Add , Checkbox , vAllMQualities , ALL ( One by One )
* /
( i n s t r ( T r a n s c r i p t i o n M o d e l s S e l e c t e d , " T i n y " ) ) ? ( T i n y M : = 1 ) : ( T i n y M : = 0 )
( i n s t r ( T r a n s c r i p t i o n M o d e l s S e l e c t e d , " B a s e " ) ) ? ( B a s e M : = 1 ) : ( B a s e M : = 0 )
( i n s t r ( T r a n s c r i p t i o n M o d e l s S e l e c t e d , " S m a l l " ) ) ? ( S m a l l M : = 1 ) : ( S m a l l M : = 0 )
( i n s t r ( T r a n s c r i p t i o n M o d e l s S e l e c t e d , " M e d i u m " ) ) ? ( M e d i u m M : = 1 ) : ( M e d i u m M : = 0 )
( i n s t r ( T r a n s c r i p t i o n M o d e l s S e l e c t e d , " L a r g e " ) ) ? ( L a r g e M : = 1 ) : ( L a r g e M : = 0 )
2024-07-31 06:00:31 -04:00
; (instr(TranscriptionLengthsSelected,"Short"))?(ShortPodcastsCheckStatus := 1):(ShortPodcastsCheckStatus := 0)
; (instr(TranscriptionLengthsSelected,"Medium"))?(MediumPodcastsCheckStatus := 1):(MediumPodcastsCheckStatus := 0)
; (instr(TranscriptionLengthsSelected,"Long"))?(LongPodcastsCheckStatus := 1):(LongPodcastsCheckStatus := 0)
2024-01-14 21:39:35 -05:00
; Msgbox % "ShortPodcastsCheckStatus: " ShortPodcastsCheckStatus
global AudioFilesDIR
global ShowTooltip
global ErrorLogText
TranscriptionModels := [ ] ; Create an array
TranscriptionModelPaths := [ ] ; Create an array
TranscriptionModelGPUNames := [ ] ; Create an array
; -------------------------------GUI Variables-------------------------------
2024-07-31 04:37:48 -04:00
GUIMargin := 10
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
VerticalLineHeight := 600
2024-01-14 21:39:35 -05:00
2024-07-31 06:00:31 -04:00
GuiRowOneWidth := 310
2024-07-31 04:37:48 -04:00
GUIRowTwoXPos := 350
GUIRowTwoWidth := 350
2024-07-31 06:00:31 -04:00
GUIRowTwoVerticalLineXPos := GUIRowTwoXPos - ( GUIMargin )
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
GUIRowThreeXPos := GUIRowTwoXPos + GUIRowTwoWidth + ( GUIMargin * 2 )
GUIRowThreeVerticalLineXPos := GUIRowThreeXPos - GUIMargin
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
GUIButtonWidths := 50
2024-07-31 06:00:31 -04:00
GUIEditBoxWidth := GUIRowTwoXPos - ( GUIMargin * 8 )
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
GuiWidth := 1100
2024-01-14 21:39:35 -05:00
GuiStartButtonXPos := GUIRowTwoXPos + %GUIMargin%
GUISelectButtonWidths := 70
TranscribeButtonWidth := GuiWidth - GUIRowThreeXPos - ( GUIMargin * 2 )
; Msgbox % "TranscribeButtonWidth: " TranscribeButtonWidth
; MAIN SCRIPT
;------------------------------------------------
2024-07-31 06:00:31 -04:00
gui , font , s10
2024-07-31 04:37:48 -04:00
Gui , Font , Bold
Gui , Font , underline
2024-07-31 06:00:31 -04:00
Gui , Add , Button , x %GUIMargin% y %GUIMargin% w %GuiRowOneWidth% center , Transcription Settings
2024-01-14 21:39:35 -05:00
Gui , font , normal
; Gui, Add, Text
; Gui, font, Bold
2024-07-31 06:00:31 -04:00
Gui , Add , Text , x %GUIMargin% y + 20 w %GUIEditBoxWidth% center , Transcribe Individual File ( s )
2024-01-14 21:39:35 -05:00
; Gui, font, normal
2024-07-31 06:00:31 -04:00
Gui , Add , Edit , h30 vFilesFilepath gUpdateGUI w %GUIEditBoxWidth%
Gui , Font , s8
Gui , Add , Button , x + 0 w50 h30 gSelectFile , Select
2024-01-14 21:39:35 -05:00
; Gui, font, Bold
; Gui, Add, Text, cRed center w200 x%GUIMargin%, OR
2024-07-31 04:37:48 -04:00
; Gui, Add, Text,x%GUIMargin% y+40 w%GUIEditBoxWidth% center, OR
2024-07-31 06:00:31 -04:00
Gui , Font , s12
2024-07-31 04:37:48 -04:00
Gui , Add , Text , x %GUIMargin% y + 40 w %GUIEditBoxWidth% center , Transcribe Directory
; gui, font, s12
Gui , Add , Edit , h30 vSelectedDirectoryPath gUpdateGUI w %GUIEditBoxWidth% , %SelectedDirectoryPath%
2024-07-31 06:00:31 -04:00
Gui , Font , s8
Gui , Add , Button , x + 0 w50 h30 gSelectDirectory , Select
; Gui, Add, Button, y+1 w%GUIEditBoxWidth% gSelectDirectory , Select
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
gui , add , text , y %GUIMargin% x %GUIRowTwoVerticalLineXPos% 0x11 h %VerticalLineHeight% ; 0x11 is a "line" ; refer to here: https://autohotkey.com/board/topic/50910-draw-line-gui/
2024-01-14 21:39:35 -05:00
2024-07-31 06:00:31 -04:00
Gui , Font , S10
2024-07-31 04:37:48 -04:00
Gui , Font , Bold
Gui , Font , underline
2024-07-31 06:00:31 -04:00
Gui , Add , Button , x %GUIRowTwoXPos% y %GUIMargin% w %GUIRowTwoWidth% center , Transcription Model
2024-01-14 21:39:35 -05:00
Gui , font , normal ; , Param2, Param3, Param4]
2024-01-14 22:46:19 -05:00
2024-01-14 21:39:35 -05:00
; Gui, Add, Radio
2024-01-14 22:46:19 -05:00
2024-07-31 04:37:48 -04:00
Gui , Add , Checkbox , w %GUIRowTwoWidth% vBaseM checked %BaseM% , Base ( 142 MB Disk , ~ 210 MB RAM )
Gui , Add , Checkbox , w %GUIRowTwoWidth% vSmallM checked %SmallM% , Small ( 466 MB Disk , ~ 600 MB RAM )
Gui , Add , Checkbox , w %GUIRowTwoWidth% vMediumM checked %MediumM% , Medium ( 1.5 GB Disk , ~ 1.7 GB RAM )
Gui , Add , Checkbox , w %GUIRowTwoWidth% vLargeM checked %LargeM% , Large ( 2.9 GB Disk , ~ 3.3 GB RAM )
Gui , Add , Checkbox , w %GUIRowTwoWidth% vAllMQualities , ALL ( One by One )
2024-01-14 21:39:35 -05:00
2024-01-29 23:20:32 -05:00
; Gui, Add, Slider, w200 h20 Range1-5, test, one, two ; Creates a horizontal slider
2024-07-31 06:00:31 -04:00
/* Gui, Font, Bold
2024-01-29 23:20:32 -05:00
Gui , Font , underline
2024-07-31 06:00:31 -04:00
Gui , Add , Button , x %GUIRowTwoXPos% y + 15 w %GUIRowTwoXPos% center , Length of File to Transcribe
2024-01-14 21:39:35 -05:00
Gui , font , normal
2024-01-14 22:46:19 -05:00
Gui , Add , Checkbox , vAnyLengthMediaFile gUpdateGUI checked %AnyLengthMediaFileCheckStatus% , ANY Length
2024-01-14 21:39:35 -05:00
Gui , Add , Checkbox , y + %GUIMargin% gUpdateGUI vShortPodcasts checked %ShortPodcastsCheckStatus% , Short ( < 30 Mins )
Gui , Add , Checkbox , vMediumPodcasts gUpdateGUI checked %MediumPodcastsCheckStatus% , Medium ( 30 - 60 Mins )
Gui , Add , Checkbox , vLongPodcasts gUpdateGUI checked %LongPodcastsCheckStatus% , Long ( > 60 Mins )
2024-07-31 06:00:31 -04:00
* /
; Gui, Add, Text, , Number of CPU Threads ; `nTotal Processors on PC: %ProcessorCount%
Gui , Font , Bold
Gui , Font , underline
Gui , Add , Button , x %GUIRowTwoXPos% y + 15 w %GUIRowTwoXPos% center , Number of CPU Threads ( PC MAX %ProcessorCount% )
Gui , Font , Normal
; Gui, Add, Text, x%GUIMargin% y+%GUIMargin% w%GUIEditBoxWidth% center, Number of CPU Threads (PC MAX: %ProcessorCount%) ; `nTotal Processors on PC: %ProcessorCount%
Gui , Add , Edit , gUpdateGUI w %GUIRowTwoXPos% ,
Gui , Add , UpDown , vCPUThreads Range1 - 20 , %CPUThreads%
2024-01-14 22:46:19 -05:00
2024-01-14 21:39:35 -05:00
Gui , Font , Bold
2024-07-31 04:37:48 -04:00
Gui , Font , underline
2024-07-31 06:00:31 -04:00
Gui , Add , Button , x %GUIRowTwoXPos% y + 15 w %GUIRowTwoWidth% center , Other Settings
2024-01-14 21:39:35 -05:00
Gui , font , normal
2024-07-31 04:37:48 -04:00
Gui , Add , Checkbox , vHideCMDWindows checked %HideCMDWindows% , Hide CMD Windows
Gui , Add , Checkbox , vKeepCMDOpenOrClose checked %HideCMDWindows% , Keep CMD Open After Model Completion
2024-01-14 21:39:35 -05:00
Gui , Add , Checkbox , vShowTooltip checked %ShowTooltip% , Show Tooltip of Progress at Top of Screen
2024-07-31 06:00:31 -04:00
Gui , Add , Checkbox , vNTFY checked %NTFY% , NTFY After Each Transcription
2024-07-31 04:37:48 -04:00
Gui , Add , Checkbox , vUploadResultToNTFY checked %UploadResultToNTFY% , Upload Transcription to NTFY
2024-01-14 21:39:35 -05:00
Gui , Add , Checkbox , vContinueAfterCMDClose checked %ContinueAfterCMDCloseCheckStatus% , Start After Current Running Transcription Ends
2024-07-31 04:37:48 -04:00
Gui , Add , Checkbox , vShutdownOnFinish , Shutdown PC on Completion
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
gui , add , text , y20 x %GUIRowThreeVerticalLineXPos% 0x11 h %VerticalLineHeight% ; 0x11 is a "line" ; refer to here: https://autohotkey.com/board/topic/50910-draw-line-gui/
2024-01-14 21:39:35 -05:00
gui , font , s12
2024-07-31 04:37:48 -04:00
Gui , Font , Bold
Gui , Font , underline
2024-01-14 21:39:35 -05:00
Gui , Add , text , y %GUIMargin% w %TranscribeButtonWidth% x %GUIRowThreeXPos% h20 Center , Status Log
gui , font , normal
gui , font , s7
2024-07-31 04:37:48 -04:00
Gui , Add , Edit , y + %GUIMargin% w %TranscribeButtonWidth% x %GUIRowThreeXPos% h450 vStatusLog
2024-01-14 21:39:35 -05:00
Gui , font , Bold
Gui , Font , s12
Gui , Add , Button , y + 20 x %GUIRowThreeXPos% w %TranscribeButtonWidth% h40 gSubmit Center , Transcribe
gui , font , normal
Gui , Font , s9
2024-07-31 04:37:48 -04:00
Gui , Add , Button , y + %GUIMargin% x %GUIRowThreeXPos% w %TranscribeButtonWidth% h30 gReloadScript Center , Restart
2024-01-14 21:39:35 -05:00
Gui , Font , s5
2024-01-14 21:48:03 -05:00
; Gui, Add, StatusBar,Center, This Node: Minutes Transcribed by Node: Total Minutes Transcribed by All Nodes: Total Minutes of All Transcriptions: Average time to transcribe 1 min:
2024-01-14 21:39:35 -05:00
gui , show , w %GuiWidth% , %ScriptName% %ScriptVersion%
Return
UpdateGUI:
Gui , Submit , NoHide ; , Param2, Param3, Param4]
; msgbox % SelectedDirectoryPath
Return
SelectFile:
if ( SelectedDirectoryPath ) {
2024-07-31 04:37:48 -04:00
GuiControl , Text , SelectedDirectoryPath ,
2024-01-14 21:39:35 -05:00
}
2024-07-31 04:37:48 -04:00
2024-01-14 21:39:35 -05:00
FileSelectFile , SelectedFiles , M3 ; M3 = Multiselect existing files.
if ( SelectedFiles = " " )
return
GUIFilesText := StrReplace ( SelectedFiles , " `n " , " | " )
GuiControl , Text , FilesFilepath , %GUIFilesText%
return
SelectDirectory:
2024-07-31 04:37:48 -04:00
if ( FilesFilepath ) {
GuiControl , Text , FilesFilepath ,
2024-01-14 21:39:35 -05:00
}
; have user select a file within the directory they want transcribed.
; Will later get the directory name from this file
FileSelectFile , SelectedDirectoryPath
if ( SelectedDirectoryPath = " " )
return
GuiControl , Text , SelectedDirectoryPath , %SelectedDirectoryPath%
return
GuiClose:
ExitApp
ReloadScript:
Reload
ExitApp
Submit:
gui , Submit , NoHide
2024-07-31 04:37:48 -04:00
; Hide CMD popups when doing run, or runwait or comspec commands
if ( HideCMDWindows ) {
DllCall ( " AllocConsole " )
WinHide % " ahk_id " DllCall ( " GetConsoleWindow " , " ptr " )
}
2024-01-14 21:39:35 -05:00
if ( NTFY ) {
IniRead , NTFYURL , Settings . ini , %ScriptName% , NTFYURL , %A_space%
; Msgbox % "NTFYURL: " NTFYURL
if ( ! NTFYURL ) {
InputBox , NTFYURL , Input NTFY URL , Please input NTFY url for notifications . `n Generate a URL at : https : / / ntfy . sh / app
if ( ErrorLevel ) {
NTFY := 0
}
else , { ; save url to settings.ini
IniWrite , %NTFYURL% , Settings . ini , %ScriptName% , NTFYURL
}
}
}
2024-07-31 04:37:48 -04:00
IniWrite , %ShutdownOnFinish% , Settings . ini , %ScriptName% , ShutdownOnFinish
2024-01-14 21:39:35 -05:00
IniWrite , %CPUThreads% , Settings . ini , %ScriptName% , CPUThreads
IniWrite , %ShowTooltip% , Settings . ini , %ScriptName% , ShowTooltip
2024-07-31 04:37:48 -04:00
IniWrite , %HideCMDWindows% , Settings . ini , %ScriptName% , HideCMDWindows
IniWrite , %UploadResultToNTFY% , Settings . ini , %ScriptName% , UploadResultToNTFY
2024-07-31 06:00:31 -04:00
IniWrite , %NTFY% , Settings . ini , %ScriptName% , NTFY
2024-07-31 04:37:48 -04:00
2024-01-14 21:39:35 -05:00
; IniWrite, %ContinueAfterCMDClose%, Settings.ini, %A_ScriptName%, ContinueAfterCMDClose
if ( SelectedDirectoryPath ) {
IniWrite , %SelectedDirectoryPath% , Settings . ini , %ScriptName% , SelectedDirectoryPath
}
else , {
IniWrite , %A_space% , Settings . ini , %ScriptName% , SelectedDirectoryPath
}
if ( ! SelectedFiles AND ! SelectedDirectoryPath ) {
msgbox , Please select individual files or a directory that you want Transcribed .
return
}
Status := RunCMD ( " ffmpeg " )
; Msgbox % "Status: " Status
if ( ! InStr ( Status , " ffmpeg version " ) ) {
MsgBox , Error : , FFMPEG was not found in System PATH . `n Please install it and add it to System PATH to automatically convert files to the Whisper . cpp required 16 - bit WAV file
return
}
Message = Creating Required Variables
ShowTooltipText ( Message )
; if files selected, add them all to array
if ( SelectedFiles ) {
SelectedAudioFilesArray := [ ] ; Create array
; loop through all selected files and add them to the array
Loop , parse , SelectedFiles , `n
{
if ( A_Index = 1 ) {
AudioFilesDIR = %A_LoopField%
; MsgBox, The selected files are all contained in %A_LoopField%.
}
else
{
AudioFileFP = %AudioFilesDIR% \%A_LoopField%
SelectedAudioFilesArray . Push ( AudioFileFP ) ; Append an item to the array
; SelectedAudioFilesVAR .= AudioFileFP . ","
}
}
}
; if directory selected, loop through all files and add them to the array
if ( SelectedDirectoryPath ) {
SplitPath , SelectedDirectoryPath , OutFileName , AudioFilesDIR , OutExtension , OutNameNoExt , OutDrive
; msgbox, adding files in directory to var
SelectedAudioFilesArray := [ ] ; Create array
Text = Creating Array of Whitelisted Files ( %WhitelistedMediaFilesExtensions% ) `n in Directory : %AudioFilesDIR%
ShowTooltipText ( Text )
PrePendToErrorLogText ( text )
Loop , files , %AudioFilesDIR% \* . * , F
{
SplitPath , A_LoopFileFullPath , FileNameWExt , FileDir , FileExt , FileNameNoExt ,
if ( InStr ( WhitelistedMediaFilesExtensions , FileExt ) ) {
SelectedAudioFilesArray . Push ( A_LoopFileFullPath )
}
}
}
; If directory selected, add all files to array
; Msgbox % "AudioFilesDIR: " AudioFilesDIR
2024-07-31 04:37:48 -04:00
; KeepCMDOpenOrClose := 0
2024-01-14 21:39:35 -05:00
OverwritePreviousTranscriptions := 0
2024-07-31 04:37:48 -04:00
if ( KeepCMDOpenOrClose ) {
KeepCMDOpenOrClose := " K "
2024-01-14 21:39:35 -05:00
}
else , {
2024-07-31 04:37:48 -04:00
KeepCMDOpenOrClose := " C "
2024-01-14 21:39:35 -05:00
}
; clear variable from GUI
TranscriptionModelsSelected :=
; push to array each quality selected
if ( TinyM Or AllMQualities ) {
TranscriptionModels . Push ( " Tiny " ) ; Append an item to the array
TranscriptionModelPaths . Push ( tinyM_FP ) ; Append an item to the array
TranscriptionModelsSelected .= " Tiny| "
}
if ( SmallM Or AllMQualities ) {
TranscriptionModels . Push ( " Small " ) ; Append an item to the array
TranscriptionModelPaths . Push ( smallM_FP ) ; Append an item to the array
TranscriptionModelsSelected .= " Small| "
}
if ( BaseM Or AllMQualities ) {
TranscriptionModels . Push ( " Base " ) ; Append an item to the array
TranscriptionModelPaths . Push ( baseM_FP ) ; Append an item to the array
TranscriptionModelsSelected .= " Base| "
}
if ( MediumM Or AllMQualities ) {
TranscriptionModels . Push ( " Medium " ) ; Append an item to the array
TranscriptionModelPaths . Push ( mediumM_FP ) ; Append an item to the array
TranscriptionModelsSelected .= " Medium| "
}
if ( LargeM Or AllMQualities ) {
TranscriptionModels . Push ( " Large " ) ; Append an item to the array
TranscriptionModelPaths . Push ( largeM_FP ) ; Append an item to the array
TranscriptionModelsSelected .= " Large| "
}
if ( TranscriptionModelsSelected = " " ) {
ToolTip
Text = Please Select at Least ONE Model to Transcribe With
msgbox , %Text%
return
}
; save selected models to ini files
IniWrite , %TranscriptionModelsSelected% , Settings . ini , %ScriptName% , TranscriptionModelsSelected
2024-07-31 06:00:31 -04:00
/* TranscriptionLengthsSelected :=
2024-01-14 21:39:35 -05:00
( S h o r t P o d c a s t s ) ? ( T r a n s c r i p t i o n L e n g t h s S e l e c t e d . = " S h o r t | " ) : ( " " )
( M e d i u m P o d c a s t s ) ? ( T r a n s c r i p t i o n L e n g t h s S e l e c t e d . = " M e d i u m | " ) : ( " " )
( L o n g P o d c a s t s ) ? ( T r a n s c r i p t i o n L e n g t h s S e l e c t e d . = " L o n g | " ) : ( " " )
2024-01-14 22:46:19 -05:00
( A n y L e n g t h M e d i a F i l e ) ? ( T r a n s c r i p t i o n L e n g t h s S e l e c t e d . = " A n y L e n g t h M e d i a F i l e | " ) : ( " " )
2024-01-14 21:39:35 -05:00
if ( TranscriptionLengthsSelected = " " ) {
ToolTip
Text = Please Select the Audio Length you 'd like to Transcribe
msgbox , %Text%
return
}
IniWrite , %TranscriptionLengthsSelected% , Settings . ini , %ScriptName% , TranscriptionLengthsSelected
2024-07-31 06:00:31 -04:00
* /
2024-01-14 21:39:35 -05:00
; msgbox
text = Creating Required Directories
ShowTooltipText ( Text )
FileCreateDir , %AudioFilesDIR% \Transcriptions
2024-01-29 23:20:32 -05:00
FileCreateDir , %AudioFilesDIR% \Transcriptions \Logs
FileCreateDir , %AudioFilesDIR% \Transcriptions \Large
FileCreateDir , %AudioFilesDIR% \Transcriptions \Medium
FileCreateDir , %AudioFilesDIR% \Transcriptions \Small
FileCreateDir , %AudioFilesDIR% \Transcriptions \Base
2024-01-14 21:39:35 -05:00
FileCreateDir , %AudioFilesDIR% \WAVFiles
text = Starting Transcription
ShowTooltipText ( Text )
PrePendToErrorLogText ( text )
; loop through the array and transcribe using options selected
; Msgbox % TranscriptionModels.Length() ; Display total number of items in the array
; ArrayLenght := TranscriptionModels.Length() ; Save total number of items in the array
if ( ContinueAfterCMDClose and WinExist ( " Podcast-Transcription-In-Progress " ) ) {
; msgbox, cmd found.
Text = Waiting for Current Running Transcription to Finish in CMD
ShowTooltipText ( Text )
PrePendToErrorLogText ( text )
WinWaitClose , ahk_class ConsoleWindowClass ;, WinText, Seconds [, ExcludeTitle, ExcludeText]
; msgbox, cmd closed
}
; loop for each selected audio file
loop % SelectedAudioFilesArray . Length ( ) {
Filepath := SelectedAudioFilesArray [ A_Index ]
OriginalFilepath := SelectedAudioFilesArray [ A_Index ]
SplitPath , Filepath , OutFileName , OutDir , OutExtension , OutNameNoExt , OutDrive
; Convert the file to 16-bit WAV file as required by whisper.cpp
WavFilepath = %AudioFilesDIR% \WAVFiles \%OutNameNoExt% . wav
; loop through each selected transcription model
Loop % TranscriptionModels . Length ( ) {
ModelName := TranscriptionModels [ A_Index ]
ModelPath := TranscriptionModelPaths [ A_Index ]
; create filepaths where outputs will be saved to
2024-01-29 23:20:32 -05:00
OutputPath = %AudioFilesDIR% \Transcriptions \%ModelName% \%OutNameNoExt%
OutputModelTxtFile = %OutputPath% . txt ; the filepath of one of the outputs
LogFileFP = %AudioFilesDIR% \Transcriptions \Logs \%OutNameNoExt% _ %ModelName% . log
2024-01-14 21:39:35 -05:00
Text = Checking for Previous Transcription
ShowTooltipText ( Text )
; If .txt Transcription file exists, move on to next model
if ( FileExist ( OutputModelTxtFile ) ) {
Message := " Skipping " . OutFileName . " - already transcribed with " . ModelName . " Model "
PrePendToErrorLogText ( Message )
Continue
}
; otherwise check if log file exists from a previous run, or current run on different node (if using shared folder)
if ( FileExist ( LogFileFP ) ) {
FileGetTime , LogFileFPModificationTime , %LogFileFP% , M ;
; EnvSub, Var, Value [, TimeUnits]
EnvSub , LogFileFPModificationTime , A_Now , S ; get hours SINCE last modified
; Check if log file was last added to more than 24 hours ago
; No podcast transcription should take more than that, and it means that a node started, but never finished it
LogFileFPModificationTime := ( LogFileFPModificationTime * - 1 )
; Msgbox % "LogFileFPModificationTime: " LogFileFPModificationTime
if ( ( LogFileFPModificationTime < 86400 ) ) {
text = Skipping %OutFileName% with Model : %ModelName% - Currently being Transcribed by a different node .
PrePendToErrorLogText ( text )
ShowTooltipText ( Text )
; sleep, 1000
Continue
}
}
; get information about audio file
Obj := Filexpro ( Filepath , ,
, " Length "
, " Size " )
AudioLength := obj [ " Length " ]
AudioLengthArray := StrSplit ( AudioLength , " : " )
TotalTimeInSeconds := ( ( AudioLengthArray [ 1 ] * 60 ) * 60 ) + ( AudioLengthArray [ 2 ] * 60 ) + AudioLengthArray [ 3 ]
if ( FileExist ( WavFilepath ) ) { ; re-use previously converted wav file if it exists
Filepath := WavFilepath
} else , {
text = Converting File : %OutFileName% To 16 - bit WAV file
ShowTooltipText ( Text )
PrePendToErrorLogText ( text )
2024-07-31 04:37:48 -04:00
runwait , %ComSpec% / %KeepCMDOpenOrClose% ffmpeg - i " %Filepath% " - ar 16000 - ac 1 - c : a pcm_s16le " %WavFilepath% "
2024-01-14 21:39:35 -05:00
}
if ( ! FileExist ( WavFilepath ) ) {
Message = WAV file not found at : `n %WavFilepath% `n Conversion failed for some reason . `n Please select the " Keep CMD Open " checkbox and run again to see the error . `n Click OK to exit .
PrePendToErrorLogText ( text )
Continue
}
FormatTime , TodayDate , YYYYMMDDHH24MISS , hh : mm
text = Transcription in Progress `n Model : %ModelName% CPU Threads : %CPUThreads% Length : %AudioLength% `n File : %OutNameNoExt% `n Start Time : %TodayDate%
LogToTextFile ( text , LogFileFP )
PrePendToErrorLogText ( text )
ShowTooltipText ( Text )
; msgbox
UStartTime := A_TickCount ; start time
2024-07-31 04:43:29 -04:00
; -mc 0 ; Fixes Model Getting stuck on same phrase ; https://github.com/ggerganov/whisper.cpp/issues/924
2024-07-31 06:00:31 -04:00
runwait , %ComSpec% / %KeepCMDOpenOrClose% title Podcast - Transcription - In - Progress & %A_scriptdir% \Models \main . exe - m %ModelPath% - mc 0 - f " %WavFilepath% " - t %CPUThreads% - otxt - of " %OutputPath% " ; -ovtt -osrt -owts -ocsv
2024-01-14 21:39:35 -05:00
URunTime := round ( ( ( A_TickCount - UStartTime ) / 1000 ) , 2 ) ; end time
Message = Time to Transcribe : %URunTime% seconds
LogToTextFile ( Message , LogFileFP )
; get time it took to transcribe in seconds
TranscriptionLength := round ( ( ( A_TickCount - UStartTime ) / 1000 ) , 2 )
; if more than 1 hour, convert time to hours:minutes for NTFY message
( T r a n s c r i p t i o n L e n g t h > 3 6 0 0 ) ? ( N T F Y T r a n s c r i p t i o n T i m e : = r o u n d ( ( T r a n s c r i p t i o n L e n g t h / 3 6 0 0 ) , 2 ) . " H o u r s " ) : ( N T F Y T r a n s c r i p t i o n T i m e : = T r a n s c r i p t i o n L e n g t h . " S e c o n d s " )
SecondsToTranscribe1Sec := round ( ( TranscriptionLength / TotalTimeInSeconds ) , 2 )
; TotalTimeInSeconds
text = Transcription of %WavFilepath% took a total of %TranscriptionLength% Seconds
LogToTextFile ( text , LogFileFP )
PrePendToErrorLogText ( text )
2024-07-31 04:37:48 -04:00
if ( NTFY OR UploadResultToNTFY ) {
if ( UploadResultToNTFY ) {
Command = " %NTFYEXEFilepath% " publish - t " %OutNameNoExt% " - f " %OutputPath%.txt " %NTFYTopic%
2024-07-31 06:00:31 -04:00
Status := RunCMD ( Command )
}
else if ( NTFY ) {
; Message = Transcription Complete `nNode: %A_ComputerName% `nFile: %OutNameNoExt% `nAudio Length: %AudioLength%`nModel: %ModelName%`nCPU Threads: %CPUThreads% `nTTTS: %NTFYTranscriptionTime%`nTTS 1 (s): %SecondsToTranscribe1Sec% Seconds
; Message = Transcription Complete `nNode: %A_ComputerName% `nFile: %OutNameNoExt% `nAudio Length: %AudioLength%`nModel: %ModelName%`nCPU Threads: %CPUThreads% `nTTTS: %NTFYTranscriptionTime%`nTTS 1 (s): %SecondsToTranscribe1Sec% Seconds
Command = " %NTFYEXEFilepath% " publish - t " %OutNameNoExt% " %NTFYTopic% " Transcription Complete! "
2024-07-31 04:37:48 -04:00
; Clipboard := Command
; Msgbox % "Command: " Command
Status := RunCMD ( Command )
; Msgbox % "Status: " Status
2024-07-31 06:00:31 -04:00
; Message = Transcription Complete `nNode: %A_ComputerName% `nFile: %OutNameNoExt% `nAudio Length: %AudioLength%`nModel: %ModelName%`nCPU Threads: %CPUThreads% `nTTTS: %NTFYTranscriptionTime%`nTTS 1 (s): %SecondsToTranscribe1Sec% Seconds
; SendMessagetoNTFY(Message, NTFYURL)
2024-07-31 04:37:48 -04:00
}
2024-01-14 21:39:35 -05:00
}
}
; / All transcriptions have been looped through
2024-07-31 06:00:31 -04:00
; reset timer for next loop
TranscriptionLength :=
2024-01-14 21:39:35 -05:00
}
ToolTip
if ( NTFY ) {
Message = Node : %A_ComputerName% Has Completed Transcribing ALL Selected Files ! ;`nFile: %OutNameNoExt% `nModel: %ModelName%`nCPU Threads: %CPUThreads% `nLength: %AudioLength%`nTime: %TranscriptionLength% Seconds
SendMessagetoNTFY ( Message , NTFYURL )
}
2024-07-31 04:37:48 -04:00
if ( ShutdownOnFinish ) {
Shutdown , 9 ; shutdown + power down: 1 + 8 = 9
2024-01-14 21:39:35 -05:00
}
2024-07-31 06:00:31 -04:00
else , {
msgbox , All Transcriptions have been completed .
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
return
/*
* /
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
; Functions
;------------------------------------------------
LogToTextFile ( Text , Filepath ) {
; ErrorLoggingFile := Filepath
FileAppend , %Text% `n `n , %Filepath%
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
ShowTooltipText ( Text ) {
if ( ShowTooltip ) {
TooltipFirstLine := StrSplit ( Text , " `n " )
TooltipFirstLine := TooltipFirstLine [ 1 ]
ToolTipLen := StrLen ( TooltipFirstLine )
TooltipXPos := A_ScreenWidth / 2 - ( ( ToolTipLen * 9 ) / 2 )
; Msgbox % "TooltipXPos: " TooltipXPos
ToolTip , %Text% , %TooltipXPos% , 0
2024-01-14 21:39:35 -05:00
}
2024-07-31 04:37:48 -04:00
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
PrePendToErrorLogText ( Text ) {
ErrorLogText := Text " `n `n " . ErrorLogText
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
GuiControl , Text , StatusLog , %ErrorLogText%
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
SendMessagetoNTFY ( Message , URL ) {
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
command = powershell ( Invoke - RestMethod - Method 'Post ' - Uri %URL% - Body '%Message% ' - UseBasicParsing )
Status := RunCMD ( Command )
; Msgbox % "Status: " Status
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
; -------------------------------FileXPro Get File Attributes-------------------------------
;https://www.autohotkey.com/boards/viewtopic.php?t=59882
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
Filexpro ( sFile := " " , Kind := " " , P * ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
If ( sFile = " " )
{ ; Deinit static variable
xDetails := " "
Return
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
fex := { } , _FileExt := " "
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
Loop , Files , % RTrim ( sfile , " \*/. " ) , DF
{
If not FileExist ( sFile := A_LoopFileLongPath )
2024-01-14 21:39:35 -05:00
{
Return
2024-07-31 04:37:48 -04:00
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
SplitPath , sFile , _FileExt , _Dir , _Ext , _File , _Drv
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
If ( p [ p . length ( ) ] = " xInfo " ) ; Last parameter is xInfo
2024-01-14 21:39:35 -05:00
{
2024-07-31 04:37:48 -04:00
p . Pop ( ) ; Delete parameter
fex . SetCapacity ( 11 ) ; Make room for Extra info
fex [ " _Attrib " ] := A_LoopFileAttrib
fex [ " _Dir " ] := _Dir
fex [ " _Drv " ] := _Drv
fex [ " _Ext " ] := _Ext
fex [ " _File " ] := _File
fex [ " _File.Ext " ] := _FileExt
fex [ " _FilePath " ] := sFile
fex [ " _FileSize " ] := A_LoopFileSize
fex [ " _FileTimeA " ] := A_LoopFileTimeAccessed
fex [ " _FileTimeC " ] := A_LoopFileTimeCreated
fex [ " _FileTimeM " ] := A_LoopFileTimeModified
}
Break
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
If Not ( _FileExt ) ; Filepath not resolved
{
Return
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
objShl := ComObjCreate ( " Shell.Application " )
objDir := objShl . NameSpace ( _Dir )
objItm := objDir . ParseName ( _FileExt )
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
If ( VarSetCapacity ( xDetails ) = 0 ) ; Init static variable
{
i: = - 1 , xDetails := { } , xDetails . SetCapacity ( 309 )
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
While ( i + + < 309 )
2024-01-14 21:39:35 -05:00
{
2024-07-31 04:37:48 -04:00
xDetails [ objDir . GetDetailsOf ( 0 , i ) ] := i
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
xDetails . Delete ( " " )
}
If ( Kind and Kind < > objDir . GetDetailsOf ( objItm , 11 ) ) ; File isn't desired kind
{
Return
}
i: = 0 , nParams := p . Count ( ) , fex . SetCapacity ( nParams + 11 )
While ( i + + < nParams )
{
Prop := p [ i ]
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
If ( ( Dot := InStr ( Prop , " . " ) ) and ( Prop := ( Dot = 1 ? " System " : " " ) . Prop ) )
{
fex [ Prop ] := objItm . ExtendedProperty ( Prop )
Continue
2024-01-14 21:39:35 -05:00
}
2024-07-31 04:37:48 -04:00
If ( PropNum := xDetails [ Prop ] ) > - 1
{
fex [ Prop ] := ObjDir . GetDetailsOf ( objItm , PropNum )
Continue
}
}
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
fex . SetCapacity ( - 1 )
Return fex
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
} ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-01-14 21:39:35 -05:00
2024-07-31 04:37:48 -04:00
; Misc
;------------------------------------------------
2024-01-14 21:39:35 -05:00
; Escape::ExitApp