microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/tts-voiceover/scripts/Invoke-GenerateVoiceover.ps1
118lines · modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | #Requires -Version 7.0 |
| 5 | # |
| 6 | # Invoke-GenerateVoiceover.ps1 |
| 7 | # |
| 8 | # Purpose: Wrapper that manages uv venv setup and delegates to generate_voiceover.py |
| 9 | |
| 10 | <# |
| 11 | .SYNOPSIS |
| 12 | Generates per-slide TTS voice-over from YAML speaker notes via Azure Speech SDK. |
| 13 | |
| 14 | .DESCRIPTION |
| 15 | Manages the Python virtual environment and invokes generate_voiceover.py to |
| 16 | produce per-slide WAV files from YAML speaker notes with SSML acronym aliases. |
| 17 | |
| 18 | .PARAMETER DryRun |
| 19 | Print SSML templates without generating audio. |
| 20 | |
| 21 | .PARAMETER Voice |
| 22 | Azure TTS voice name. Defaults to en-US-Andrew:DragonHDLatestNeural. |
| 23 | |
| 24 | .PARAMETER Rate |
| 25 | Speech prosody rate. Defaults to +10%. |
| 26 | |
| 27 | .PARAMETER ContentDir |
| 28 | Path to slide content directory. Defaults to content. |
| 29 | |
| 30 | .PARAMETER OutputDir |
| 31 | Path to WAV output directory. Defaults to voice-over. |
| 32 | |
| 33 | .PARAMETER Lexicon |
| 34 | Path to custom acronyms.yaml lexicon file. |
| 35 | |
| 36 | .PARAMETER SkipVenvSetup |
| 37 | Skip virtual environment creation and dependency installation. |
| 38 | |
| 39 | .EXAMPLE |
| 40 | ./Invoke-GenerateVoiceover.ps1 -DryRun -ContentDir content |
| 41 | |
| 42 | .EXAMPLE |
| 43 | ./Invoke-GenerateVoiceover.ps1 -ContentDir content -OutputDir voice-over |
| 44 | |
| 45 | .EXAMPLE |
| 46 | ./Invoke-GenerateVoiceover.ps1 -ContentDir content -Voice "en-US-Jenny:DragonHDLatestNeural" -Rate "+5%" |
| 47 | |
| 48 | .NOTES |
| 49 | Part of the tts-voiceover skill. Manages uv virtual environment setup |
| 50 | and delegates to generate_voiceover.py for TTS audio generation. |
| 51 | #> |
| 52 | |
| 53 | [CmdletBinding()] |
| 54 | param( |
| 55 | [Parameter(Mandatory = $false)] |
| 56 | [switch]$DryRun, |
| 57 | |
| 58 | [Parameter(Mandatory = $false)] |
| 59 | [string]$Voice, |
| 60 | |
| 61 | [Parameter(Mandatory = $false)] |
| 62 | [string]$Rate, |
| 63 | |
| 64 | [Parameter(Mandatory = $false)] |
| 65 | [string]$ContentDir, |
| 66 | |
| 67 | [Parameter(Mandatory = $false)] |
| 68 | [string]$OutputDir, |
| 69 | |
| 70 | [Parameter(Mandatory = $false)] |
| 71 | [string]$Lexicon, |
| 72 | |
| 73 | [Parameter(Mandatory = $false)] |
| 74 | [switch]$SkipVenvSetup |
| 75 | ) |
| 76 | |
| 77 | $ErrorActionPreference = 'Stop' |
| 78 | |
| 79 | $ScriptDir = $PSScriptRoot |
| 80 | $SkillRoot = Split-Path $ScriptDir |
| 81 | $VenvDir = Join-Path $SkillRoot '.venv' |
| 82 | |
| 83 | Import-Module (Join-Path $ScriptDir 'Modules/TtsVoiceoverHelpers.psm1') -Force |
| 84 | |
| 85 | #region Main |
| 86 | |
| 87 | if ($MyInvocation.InvocationName -ne '.') { |
| 88 | |
| 89 | $null = Test-UvAvailability |
| 90 | |
| 91 | if (-not $SkipVenvSetup) { |
| 92 | Initialize-PythonEnvironment -SkillRoot $SkillRoot |
| 93 | } |
| 94 | |
| 95 | $python = Get-VenvPythonPath -VenvDir $VenvDir |
| 96 | if (-not (Test-Path $python)) { |
| 97 | throw "Python not found at $python. Run without -SkipVenvSetup to initialize." |
| 98 | } |
| 99 | |
| 100 | $script = Join-Path $ScriptDir 'generate_voiceover.py' |
| 101 | $PythonArgs = @() |
| 102 | |
| 103 | if ($DryRun) { $PythonArgs += '--dry-run' } |
| 104 | if ($Voice) { $PythonArgs += '--voice', $Voice } |
| 105 | if ($Rate) { $PythonArgs += '--rate', $Rate } |
| 106 | if ($ContentDir) { $PythonArgs += '--content-dir', $ContentDir } |
| 107 | if ($OutputDir) { $PythonArgs += '--output-dir', $OutputDir } |
| 108 | if ($Lexicon) { $PythonArgs += '--lexicon', $Lexicon } |
| 109 | if ($VerbosePreference -ne 'SilentlyContinue') { $PythonArgs += '--verbose' } |
| 110 | |
| 111 | & $python $script @PythonArgs |
| 112 | if ($LASTEXITCODE -ne 0) { |
| 113 | throw "generate_voiceover.py exited with code $LASTEXITCODE" |
| 114 | } |
| 115 | |
| 116 | } |
| 117 | |
| 118 | #endregion Main |
| 119 | |