Skip to content

Commit

Permalink
Clean the audio twice for a cleaner output.
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaszanolli committed Feb 13, 2024
1 parent b224363 commit be7ecc4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
27 changes: 20 additions & 7 deletions devinyl.ps1
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down Expand Up @@ -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
Remove-Item noiseaudpre.wav, noiseaud.wav, noisepre.prof, noise.prof, $OUTPUTFILE-preclean.wav, $OUTPUTFILE-clean.wav, $DECOMPRESSED
41 changes: 28 additions & 13 deletions devinyl.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -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"

0 comments on commit be7ecc4

Please sign in to comment.