Last active
October 2, 2020 13:25
-
-
Save lasp73/9e4fa1ef9f7ad7b6adcb68ce09bcdd85 to your computer and use it in GitHub Desktop.
Scripts to get the maximum amplitude from audio files and plot histogram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
AUDIODIR=$1 | |
helpmsg="get-audio-max.sh <input directory>" | |
[[ -n "$AUDIODIR" ]] || \ | |
{ | |
echo "You must inform the input directory with the RAW audio files"; | |
echo $helpmsg; | |
exit 1; | |
} | |
[[ ${AUDIODIR,,} == "--help" ]] && { echo $helpmsg; exit 1; } | |
type sox1 >/dev/null 2>&1 || \ | |
{ | |
echo "You must install 'sox' first."; | |
echo "Use something like 'sudo yum -y install sox' or 'sudo apt-get install sox'"; | |
exit 1; | |
} | |
find $AUDIODIR -name "*.wav" -exec sox {} -n stat 2>&1 \; | grep "Maximum amplitude" | sed -r "s/\s+//g" | cut -d":" -f 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import matplotlib.pyplot as plt | |
import sys | |
values = [] | |
for line in sys.stdin: | |
values.append(float(line)) | |
plt.xlabel('Metric') | |
plt.ylabel('Frequency') | |
plt.title('Histogram') | |
plt.hist(values, bins=100, facecolor='blue', normed=True, cumulative=True) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can show the histogram by running:
./get-audio-max.sh audio_dir | ./plot-histogram.py