import wave

def get_wav_metadata(file_path): with wave.open(file_path, 'r') as wav_file: sample_rate = wav_file.getframerate() num_frames = wav_file.getnframes() num_channels = wav_file.getnchannels() bits_per_sample = wav_file.getsampwidth() * 8 return (sample_rate, num_frames, num_channels, bits_per_sample)

if name == 'main': wavfile = "./talk.wav" sample_rate, num_frames, num_channels, bits_per_sample = get_wav_metadata(wavfile) print("采样率:", sample_rate) print("采样点数量:", num_frames) print("声道数:", num_channels) print("量化位数:", bits_per_sample

请将python代码格式化:import wavedef get_wav_metadatafile_pathwith waveopenfile_path r as wav_filesample_rate = wav_filegetframeratenum_frames = wav_filegetnframesnum_channels = wav_filegetnchannelsbits_per_s

原文地址: http://www.cveoy.top/t/topic/ieDR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录