microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/powerpoint/scripts/Invoke-EmbedAudio.ps1
91lines · modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | #Requires -Version 7.0 |
| 5 | |
| 6 | <# |
| 7 | .SYNOPSIS |
| 8 | Embed WAV audio files into a PowerPoint deck. |
| 9 | |
| 10 | .DESCRIPTION |
| 11 | Wrapper script that manages the Python virtual environment and invokes |
| 12 | embed_audio.py to embed per-slide WAV files into a PPTX presentation. |
| 13 | |
| 14 | .PARAMETER InputPath |
| 15 | Input PPTX file path. |
| 16 | |
| 17 | .PARAMETER AudioDir |
| 18 | Directory containing slide-NNN.wav files. |
| 19 | |
| 20 | .PARAMETER OutputPath |
| 21 | Output PPTX file path. |
| 22 | |
| 23 | .PARAMETER Slides |
| 24 | Comma-separated slide numbers to embed audio on (optional). |
| 25 | |
| 26 | .PARAMETER SkipVenvSetup |
| 27 | Skip virtual environment setup. |
| 28 | |
| 29 | .EXAMPLE |
| 30 | ./Invoke-EmbedAudio.ps1 -InputPath deck.pptx -AudioDir voice-over/ -OutputPath out.pptx |
| 31 | |
| 32 | .NOTES |
| 33 | Part of the powerpoint skill. Manages uv virtual environment setup |
| 34 | and delegates to embed_audio.py for WAV embedding into PPTX slides. |
| 35 | #> |
| 36 | |
| 37 | [CmdletBinding()] |
| 38 | param( |
| 39 | [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$InputPath, |
| 40 | [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$AudioDir, |
| 41 | [Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$OutputPath, |
| 42 | [Parameter(Mandatory = $false)][string]$Slides, |
| 43 | [Parameter(Mandatory = $false)][switch]$SkipVenvSetup |
| 44 | ) |
| 45 | |
| 46 | $ErrorActionPreference = 'Stop' |
| 47 | |
| 48 | #region Environment Setup |
| 49 | |
| 50 | $ScriptDir = $PSScriptRoot |
| 51 | $SkillRoot = Split-Path -Parent $ScriptDir |
| 52 | $VenvDir = Join-Path $SkillRoot '.venv' |
| 53 | |
| 54 | #endregion Environment Setup |
| 55 | |
| 56 | #region Main |
| 57 | |
| 58 | if ($MyInvocation.InvocationName -ne '.') { |
| 59 | |
| 60 | try { |
| 61 | if (-not $SkipVenvSetup) { |
| 62 | if (-not (Get-Command uv -ErrorAction SilentlyContinue)) { |
| 63 | throw 'uv is required but was not found on PATH.' |
| 64 | } |
| 65 | uv sync --directory $SkillRoot |
| 66 | } |
| 67 | |
| 68 | $python = if (Test-Path (Join-Path $VenvDir 'Scripts/python.exe')) { |
| 69 | Join-Path $VenvDir 'Scripts/python.exe' |
| 70 | } elseif (Test-Path (Join-Path $VenvDir 'bin/python')) { |
| 71 | Join-Path $VenvDir 'bin/python' |
| 72 | } else { |
| 73 | throw "Python interpreter not found in venv. Run: uv sync --directory `"$SkillRoot`"" |
| 74 | } |
| 75 | |
| 76 | $script = Join-Path $ScriptDir 'embed_audio.py' |
| 77 | $ScriptArgs = @($script, '--input', $InputPath, '--audio-dir', $AudioDir, '--output', $OutputPath) |
| 78 | if ($Slides) { $ScriptArgs += '--slides'; $ScriptArgs += $Slides } |
| 79 | if ($VerbosePreference -eq 'Continue') { $ScriptArgs += '-v' } |
| 80 | |
| 81 | & $python @ScriptArgs |
| 82 | exit $LASTEXITCODE |
| 83 | } |
| 84 | catch { |
| 85 | Write-Error -ErrorAction Continue "Invoke-EmbedAudio failed: $($_.Exception.Message)" |
| 86 | exit 1 |
| 87 | } |
| 88 | |
| 89 | } |
| 90 | |
| 91 | #endregion Main |
| 92 | |