microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/tts-voiceover/scripts/Invoke-EmbedAudio.ps1
94lines · modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | #Requires -Version 7.0 |
| 5 | # |
| 6 | # Invoke-EmbedAudio.ps1 |
| 7 | # |
| 8 | # Purpose: Wrapper that manages uv venv setup and delegates to embed_audio.py |
| 9 | |
| 10 | <# |
| 11 | .SYNOPSIS |
| 12 | Embeds per-slide WAV voice-over files into a PowerPoint deck. |
| 13 | |
| 14 | .DESCRIPTION |
| 15 | Manages the Python virtual environment and invokes embed_audio.py to add |
| 16 | WAV files as embedded media objects in the corresponding slides of a PPTX file. |
| 17 | |
| 18 | .PARAMETER InputPath |
| 19 | Source PPTX file path. Required. |
| 20 | |
| 21 | .PARAMETER AudioDir |
| 22 | Directory containing slide-NNN.wav files. Defaults to voice-over. |
| 23 | |
| 24 | .PARAMETER OutputPath |
| 25 | Output PPTX file path. Defaults to input stem + '-narrated.pptx'. |
| 26 | |
| 27 | .PARAMETER SkipVenvSetup |
| 28 | Skip virtual environment creation and dependency installation. |
| 29 | |
| 30 | .EXAMPLE |
| 31 | ./Invoke-EmbedAudio.ps1 -InputPath deck.pptx -AudioDir voice-over |
| 32 | |
| 33 | .EXAMPLE |
| 34 | ./Invoke-EmbedAudio.ps1 -InputPath deck.pptx -AudioDir voice-over -OutputPath deck-narrated.pptx |
| 35 | |
| 36 | .NOTES |
| 37 | Part of the tts-voiceover skill. Manages uv virtual environment setup |
| 38 | and delegates to embed_audio.py for WAV embedding into PPTX slides. |
| 39 | #> |
| 40 | |
| 41 | [CmdletBinding()] |
| 42 | param( |
| 43 | [Parameter(Mandatory = $true)] |
| 44 | [ValidateNotNullOrEmpty()] |
| 45 | [string]$InputPath, |
| 46 | |
| 47 | [Parameter(Mandatory = $false)] |
| 48 | [string]$AudioDir, |
| 49 | |
| 50 | [Parameter(Mandatory = $false)] |
| 51 | [string]$OutputPath, |
| 52 | |
| 53 | [Parameter(Mandatory = $false)] |
| 54 | [switch]$SkipVenvSetup |
| 55 | ) |
| 56 | |
| 57 | $ErrorActionPreference = 'Stop' |
| 58 | |
| 59 | $ScriptDir = $PSScriptRoot |
| 60 | $SkillRoot = Split-Path $ScriptDir |
| 61 | $VenvDir = Join-Path $SkillRoot '.venv' |
| 62 | |
| 63 | Import-Module (Join-Path $ScriptDir 'Modules/TtsVoiceoverHelpers.psm1') -Force |
| 64 | |
| 65 | #region Main |
| 66 | |
| 67 | if ($MyInvocation.InvocationName -ne '.') { |
| 68 | |
| 69 | $null = Test-UvAvailability |
| 70 | |
| 71 | if (-not $SkipVenvSetup) { |
| 72 | Initialize-PythonEnvironment -SkillRoot $SkillRoot |
| 73 | } |
| 74 | |
| 75 | $python = Get-VenvPythonPath -VenvDir $VenvDir |
| 76 | if (-not (Test-Path $python)) { |
| 77 | throw "Python not found at $python. Run without -SkipVenvSetup to initialize." |
| 78 | } |
| 79 | |
| 80 | $script = Join-Path $ScriptDir 'embed_audio.py' |
| 81 | $PythonArgs = @('--input', $InputPath) |
| 82 | |
| 83 | if ($AudioDir) { $PythonArgs += '--audio-dir', $AudioDir } |
| 84 | if ($OutputPath) { $PythonArgs += '--output', $OutputPath } |
| 85 | if ($VerbosePreference -ne 'SilentlyContinue') { $PythonArgs += '--verbose' } |
| 86 | |
| 87 | & $python $script @PythonArgs |
| 88 | if ($LASTEXITCODE -ne 0) { |
| 89 | throw "embed_audio.py exited with code $LASTEXITCODE" |
| 90 | } |
| 91 | |
| 92 | } |
| 93 | |
| 94 | #endregion Main |
| 95 | |