简体   繁体   English

使用scipy.io.wavfile读取wav文件,然后写入不会复制原始文件

[英]reading a wav file using scipy.io.wavfile and then writing doesn't reproduce the original file

I am trying to work with wav files in Python. 我正在尝试使用Python中的wav文件。 I downloaded the SciPy library which supposedly can do the job. 我下载了SciPy库,据说该库可以完成这项工作。 To see that it works I'm trying to read a wav file and then write it again to disk. 为了查看它是否有效,我尝试读取一个wav文件,然后将其再次写入磁盘。 For some reason the new wav file that is created is not similar to the old one. 由于某种原因,创建的新的wav文件与旧的不相似。

import scipy.io.wavfile as wav
(rate,sample) = wav.read("/vocal.wav")
wav.write("/temp.wav", rate, sample)

scipy.io.wavfile.write(filename, rate, data) : Writes a simple uncompressed WAV file. scipy.io.wavfile.write(文件名,速率,数据):写入一个简单的未压缩WAV文件。 (From here ) (从这里

I suspect that your input file has some kind of compression. 我怀疑您的输入文件有某种压缩。

I do not have much experience with SciPy , but according to the documentation of scipy.io.wavfile.write the array do be written is expected to be an array of int type values. 我对SciPy并没有太多经验,但是根据scipy.io.wavfile.write的文档,要写入的数组应该是int类型值的数组。 While scipy.io.wavfile.read tells that type of the array is determined by the type of data in the file. 尽管scipy.io.wavfile.read告诉您数组的类型由文件中的数据类型决定。 They may not be the same. 他们可能不一样。

It would be good, to read the written file once again and check if the array read from original contains the same date after conversion to int . 最好再次读取写入的文件,并检查从原始读取的数组转换为int后是否包含相同的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM