Created
February 23, 2018 22:13
-
-
Save mohit-0212/540bf61ceae166970ce245b88e68ff4b to your computer and use it in GitHub Desktop.
Analysing audio signals of a video
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
import subprocess | |
import numpy as np | |
import scipy | |
import librosa | |
import matplotlib.pyplot as plt | |
file_input = "/path for/video file/" | |
file_output = "/path for/output audio file.wav/" | |
command = "ffmpeg -i " + file_input +" -t 300 -codec:a pcm_s16le -ac 1 "+ file_output #converts the first 5 minutes of video file to wav output | |
subprocess.call(command, shell=True) | |
x, sr = librosa.load(file_output) | |
rmse = librosa.feature.rmse(x) | |
rate = 300.0/rmse.shape[1] | |
time = [i*rate for i in range(1,rmse.shape[1]+1)] #get corresponding time values for frames | |
plt.figure(1) | |
plt.plot(time, rmse[0]) | |
plt.show() | |
zcrs = librosa.feature.zero_crossing_rate(x) | |
plt.figure(2) | |
plt.plot(time, zcrs[0]) | |
plt.show() | |
''' | |
Tried taking difference of above two values | |
diff = [] | |
for i in range(len(zcrs[0])): | |
z = rmse[0][i]-zcrs[0][i] | |
if z>0: | |
z=0 | |
diff.append(z) | |
plt.figure(3) | |
plt.plot(ind, diff) | |
plt.show() | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment