Выровнять громкость папки
Пакетно приводит файлы к выбранному LUFS и складывает MP3 в отдельную папку.
Что делает скрипт
Скрипт проходит по папке и применяет 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 256kpowershell -File Set-AudioLoudness.ps1 -Path D:\Voice -Target -18 -Force
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
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 }
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.