Python wav file zero-crossing rate and plot out

import math
import wave
import numpy as np
import pylab as pl

def ZeroCR(waveData,frameSize,overLap):
    wlen = len(waveData)
    step = frameSize - overLap
    frameNum = math.ceil(wlen/step)
    zcr = np.zeros((frameNum,1))
    for i in range(frameNum):
        curFrame = waveData[np.arange(i*step,min(i*step+frameSize,wlen))]
        #To avoid DC bias, usually we need to perform mean subtraction on each frame
        curFrame = curFrame - np.mean(curFrame) # zero-justified
        zcr[i] = sum(curFrame[0:-1]*curFrame[1::]<=0)
        # print(zcr[i])
    return zcr


fw = wave.open(r'D:\Workspace\dejavu\preprocessing\tool\aim call wav file\guanji      4.wav','rb')
params = fw.getparams()
print(params)
nchannels, sampwidth, framerate, nframes = params[:4]
str_data = fw.readframes(nframes)
wave_data = np.fromstring(str_data, dtype=np.int16)
Wave_data = wave_data*1.0/(max(abs(wave_data)))#wave amplitude normalization
fw.close()

# calculate Zero Cross Rate
frameSize = 512
overLap = 0
zcr = ZeroCR(wave_data,frameSize,overLap)
zcr_1=zcr.T
print(zcr_1)
time = np.arange(0, len(wave_data)) * (1.0 / framerate)
time2 = np.arange(0, len(zcr)) * (len(wave_data)/len(zcr) / framerate)
pl.subplot(211)
pl.plot(time, wave_data)
pl.ylabel("Amplitude")
pl.subplot(212)
pl.plot(time2, zcr)
pl.ylabel("ZCR")
pl.xlabel("time (seconds)")
pl.show()

 

Intelligent Recommendation

Spectral Entropy and Zero Crossing Rate for Endpoint Detection of Speech Signals

The idea of ​​using double threshold method: First, the spectral entropy of the noise segment (high randomness and high confusion) is greater than the speech segment, distinguishing the voiced and noi...

Short-time zero-crossing rate in time domain for acoustic event recognition

1. Introduction to the concept The short-term zero-crossing rate can be regarded as a simple measure of the signal frequency and is a rough estimate of the spectral characteristics. (1) Zero crossing ...

MATLAB calculates short-time average zero-crossing rate of signal

1. Principle: The short-term average zero-crossing rate indicates the number of times the speech signal waveform crosses the horizontal axis in a frame of speech Two, calculate the zero-crossing rate ...

Python reading wav audio file

The first way: Beep The second way: Music (wav format or mp3 format) Installation playsound library pip install playsound Run the sample:...

Python parsing wav voice file

Description This article mainly uses python programming to parse the wav voice file, and get the number of channels, quantization bits, sampling frequency, and number of sampling points of the .wav vo...

More Recommendation

Python | Generate and play .wav file

Features: (1) Read the local .mat file (2) Convert the .mat file to .WAV file output (3) Play .WAV file instruction: When you need to run, you only need the following programs Where the LoadMAT path r...

[Python] Turn the WAV file to C

Foreword Because the sound source data is required to be stored in the C file from the WAV, try to use Python parsing. Reference article Data in WAV files need to pay attention to large end and small ...

How to sort out WAV files in Python

Copyright Notice: All articles in this blog use the CC BY-NC-SA 4.0 license agreement unless otherwise stated. Please indicate the source! Https://blog.csdn.net/huplion/article/details/81040734 1)scip...

Python convert pcm file to wav file

Convert all pcm files under pcm_path to wav files...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top