import pyaudio
import struct
import numpy as np
import wave
#gather information from data
n=(1024*4)
sound = wave.open('test.wav','rb')
num_sample = sound.getnframes()
sample_rate = sound.getframerate()
duration = round(num_sample/sample_rate, 4)
#instantiate pyaudio and start stream
p = pyaudio.PyAudio()
stream = p.open(format = p.get_format_from_width(sound.getsampwidth()),
channels = sound.getnchannels(),
rate = sample_rate,
output = True,
frames_per_buffer = n)
#Get data from .wav and turn it into integers
data = sound.readframes(n)
data_int = struct.unpack(str(len(data))+'B',data)
print(data_int_test)
这是我的代码的一部分,我从音频中制作了一个整数数组。我将尝试将减乘等加到整数上,看看会发生什么。但是,我不知道如何将整数数组转回音频。我也尝试使用numpy.frombuffer
which 也给了我整数,但我不太确定如何将它们转回来。如果有另一个模块的方法,我愿意这样做。我敢肯定 numpy 可能有什么。
尝试使用write
函数 from scipy.io.wavfile
to.wav
文件。
from scipy.io.wavfile import write
write('test.wav', sample_rate, scaled)
#write("filename.wav", int - sample rate, data)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句