"""
@author: zoutai
@file: mymfcc.py
@time: 2018/03/26
@description:
"""
from matplotlib.colors import BoundaryNorm
import librosa
import librosa.display
import numpy
import scipy.io.wavfile
from scipy.fftpack import dct
import matplotlib.pyplot as plt
import numpy as np
# 第一步-读取音频,画出时域图(采样率-幅度)
sample_rate, signal = scipy.io.wavfile.read('OSR_us_000_0010_8k.wav') # File assumed to be in the same directory
signal = signal[0:int(3.5 * sample_rate)]
# plot the wave
time = np.arange(0,len(signal))*(1.0 / sample_rate)
# plt.plot(time,signal)
plt.xlabel("Time(s)")
plt.ylabel("Amplitude")
plt.title("Signal in the Time Domain ")
plt.grid('on')#标尺,on:有,off:无。
# 第二步-预加重
# 消除高频信号。因为高频信号往往都是相似的,
# 通过前后时间相减,就可以近乎抹去高频信号,留下低频信号。
# 原理:y(t)=x(t)−αx(t−1)
pre_emphasis = 0.97
emphasized_signal = numpy.append(signal[0], signal[1:] - pre_emphasis * signal[:-1])
time = np.arange(0,len(emphasized_signal))*(1.0 / sample_rate)
# plt.plot(time,emphasized_signal)
# plt.xlabel("Time(s)")