python wave文件的额处理方法
来源:互联网 发布:淘宝购物付款流程图 编辑:程序博客网 时间:2024/05/21 17:16
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as signal
import wave
'''
This is a wave test program
'''
def read_wave_data(file_path):
#open a wave file, and return a Wave_read object
f = wave.open(file_path,"rb")
#read the wave's format infomation,and return a tuple
params = f.getparams()
#get the info
nchannels, sampwidth, framerate, nframes = params[:4]
#Reads and returns nframes of audio, as a string of bytes.
str_data = f.readframes(nframes)
#close the stream
f.close()
#turn the wave's data to array
wave_data = np.fromstring(str_data, dtype = np.short)
#for the data is stereo,and format is LRLRLR...
#shape the array to n*2(-1 means fit the y coordinate)
wave_data.shape = -1, nchannels
#transpose the data
wave_data = wave_data.T
#calculate the time bar
time = np.arange(0, nframes) * (1.0/framerate)
return wave_data, nchannels,sampwidth,framerate
def write_wave_data(file_path, wave_data, nchannels, sampwidth,framerate):
f = wave.open(file_path,"wb")
f.setnchannels(nchannels)
f.setsampwidth(sampwidth)
f.setframerate(framerate)
f.writeframes(wave_data.tostring())
return
if __name__ == "__main__":
wave_data,nchannels,sampwidth,framerate = read_wave_data("voice_tv_door_binaural.wav")
print nchannels,sampwidth,framerate
print wave_data
print type(wave_data)
print "OK"
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as signal
import wave
'''
This is a wave test program
'''
def read_wave_data(file_path):
#open a wave file, and return a Wave_read object
f = wave.open(file_path,"rb")
#read the wave's format infomation,and return a tuple
params = f.getparams()
#get the info
nchannels, sampwidth, framerate, nframes = params[:4]
#Reads and returns nframes of audio, as a string of bytes.
str_data = f.readframes(nframes)
#close the stream
f.close()
#turn the wave's data to array
wave_data = np.fromstring(str_data, dtype = np.short)
#for the data is stereo,and format is LRLRLR...
#shape the array to n*2(-1 means fit the y coordinate)
wave_data.shape = -1, nchannels
#transpose the data
wave_data = wave_data.T
#calculate the time bar
time = np.arange(0, nframes) * (1.0/framerate)
return wave_data, nchannels,sampwidth,framerate
def write_wave_data(file_path, wave_data, nchannels, sampwidth,framerate):
f = wave.open(file_path,"wb")
f.setnchannels(nchannels)
f.setsampwidth(sampwidth)
f.setframerate(framerate)
f.writeframes(wave_data.tostring())
return
if __name__ == "__main__":
wave_data,nchannels,sampwidth,framerate = read_wave_data("voice_tv_door_binaural.wav")
print nchannels,sampwidth,framerate
print wave_data
print type(wave_data)
print "OK"
0 0
- python wave文件的额处理方法
- DirectSound操作WAVE文件的方法
- Wave文件的基础知识
- wave文件的格式
- (7): 建立一个空的 Wave 文件(三种方法)
- Wave文件的组织结构
- Python 文件处理方法详解
- python的文件处理
- wave 文件
- WAVE文件
- wave文件头文件的定义
- 关于语音聊天(wave系列函数播放文件、网络音频)的实现方法
- 处理文件的方法
- ADPCM WAVE文件的压缩与解压缩
- (5): 获取 Wave 文件的格式信息
- (6): 获取 Wave 文件的波形数据
- 关于 Wave 文件的基础知识与文件格式
- 编写 wave flac ape 的 cue 文件
- SpringMVC的RESTful(二)定制格式
- sorted函数以及operator.itemgetter函数
- boost::function
- 价值观
- 加密后的php代码需要ZendGuardLoader模块才能正常运行
- python wave文件的额处理方法
- Android基础知识
- 轮播图
- spring boot最小web项目
- UIPageControl点击小圆点跳转到对应位置的方法
- SpringMVC注入Interceptor失败
- Opencv3.0-python: 视频处理时报错color.cpp:7456: error: (-215) scn == 3 || scn == 4 的解决办法
- 为什么要设置环境变量,环境变量有什么用?
- Unity3d版FlappyBird(像素小鸟)