Skip to content

Instantly share code, notes, and snippets.

@lasp73
Last active October 2, 2020 13:25
Show Gist options
  • Save lasp73/9e4fa1ef9f7ad7b6adcb68ce09bcdd85 to your computer and use it in GitHub Desktop.
Save lasp73/9e4fa1ef9f7ad7b6adcb68ce09bcdd85 to your computer and use it in GitHub Desktop.
Scripts to get the maximum amplitude from audio files and plot histogram
#!/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
#!/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()
@lasp73
Copy link
Author

lasp73 commented Jun 6, 2018

You can show the histogram by running:
./get-audio-max.sh audio_dir | ./plot-histogram.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment