[英]python waveform to WAV file converter
您可以使用标准wave
库。 这是我使用的功能。 如果需要更多通道或不同的样本宽度,则可以进一步修改。
import wave
import struct
def signal_to_wav(signal, fname, Fs):
"""Convert a numpy array into a wav file.
Args
----
signal : 1-D numpy array
An array containing the audio signal.
fname : str
Name of the audio file where the signal will be saved.
Fs: int
Sampling rate of the signal.
"""
data = struct.pack('<' + ('h'*len(signal)), *signal)
wav_file = wave.open(fname, 'wb')
wav_file.setnchannels(1)
wav_file.setsampwidth(2)
wav_file.setframerate(Fs)
wav_file.writeframes(data)
wav_file.close()
一些到文档的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.