From be7ecc41a9658ce0edc5c0acde48ebb8c788d011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Zanolli?= Date: Mon, 12 Feb 2024 21:19:38 -0300 Subject: [PATCH] Clean the audio twice for a cleaner output. --- devinyl.ps1 | 27 ++++++++++++++++++++------- devinyl.sh | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/devinyl.ps1 b/devinyl.ps1 index 7005d03..54440a8 100644 --- a/devinyl.ps1 +++ b/devinyl.ps1 @@ -1,5 +1,4 @@ # Based on this guide: http://www.zoharbabin.com/how-to-do-noise-reduction-using-ffmpeg-and-sox/ -# Script converted to PowerShell # Check that FFMPEG and sox are installed if (-not (Get-Command ffmpeg -ErrorAction SilentlyContinue)) { @@ -28,19 +27,33 @@ $DECOMPRESSED = $OUTPUTFILE + '.wav' Write-Host "Decompressing the audio file..." ffmpeg -i $INPUTFILE $DECOMPRESSED -# Listen to first half second of video -Write-Host "Listening to first half second of video to get noise level..." -ffmpeg -i $DECOMPRESSED -ss 00:00:00.0 -t 00:00:00.5 noiseaud.wav +# Listen to first half second of audio +Write-Host "Listening to first half second of audio to get noise level..." +ffmpeg -i $DECOMPRESSED -ss 00:00:01.0 -t 00:00:02.0 noiseaudpre.wav # Generate noise profile Write-Host "Making noise profile..." -sox noiseaud.wav -n noiseprof noise.prof +sox noiseaudpre.wav -n noiseprof noisepre.prof # Clean the audio file with the profile created Write-Host "Cleaning the audio with the profile..." -sox $DECOMPRESSED $OUTPUTFILE-clean.wav noisered noise.prof 0.21 +sox $DECOMPRESSED $OUTPUTFILE-preclean.wav noisered noisepre.prof 0.21 + +# Listen to first half second of audio +Write-Host "Listening to first half second of audio to get noise level..." +ffmpeg -i $OUTPUTFILE-preclean.wav -ss 00:00:01.0 -t 00:00:02.0 noiseaud.wav + +# Generate second noise profile +Write-Host "Making second noise profile..." +sox noiseaud.wav -n noiseprof noise.prof + +# Clean the audio file with the second profile +Write-Host "Cleaning the audio with the second profile..." +sox $OUTPUTFILE-preclean.wav $OUTPUTFILE-clean.wav noisered noise.prof 0.21 + +# Convert the cleaned audio to FLAC ffmpeg -i $OUTPUTFILE-clean.wav $OUTPUTFILE-clean.flac Write-Host "Cleaning up..." # Clean up temp files -Remove-Item noiseaud.wav, noise.prof, $OUTPUTFILE-clean.wav, $DECOMPRESSED \ No newline at end of file +Remove-Item noiseaudpre.wav, noiseaud.wav, noisepre.prof, noise.prof, $OUTPUTFILE-preclean.wav, $OUTPUTFILE-clean.wav, $DECOMPRESSED \ No newline at end of file diff --git a/devinyl.sh b/devinyl.sh index a3ad85c..178b92b 100644 --- a/devinyl.sh +++ b/devinyl.sh @@ -1,6 +1,8 @@ #!/bin/bash -# Check if ffmpeg and sox are installed +# Based on this guide: http://www.zoharbabin.com/how-to-do-noise-reduction-using-ffmpeg-and-sox/ + +# Check that FFMPEG and sox are installed if ! command -v ffmpeg &> /dev/null then echo "FFMPEG is not installed." @@ -14,34 +16,47 @@ then fi # Check if a file has been passed for cleaning -if [ $# -eq 0 ] -then +if [ "$#" -eq 0 ]; then echo "No file given to clean up." exit fi # Variables -INPUTFILE=$1 +INPUTFILE="$1" OUTPUTFILE="${INPUTFILE%.*}" -DECOMPRESSED="$OUTPUTFILE.wav" +DECOMPRESSED="${OUTPUTFILE}.wav" # Decompress the audio file echo "Decompressing the audio file..." -ffmpeg -i $INPUTFILE $DECOMPRESSED +ffmpeg -i "$INPUTFILE" "$DECOMPRESSED" -# Listen to first half second of video -echo "Listening to first half second of video to get noise level..." -ffmpeg -i $DECOMPRESSED -ss 00:00:00.0 -t 00:00:00.5 noiseaud.wav +# Listen to first half second of audio +echo "Listening to first half second of audio to get noise level..." +ffmpeg -i "$DECOMPRESSED" -ss 00:00:01.0 -t 00:00:02.0 noiseaudpre.wav # Generate noise profile echo "Making noise profile..." -sox noiseaud.wav -n noiseprof noise.prof +sox noiseaudpre.wav -n noiseprof noisepre.prof # Clean the audio file with the profile created echo "Cleaning the audio with the profile..." -sox $DECOMPRESSED $OUTPUTFILE-clean.wav noisered noise.prof 0.21 -ffmpeg -i $OUTPUTFILE-clean.wav $OUTPUTFILE-clean.flac +sox "$DECOMPRESSED" "${OUTPUTFILE}-preclean.wav" noisered noisepre.prof 0.21 + +# Listen to first half second of audio +echo "Listening to first half second of audio to get noise level..." +ffmpeg -i "${OUTPUTFILE}-preclean.wav" -ss 00:00:01.0 -t 00:00:02.0 noiseaud.wav + +# Generate second noise profile +echo "Making second noise profile..." +sox noiseaud.wav -n noiseprof noise.prof + +# Clean the audio file with the second profile +echo "Cleaning the audio with the second profile..." +sox "${OUTPUTFILE}-preclean.wav" "${OUTPUTFILE}-clean.wav" noisered noise.prof 0.21 + +# Convert the cleaned audio to FLAC +ffmpeg -i "${OUTPUTFILE}-clean.wav" "${OUTPUTFILE}-clean.flac" echo "Cleaning up..." # Clean up temp files -rm noiseaud.wav noise.prof $OUTPUTFILE-clean.wav $DECOMPRESSED +rm noiseaudpre.wav noiseaud.wav noisepre.prof noise.prof "${OUTPUTFILE}-preclean.wav" "${OUTPUTFILE}-clean.wav" "$DECOMPRESSED" \ No newline at end of file