Аудио

Выровнять громкость папки

Пакетно приводит файлы к выбранному LUFS и складывает MP3 в отдельную папку.

PowerShell Windows Средний
Скачать Set-AudioLoudness.ps1
Описание

Что делает скрипт

Скрипт проходит по папке и применяет loudnorm к каждому файлу, чтобы выпуски или треки звучали одинаково. Цель выбирается из типовых значений -23, -20, -18, -16 и -14 LUFS. Оригиналы не меняются, существующие результаты пропускаются.

Запуск

Быстрый старт

powershell -File Set-AudioLoudness.ps1 -Path C:\Podcasts -Target -16

Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.

Примеры

Другие варианты

  • powershell -File Set-AudioLoudness.ps1 -Path C:\Music -Target -14 -Bitrate 256k
  • powershell -File Set-AudioLoudness.ps1 -Path D:\Voice -Target -18 -Force
Зависимости

Что понадобится

PowerShell 5.1+ Встроен в Windows 10 и 11
Windows Встроен в Windows 10/11 (PowerShell 5.1)
FFmpeg 6+ Кодирование, фильтры и ffprobe
Windows winget install Gyan.FFmpeg
Исходник

Set-AudioLoudness.ps1

[CmdletBinding(SupportsShouldProcess = $true)]
param(
    [Parameter(Mandatory = $true)]
    [string]$Path,
    [string]$OutputDirectory,
    [ValidateSet('-23', '-20', '-18', '-16', '-14')]
    [string]$Target = '-16',
    [ValidateSet('128k', '192k', '256k', '320k')]
    [string]$Bitrate = '192k',
    [switch]$Force
)

$ErrorActionPreference = 'Stop'

$ffmpeg = Get-Command ffmpeg -ErrorAction SilentlyContinue
if (-not $ffmpeg) {
    throw 'ffmpeg не найден. Установите FFmpeg через winget.'
}

$resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop
$extensions = @('.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac', '.wma')
if (Test-Path -LiteralPath $resolved.Path -PathType Container) {
    $root = $resolved.Path
    $files = @(Get-ChildItem -LiteralPath $root -File -Recurse -ErrorAction SilentlyContinue |
        Where-Object { $extensions -contains $_.Extension.ToLowerInvariant() })
    if (-not $OutputDirectory) { $OutputDirectory = Join-Path $root 'aligned' }
} else {
    $item = Get-Item -LiteralPath $resolved.Path
    if ($extensions -notcontains $item.Extension.ToLowerInvariant()) {
        throw "Формат не похож на аудио: $($item.Extension)"
    }
    $files = @($item)
    if (-not $OutputDirectory) {
        $OutputDirectory = Join-Path (Split-Path -Parent $item.FullName) 'aligned'
    }
}

if ($files.Count -eq 0) {
    Write-Host 'Аудиофайлы не найдены.'
    exit 0
}

$outRoot = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputDirectory)
New-Item -ItemType Directory -Path $outRoot -Force | Out-Null

$filter = "loudnorm=I=$Target`:TP=-1.5:LRA=11"
$done = 0
$skipped = 0
$failed = 0

foreach ($item in $files) {
    $destination = Join-Path $outRoot ($item.BaseName + '_aligned.mp3')
    if ((Test-Path -LiteralPath $destination) -and -not $Force) {
        Write-Host "Пропуск: $destination уже существует"
        $skipped++
        continue
    }
    if (-not $PSCmdlet.ShouldProcess($destination, "Выровнять громкость до $Target LUFS")) { continue }

    $overwrite = if ($Force) { '-y' } else { '-n' }
    & $ffmpeg.Source -hide_banner -loglevel error -nostdin $overwrite `
        -i $item.FullName -af $filter -ar 44100 -ac 2 `
        -c:a libmp3lame -b:a $Bitrate -map_metadata 0 $destination
    if ($LASTEXITCODE -eq 0) {
        Write-Host "Готово: $($item.Name) -> $destination"
        $done++
    } else {
        Write-Host "Ошибка: $($item.FullName)" -ForegroundColor Red
        $failed++
    }
}

Write-Host "Итог: готово $done, пропущено $skipped, ошибок $failed"
if ($failed -gt 0) { exit 2 }

Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.

CLI 1.0.0

Скачать без браузера

Команда скачает этот файл в текущую папку. CLI работает на Windows, macOS и Linux.

scriptdock get audio-loudness-align
  • Поиск по всему каталогу
  • Python 3.10+
  • Без внешних пакетов
Скачать CLI

GUI-версия готовится. Подробнее

Категория

Аудио

Конвертация, нормализация, обрезка, теги и подготовка звука.