microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/powerpoint/scripts/embed-audio.sh
75lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # embed-audio.sh |
| 6 | # Embed WAV audio files into a PowerPoint deck. |
| 7 | |
| 8 | set -euo pipefail |
| 9 | |
| 10 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 11 | SKILL_ROOT="$(dirname "${SCRIPT_DIR}")" |
| 12 | VENV_DIR="${SKILL_ROOT}/.venv" |
| 13 | |
| 14 | SKIP_VENV_SETUP=false |
| 15 | VERBOSE=false |
| 16 | |
| 17 | err() { |
| 18 | printf "ERROR: %s\n" "$1" >&2 |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | usage() { |
| 23 | cat <<EOF |
| 24 | Usage: $(basename "$0") [OPTIONS] |
| 25 | |
| 26 | Options: |
| 27 | --input <path> Input PPTX file path (required) |
| 28 | --audio-dir <path> Directory containing WAV files (required) |
| 29 | --output <path> Output PPTX file path (required) |
| 30 | --slides <list> Comma-separated slide numbers (optional) |
| 31 | --skip-venv-setup Skip virtual environment setup |
| 32 | -v, --verbose Enable verbose output |
| 33 | -h, --help Show this help message |
| 34 | EOF |
| 35 | exit 0 |
| 36 | } |
| 37 | |
| 38 | get_venv_python_path() { |
| 39 | if [[ -f "${VENV_DIR}/Scripts/python.exe" ]]; then |
| 40 | echo "${VENV_DIR}/Scripts/python.exe" |
| 41 | elif [[ -f "${VENV_DIR}/bin/python" ]]; then |
| 42 | echo "${VENV_DIR}/bin/python" |
| 43 | else |
| 44 | err "Python interpreter not found in venv. Run: uv sync --directory \"${SKILL_ROOT}\"" |
| 45 | fi |
| 46 | } |
| 47 | |
| 48 | main() { |
| 49 | local -a pass_through=() |
| 50 | |
| 51 | while (( $# > 0 )); do |
| 52 | case "$1" in |
| 53 | --skip-venv-setup) SKIP_VENV_SETUP=true; shift ;; |
| 54 | -v|--verbose) VERBOSE=true; shift ;; |
| 55 | -h|--help) usage ;; |
| 56 | *) pass_through+=("$1"); shift ;; |
| 57 | esac |
| 58 | done |
| 59 | |
| 60 | if [[ "${SKIP_VENV_SETUP}" == "false" ]]; then |
| 61 | if ! command -v uv &>/dev/null; then |
| 62 | err "uv is required but was not found on PATH." |
| 63 | fi |
| 64 | uv sync --directory "${SKILL_ROOT}" |
| 65 | fi |
| 66 | |
| 67 | local python |
| 68 | python="$(get_venv_python_path)" |
| 69 | |
| 70 | [[ "${VERBOSE:-false}" == "true" ]] && pass_through+=("-v") |
| 71 | |
| 72 | "${python}" "${SCRIPT_DIR}/embed_audio.py" "${pass_through[@]}" |
| 73 | } |
| 74 | |
| 75 | main "$@" |